Example usage for org.eclipse.jface.viewers IStructuredSelection isEmpty

List of usage examples for org.eclipse.jface.viewers IStructuredSelection isEmpty

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection isEmpty.

Prototype

public boolean isEmpty();

Source Link

Document

Returns whether this selection is empty.

Usage

From source file:com.amalto.workbench.dialogs.datacontainer.UpdateAutoIncrementDialog.java

License:Open Source License

private void createTable(Composite mainComp) {
    int style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION;
    resultsViewer = new TableViewer(mainComp, style);
    resultsViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    resultsViewer.getTable().setHeaderVisible(true);
    resultsViewer.getTable().setLinesVisible(true);
    resultsViewer.setContentProvider(getContentProvider());

    TableViewerColumn column = new TableViewerColumn(resultsViewer, SWT.NONE);
    column.getColumn().setText(Messages.UpdateAutoIncrementDialog_entity);
    column.getColumn().setResizable(true);
    column.getColumn().setWidth(300);/* w ww  . ja v  a 2 s.com*/
    column.setLabelProvider(new CustomedLabelProvider(0));
    column.setEditingSupport(null);

    column = new TableViewerColumn(resultsViewer, SWT.NONE);
    column.getColumn().setText(Messages.UpdateAutoIncrementDialog_value);
    column.getColumn().setResizable(true);
    column.getColumn().setWidth(100);
    column.setLabelProvider(new CustomedLabelProvider(1));
    column.setEditingSupport(new EditingSupport(resultsViewer) {

        @Override
        protected CellEditor getCellEditor(Object element) {
            return new VerificableTextCellEditor(resultsViewer.getTable());
        }

        @Override
        protected boolean canEdit(Object element) {
            return true;
        }

        @Override
        protected Object getValue(Object element) {
            Line line = (Line) element;
            return line.keyValues.get(1).value;
        }

        @Override
        protected void setValue(Object element, Object value) {
            Line line = (Line) element;
            line.keyValues.get(1).value = value.toString();
            resultsViewer.refresh();
        }

    });

    resultsViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) resultsViewer.getSelection();
            resetBtn.setEnabled(!selection.isEmpty());
        }
    });

    List<Line> lines = getInput();

    resultsViewer.setInput(lines);
}

From source file:com.amalto.workbench.dialogs.MDMXSDSchemaEntryDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    parent.getShell().setText(this.title);

    Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout layout = (GridLayout) composite.getLayout();
    layout.numColumns = 1;/* ww w .  j a v a 2s. c o m*/

    wcListViewer = new ListViewer(composite,
            SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    wcListViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    ((GridData) wcListViewer.getControl().getLayoutData()).minimumHeight = 200;

    wcListViewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public Object[] getElements(Object inputElement) {
            return ((ArrayList) inputElement).toArray(new String[] {});
        }
    });

    wcListViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            importedUrls.clear();
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            Iterator iter = selection.iterator();
            while (iter.hasNext()) {
                String url = (String) iter.next();
                importedUrls.add(url);
            }
            getButton(IDialogConstants.OK_ID).setEnabled(!selection.isEmpty());
        }
    });
    wcListViewer.setLabelProvider(new ILabelProvider() {

        public void addListener(ILabelProviderListener listener) {
        }

        public void dispose() {
        }

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void removeListener(ILabelProviderListener listener) {
        }

        public Image getImage(Object element) {
            return null;
        }

        public String getText(Object element) {
            return element.toString();
        }
    });

    wcListViewer.setSorter(new ViewerSorter());
    wcListViewer.setInput(urls);
    return composite;
}

From source file:com.amalto.workbench.editors.actions.EditItemAction.java

License:Open Source License

@Override
public void run() {
    try {//www  .  j  a v  a  2 s . c  o  m
        super.run();

        IStructuredSelection selection = ((IStructuredSelection) viewer.getSelection());

        if (selection.isEmpty()) {
            return;
        }

        WSRoutingOrderV2 routingOrder = (WSRoutingOrderV2) selection.getFirstElement();

        StringWriter sw = new StringWriter();
        Marshaller.marshal(routingOrder, sw);

        final DOMViewDialog d = new DOMViewDialog(shell, Util.parse(sw.toString()));
        d.addListener(new Listener() {

            public void handleEvent(Event event) {
                d.close();
            }// handleEvent
        });

        d.setBlockOnOpen(true);
        d.open();

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(shell, Messages._Error, Messages.bind(
                Messages.RoutingEngineV2BrowserMainPage_ErrorToViewRoutingOrder, e.getLocalizedMessage()));
    }
}

From source file:com.amalto.workbench.editors.xsdeditor.XSDEditor.java

License:Open Source License

private void resetTreeSelection(int newPageIndex) {
    DataModelMainPage dataModelEditorPage = getDataModelEditorPage();
    if (dataModelEditorPage != null) {
        TreeViewer treeViewer = dataModelEditorPage.getTreeViewer();
        if (newPageIndex == MODEL_PAGE_INDEX) {
            treeViewer.setSelection(null);
        } else if (newPageIndex == SOURCE_PAGE_INDEX) {
            IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
            if (!selection.isEmpty()) {
                Object firstElement = selection.getFirstElement();
                if ((firstElement instanceof XSDIdentityConstraintDefinition)) {
                    XSDIdentityConstraintDefinition cdf = (XSDIdentityConstraintDefinition) firstElement;
                    XSDConcreteComponent container = cdf.getContainer();
                    treeViewer.setSelection(new StructuredSelection(container));
                } else if ((firstElement instanceof XSDXPathDefinition)) {
                    XSDXPathDefinition pathdef = (XSDXPathDefinition) firstElement;
                    XSDConcreteComponent container = pathdef.getContainer().getContainer();
                    treeViewer.setSelection(new StructuredSelection(container));
                } else if (firstElement instanceof XSDAnnotation) {
                    XSDAnnotation annotation = (XSDAnnotation) firstElement;
                    XSDConcreteComponent container = annotation.getContainer();
                    treeViewer.setSelection(new StructuredSelection(container));
                }//  w ww .  jav  a 2s . c om
            }
        }
    }
}

From source file:com.android.ide.eclipse.adt.internal.launch.junit.AndroidJUnitLaunchConfigurationTab.java

License:Open Source License

/**
 * Returns the current Java element context from which to initialize
 * default settings, or <code>null</code> if none.
 *
 * @return Java element context./*from w w w .  j a v  a  2s  .  c om*/
 */
private IJavaElement getContext() {
    IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (activeWorkbenchWindow == null) {
        return null;
    }
    IWorkbenchPage page = activeWorkbenchWindow.getActivePage();
    if (page != null) {
        ISelection selection = page.getSelection();
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection ss = (IStructuredSelection) selection;
            if (!ss.isEmpty()) {
                Object obj = ss.getFirstElement();
                if (obj instanceof IJavaElement) {
                    return (IJavaElement) obj;
                }
                if (obj instanceof IResource) {
                    IJavaElement je = JavaCore.create((IResource) obj);
                    if (je == null) {
                        IProject pro = ((IResource) obj).getProject();
                        je = JavaCore.create(pro);
                    }
                    if (je != null) {
                        return je;
                    }
                }
            }
        }
        IEditorPart part = page.getActiveEditor();
        if (part != null) {
            IEditorInput input = part.getEditorInput();
            return (IJavaElement) input.getAdapter(IJavaElement.class);
        }
    }
    return null;
}

From source file:com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector.java

License:Open Source License

/**
 * Creates the selector.//from w  ww. ja va 2  s . co  m
 * <p/>
 * The {@link SelectorMode} changes the behavior of the selector depending on what is being
 * edited (a device config, a resource config, a given configuration).
 *
 * @param parent the composite parent.
 * @param mode the mode for the selector.
 */
public ConfigurationSelector(Composite parent, SelectorMode mode) {
    super(parent, SWT.NONE);

    mMode = mode;
    mBaseConfiguration.createDefault();

    GridLayout gl = new GridLayout(4, false);
    gl.marginWidth = gl.marginHeight = 0;
    setLayout(gl);

    // first column is the first table
    final Table fullTable = new Table(this, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    fullTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    fullTable.setHeaderVisible(true);
    fullTable.setLinesVisible(true);

    // create the column
    final TableColumn fullTableColumn = new TableColumn(fullTable, SWT.LEFT);
    // set the header
    fullTableColumn.setText("Available Qualifiers");

    fullTable.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            Rectangle r = fullTable.getClientArea();
            fullTableColumn.setWidth(r.width);
        }
    });

    mFullTableViewer = new TableViewer(fullTable);
    mFullTableViewer.setContentProvider(new QualifierContentProvider());
    // the label provider must return the value of the label only if the mode is
    // CONFIG_ONLY
    mFullTableViewer.setLabelProvider(new QualifierLabelProvider(mMode == SelectorMode.CONFIG_ONLY));
    mFullTableViewer.setInput(mBaseConfiguration);
    mFullTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection structSelection = (IStructuredSelection) selection;
                Object first = structSelection.getFirstElement();

                if (first instanceof ResourceQualifier) {
                    mAddButton.setEnabled(true);
                    return;
                }
            }

            mAddButton.setEnabled(false);
        }
    });

    // 2nd column is the left/right arrow button
    Composite buttonComposite = new Composite(this, SWT.NONE);
    gl = new GridLayout(1, false);
    gl.marginWidth = gl.marginHeight = 0;
    buttonComposite.setLayout(gl);
    buttonComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL));

    new Composite(buttonComposite, SWT.NONE);
    mAddButton = new Button(buttonComposite, SWT.BORDER | SWT.PUSH);
    mAddButton.setText("->");
    mAddButton.setEnabled(false);
    mAddButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) mFullTableViewer.getSelection();

            Object first = selection.getFirstElement();
            if (first instanceof ResourceQualifier) {
                ResourceQualifier qualifier = (ResourceQualifier) first;

                mBaseConfiguration.removeQualifier(qualifier);
                mSelectedConfiguration.addQualifier(qualifier);

                mFullTableViewer.refresh();
                mSelectionTableViewer.refresh();
                mSelectionTableViewer.setSelection(new StructuredSelection(qualifier), true);

                onChange(false /* keepSelection */);
            }
        }
    });

    mRemoveButton = new Button(buttonComposite, SWT.BORDER | SWT.PUSH);
    mRemoveButton.setText("<-");
    mRemoveButton.setEnabled(false);
    mRemoveButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) mSelectionTableViewer.getSelection();

            Object first = selection.getFirstElement();
            if (first instanceof ResourceQualifier) {
                ResourceQualifier qualifier = (ResourceQualifier) first;

                mSelectedConfiguration.removeQualifier(qualifier);
                mBaseConfiguration.addQualifier(qualifier);

                mFullTableViewer.refresh();
                mSelectionTableViewer.refresh();

                onChange(false /* keepSelection */);
            }
        }
    });

    // 3rd column is the selected config table
    final Table selectionTable = new Table(this, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    selectionTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    selectionTable.setHeaderVisible(true);
    selectionTable.setLinesVisible(true);

    // create the column
    final TableColumn selectionTableColumn = new TableColumn(selectionTable, SWT.LEFT);
    // set the header
    selectionTableColumn.setText("Chosen Qualifiers");

    selectionTable.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            Rectangle r = selectionTable.getClientArea();
            selectionTableColumn.setWidth(r.width);
        }
    });
    mSelectionTableViewer = new TableViewer(selectionTable);
    mSelectionTableViewer.setContentProvider(new QualifierContentProvider());
    // always show the qualifier value in this case.
    mSelectionTableViewer.setLabelProvider(new QualifierLabelProvider(true /* showQualifierValue */));
    mSelectionTableViewer.setInput(mSelectedConfiguration);
    mSelectionTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            // ignore selection changes during resfreshes in some cases.
            if (mOnRefresh) {
                return;
            }

            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection structSelection = (IStructuredSelection) selection;

                if (structSelection.isEmpty() == false) {
                    Object first = structSelection.getFirstElement();

                    if (first instanceof ResourceQualifier) {
                        mRemoveButton.setEnabled(true);

                        if (mMode != SelectorMode.CONFIG_ONLY) {
                            QualifierEditBase composite = mUiMap.get(first.getClass());

                            if (composite != null) {
                                composite.setQualifier((ResourceQualifier) first);
                            }

                            mStackLayout.topControl = composite;
                            mQualifierEditParent.layout();
                        }

                        return;
                    }
                } else {
                    if (mMode != SelectorMode.CONFIG_ONLY) {
                        mStackLayout.topControl = null;
                        mQualifierEditParent.layout();
                    }
                }
            }

            mRemoveButton.setEnabled(false);
        }
    });

    if (mMode != SelectorMode.CONFIG_ONLY) {
        // 4th column is the detail of the selected qualifier
        mQualifierEditParent = new Composite(this, SWT.NONE);
        mQualifierEditParent.setLayout(mStackLayout = new StackLayout());
        mQualifierEditParent.setLayoutData(new GridData(GridData.FILL_VERTICAL));

        // create the UI for all the qualifiers, and associate them to the
        // ResourceQualifer class.
        mUiMap.put(CountryCodeQualifier.class, new MCCEdit(mQualifierEditParent));
        mUiMap.put(NetworkCodeQualifier.class, new MNCEdit(mQualifierEditParent));
        mUiMap.put(LocaleQualifier.class, new LocaleEdit(mQualifierEditParent));
        mUiMap.put(LayoutDirectionQualifier.class, new LayoutDirectionEdit(mQualifierEditParent));
        mUiMap.put(SmallestScreenWidthQualifier.class, new SmallestScreenWidthEdit(mQualifierEditParent));
        mUiMap.put(ScreenWidthQualifier.class, new ScreenWidthEdit(mQualifierEditParent));
        mUiMap.put(ScreenHeightQualifier.class, new ScreenHeightEdit(mQualifierEditParent));
        mUiMap.put(ScreenSizeQualifier.class, new ScreenSizeEdit(mQualifierEditParent));
        mUiMap.put(ScreenRatioQualifier.class, new ScreenRatioEdit(mQualifierEditParent));
        mUiMap.put(ScreenOrientationQualifier.class, new OrientationEdit(mQualifierEditParent));
        mUiMap.put(UiModeQualifier.class, new UiModeEdit(mQualifierEditParent));
        mUiMap.put(NightModeQualifier.class, new NightModeEdit(mQualifierEditParent));
        mUiMap.put(DensityQualifier.class, new DensityEdit(mQualifierEditParent));
        mUiMap.put(TouchScreenQualifier.class, new TouchEdit(mQualifierEditParent));
        mUiMap.put(KeyboardStateQualifier.class, new KeyboardEdit(mQualifierEditParent));
        mUiMap.put(TextInputMethodQualifier.class, new TextInputEdit(mQualifierEditParent));
        mUiMap.put(NavigationStateQualifier.class, new NavigationStateEdit(mQualifierEditParent));
        mUiMap.put(NavigationMethodQualifier.class, new NavigationEdit(mQualifierEditParent));
        mUiMap.put(ScreenDimensionQualifier.class, new ScreenDimensionEdit(mQualifierEditParent));
        mUiMap.put(VersionQualifier.class, new VersionEdit(mQualifierEditParent));
    }
}

From source file:com.android.ide.eclipse.adt.ui.ConfigurationSelector.java

License:Open Source License

public ConfigurationSelector(Composite parent) {
    super(parent, SWT.NONE);

    mBaseConfiguration.createDefault();//from   w  w  w .  ja va2s  .  c o  m

    GridLayout gl = new GridLayout(4, false);
    gl.marginWidth = gl.marginHeight = 0;
    setLayout(gl);

    // first column is the first table
    final Table fullTable = new Table(this, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    fullTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    fullTable.setHeaderVisible(true);
    fullTable.setLinesVisible(true);

    // create the column
    final TableColumn fullTableColumn = new TableColumn(fullTable, SWT.LEFT);
    // set the header
    fullTableColumn.setText("Available Qualifiers");

    fullTable.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            Rectangle r = fullTable.getClientArea();
            fullTableColumn.setWidth(r.width);
        }
    });

    mFullTableViewer = new TableViewer(fullTable);
    mFullTableViewer.setContentProvider(new QualifierContentProvider());
    mFullTableViewer.setLabelProvider(new QualifierLabelProvider(false /* showQualifierValue */));
    mFullTableViewer.setInput(mBaseConfiguration);
    mFullTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection structSelection = (IStructuredSelection) selection;
                Object first = structSelection.getFirstElement();

                if (first instanceof ResourceQualifier) {
                    mAddButton.setEnabled(true);
                    return;
                }
            }

            mAddButton.setEnabled(false);
        }
    });

    // 2nd column is the left/right arrow button
    Composite buttonComposite = new Composite(this, SWT.NONE);
    gl = new GridLayout(1, false);
    gl.marginWidth = gl.marginHeight = 0;
    buttonComposite.setLayout(gl);
    buttonComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL));

    new Composite(buttonComposite, SWT.NONE);
    mAddButton = new Button(buttonComposite, SWT.BORDER | SWT.PUSH);
    mAddButton.setText("->");
    mAddButton.setEnabled(false);
    mAddButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) mFullTableViewer.getSelection();

            Object first = selection.getFirstElement();
            if (first instanceof ResourceQualifier) {
                ResourceQualifier qualifier = (ResourceQualifier) first;

                mBaseConfiguration.removeQualifier(qualifier);
                mSelectedConfiguration.addQualifier(qualifier);

                mFullTableViewer.refresh();
                mSelectionTableViewer.refresh();
                mSelectionTableViewer.setSelection(new StructuredSelection(qualifier), true);

                onChange(false /* keepSelection */);
            }
        }
    });

    mRemoveButton = new Button(buttonComposite, SWT.BORDER | SWT.PUSH);
    mRemoveButton.setText("<-");
    mRemoveButton.setEnabled(false);
    mRemoveButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) mSelectionTableViewer.getSelection();

            Object first = selection.getFirstElement();
            if (first instanceof ResourceQualifier) {
                ResourceQualifier qualifier = (ResourceQualifier) first;

                mSelectedConfiguration.removeQualifier(qualifier);
                mBaseConfiguration.addQualifier(qualifier);

                mFullTableViewer.refresh();
                mSelectionTableViewer.refresh();

                onChange(false /* keepSelection */);
            }
        }
    });

    // 3rd column is the selected config table
    final Table selectionTable = new Table(this, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    selectionTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    selectionTable.setHeaderVisible(true);
    selectionTable.setLinesVisible(true);

    // create the column
    final TableColumn selectionTableColumn = new TableColumn(selectionTable, SWT.LEFT);
    // set the header
    selectionTableColumn.setText("Chosen Qualifiers");

    selectionTable.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            Rectangle r = selectionTable.getClientArea();
            selectionTableColumn.setWidth(r.width);
        }
    });
    mSelectionTableViewer = new TableViewer(selectionTable);
    mSelectionTableViewer.setContentProvider(new QualifierContentProvider());
    mSelectionTableViewer.setLabelProvider(new QualifierLabelProvider(true /* showQualifierValue */));
    mSelectionTableViewer.setInput(mSelectedConfiguration);
    mSelectionTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            // ignore selection changes during resfreshes in some cases.
            if (mOnRefresh) {
                return;
            }

            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection structSelection = (IStructuredSelection) selection;

                if (structSelection.isEmpty() == false) {
                    Object first = structSelection.getFirstElement();

                    if (first instanceof ResourceQualifier) {
                        mRemoveButton.setEnabled(true);

                        QualifierEditBase composite = mUiMap.get(first.getClass());

                        if (composite != null) {
                            composite.setQualifier((ResourceQualifier) first);
                        }

                        mStackLayout.topControl = composite;
                        mQualifierEditParent.layout();

                        return;
                    }
                } else {
                    mStackLayout.topControl = null;
                    mQualifierEditParent.layout();
                }
            }

            mRemoveButton.setEnabled(false);
        }
    });

    // 4th column is the detail of the selected qualifier 
    mQualifierEditParent = new Composite(this, SWT.NONE);
    mQualifierEditParent.setLayout(mStackLayout = new StackLayout());
    mQualifierEditParent.setLayoutData(new GridData(GridData.FILL_VERTICAL));

    // create the UI for all the qualifiers, and associate them to the ResourceQualifer class.
    mUiMap.put(CountryCodeQualifier.class, new MCCEdit(mQualifierEditParent));
    mUiMap.put(NetworkCodeQualifier.class, new MNCEdit(mQualifierEditParent));
    mUiMap.put(LanguageQualifier.class, new LanguageEdit(mQualifierEditParent));
    mUiMap.put(RegionQualifier.class, new RegionEdit(mQualifierEditParent));
    mUiMap.put(ScreenOrientationQualifier.class, new OrientationEdit(mQualifierEditParent));
    mUiMap.put(PixelDensityQualifier.class, new PixelDensityEdit(mQualifierEditParent));
    mUiMap.put(TouchScreenQualifier.class, new TouchEdit(mQualifierEditParent));
    mUiMap.put(KeyboardStateQualifier.class, new KeyboardEdit(mQualifierEditParent));
    mUiMap.put(TextInputMethodQualifier.class, new TextInputEdit(mQualifierEditParent));
    mUiMap.put(NavigationMethodQualifier.class, new NavigationEdit(mQualifierEditParent));
    mUiMap.put(ScreenDimensionQualifier.class, new ScreenDimensionEdit(mQualifierEditParent));
}

From source file:com.android.ide.eclipse.auidt.internal.ui.ConfigurationSelector.java

License:Open Source License

/**
 * Creates the selector./*from   w w  w  .java  2 s.  co m*/
 * <p/>
 * The {@link SelectorMode} changes the behavior of the selector depending on what is being
 * edited (a device config, a resource config, a given configuration).
 *
 * @param parent the composite parent.
 * @param mode the mode for the selector.
 */
public ConfigurationSelector(Composite parent, SelectorMode mode) {
    super(parent, SWT.NONE);

    mMode = mode;
    mBaseConfiguration.createDefault();

    GridLayout gl = new GridLayout(4, false);
    gl.marginWidth = gl.marginHeight = 0;
    setLayout(gl);

    // first column is the first table
    final Table fullTable = new Table(this, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    fullTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    fullTable.setHeaderVisible(true);
    fullTable.setLinesVisible(true);

    // create the column
    final TableColumn fullTableColumn = new TableColumn(fullTable, SWT.LEFT);
    // set the header
    fullTableColumn.setText("Available Qualifiers");

    fullTable.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            Rectangle r = fullTable.getClientArea();
            fullTableColumn.setWidth(r.width);
        }
    });

    mFullTableViewer = new TableViewer(fullTable);
    mFullTableViewer.setContentProvider(new QualifierContentProvider());
    // the label provider must return the value of the label only if the mode is
    // CONFIG_ONLY
    mFullTableViewer.setLabelProvider(new QualifierLabelProvider(mMode == SelectorMode.CONFIG_ONLY));
    mFullTableViewer.setInput(mBaseConfiguration);
    mFullTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection structSelection = (IStructuredSelection) selection;
                Object first = structSelection.getFirstElement();

                if (first instanceof ResourceQualifier) {
                    mAddButton.setEnabled(true);
                    return;
                }
            }

            mAddButton.setEnabled(false);
        }
    });

    // 2nd column is the left/right arrow button
    Composite buttonComposite = new Composite(this, SWT.NONE);
    gl = new GridLayout(1, false);
    gl.marginWidth = gl.marginHeight = 0;
    buttonComposite.setLayout(gl);
    buttonComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL));

    new Composite(buttonComposite, SWT.NONE);
    mAddButton = new Button(buttonComposite, SWT.BORDER | SWT.PUSH);
    mAddButton.setText("->");
    mAddButton.setEnabled(false);
    mAddButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) mFullTableViewer.getSelection();

            Object first = selection.getFirstElement();
            if (first instanceof ResourceQualifier) {
                ResourceQualifier qualifier = (ResourceQualifier) first;

                mBaseConfiguration.removeQualifier(qualifier);
                mSelectedConfiguration.addQualifier(qualifier);

                mFullTableViewer.refresh();
                mSelectionTableViewer.refresh();
                mSelectionTableViewer.setSelection(new StructuredSelection(qualifier), true);

                onChange(false /* keepSelection */);
            }
        }
    });

    mRemoveButton = new Button(buttonComposite, SWT.BORDER | SWT.PUSH);
    mRemoveButton.setText("<-");
    mRemoveButton.setEnabled(false);
    mRemoveButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) mSelectionTableViewer.getSelection();

            Object first = selection.getFirstElement();
            if (first instanceof ResourceQualifier) {
                ResourceQualifier qualifier = (ResourceQualifier) first;

                mSelectedConfiguration.removeQualifier(qualifier);
                mBaseConfiguration.addQualifier(qualifier);

                mFullTableViewer.refresh();
                mSelectionTableViewer.refresh();

                onChange(false /* keepSelection */);
            }
        }
    });

    // 3rd column is the selected config table
    final Table selectionTable = new Table(this, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    selectionTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    selectionTable.setHeaderVisible(true);
    selectionTable.setLinesVisible(true);

    // create the column
    final TableColumn selectionTableColumn = new TableColumn(selectionTable, SWT.LEFT);
    // set the header
    selectionTableColumn.setText("Chosen Qualifiers");

    selectionTable.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            Rectangle r = selectionTable.getClientArea();
            selectionTableColumn.setWidth(r.width);
        }
    });
    mSelectionTableViewer = new TableViewer(selectionTable);
    mSelectionTableViewer.setContentProvider(new QualifierContentProvider());
    // always show the qualifier value in this case.
    mSelectionTableViewer.setLabelProvider(new QualifierLabelProvider(true /* showQualifierValue */));
    mSelectionTableViewer.setInput(mSelectedConfiguration);
    mSelectionTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            // ignore selection changes during resfreshes in some cases.
            if (mOnRefresh) {
                return;
            }

            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection structSelection = (IStructuredSelection) selection;

                if (structSelection.isEmpty() == false) {
                    Object first = structSelection.getFirstElement();

                    if (first instanceof ResourceQualifier) {
                        mRemoveButton.setEnabled(true);

                        if (mMode != SelectorMode.CONFIG_ONLY) {
                            QualifierEditBase composite = mUiMap.get(first.getClass());

                            if (composite != null) {
                                composite.setQualifier((ResourceQualifier) first);
                            }

                            mStackLayout.topControl = composite;
                            mQualifierEditParent.layout();
                        }

                        return;
                    }
                } else {
                    if (mMode != SelectorMode.CONFIG_ONLY) {
                        mStackLayout.topControl = null;
                        mQualifierEditParent.layout();
                    }
                }
            }

            mRemoveButton.setEnabled(false);
        }
    });

    if (mMode != SelectorMode.CONFIG_ONLY) {
        // 4th column is the detail of the selected qualifier
        mQualifierEditParent = new Composite(this, SWT.NONE);
        mQualifierEditParent.setLayout(mStackLayout = new StackLayout());
        mQualifierEditParent.setLayoutData(new GridData(GridData.FILL_VERTICAL));

        // create the UI for all the qualifiers, and associate them to the
        // ResourceQualifer class.
        mUiMap.put(CountryCodeQualifier.class, new MCCEdit(mQualifierEditParent));
        mUiMap.put(NetworkCodeQualifier.class, new MNCEdit(mQualifierEditParent));
        mUiMap.put(LanguageQualifier.class, new LanguageEdit(mQualifierEditParent));
        mUiMap.put(RegionQualifier.class, new RegionEdit(mQualifierEditParent));
        mUiMap.put(SmallestScreenWidthQualifier.class, new SmallestScreenWidthEdit(mQualifierEditParent));
        mUiMap.put(ScreenWidthQualifier.class, new ScreenWidthEdit(mQualifierEditParent));
        mUiMap.put(ScreenHeightQualifier.class, new ScreenHeightEdit(mQualifierEditParent));
        mUiMap.put(ScreenSizeQualifier.class, new ScreenSizeEdit(mQualifierEditParent));
        mUiMap.put(ScreenRatioQualifier.class, new ScreenRatioEdit(mQualifierEditParent));
        mUiMap.put(ScreenOrientationQualifier.class, new OrientationEdit(mQualifierEditParent));
        mUiMap.put(UiModeQualifier.class, new UiModeEdit(mQualifierEditParent));
        mUiMap.put(NightModeQualifier.class, new NightModeEdit(mQualifierEditParent));
        mUiMap.put(DensityQualifier.class, new DensityEdit(mQualifierEditParent));
        mUiMap.put(TouchScreenQualifier.class, new TouchEdit(mQualifierEditParent));
        mUiMap.put(KeyboardStateQualifier.class, new KeyboardEdit(mQualifierEditParent));
        mUiMap.put(TextInputMethodQualifier.class, new TextInputEdit(mQualifierEditParent));
        mUiMap.put(NavigationStateQualifier.class, new NavigationStateEdit(mQualifierEditParent));
        mUiMap.put(NavigationMethodQualifier.class, new NavigationEdit(mQualifierEditParent));
        mUiMap.put(ScreenDimensionQualifier.class, new ScreenDimensionEdit(mQualifierEditParent));
        mUiMap.put(VersionQualifier.class, new VersionEdit(mQualifierEditParent));
    }
}

From source file:com.android.sdkuilib.internal.repository.sdkman2.AddonSitesDialog.java

License:Apache License

private void newOrEdit(final boolean isEdit) {
    SdkSources sources = mUpdaterData.getSources();
    final SdkSource[] knownSources = sources.getAllSources();
    String title = isEdit ? "Edit Add-on Site URL" : "Add Add-on Site URL";
    String msg = "Please enter the URL of the addon.xml:";
    IStructuredSelection sel = (IStructuredSelection) mTableViewer.getSelection();
    final String initialValue = !isEdit || sel.isEmpty() ? null : sel.getFirstElement().toString();

    if (isEdit && initialValue == null) {
        // Edit with no actual value is not supposed to happen. Ignore this case.
        return;//from w ww . ja v a  2 s .c  om
    }

    InputDialog dlg = new InputDialog(getShell(), title, msg, initialValue, new IInputValidator() {
        public String isValid(String newText) {

            newText = newText == null ? null : newText.trim();

            if (newText == null || newText.length() == 0) {
                return "Error: URL field is empty. Please enter a URL.";
            }

            // A URL should have one of the following prefixes
            if (!newText.startsWith("file://") && //$NON-NLS-1$
            !newText.startsWith("ftp://") && //$NON-NLS-1$
            !newText.startsWith("http://") && //$NON-NLS-1$
            !newText.startsWith("https://")) { //$NON-NLS-1$
                return "Error: The URL must start by one of file://, ftp://, http:// or https://";
            }

            if (isEdit && newText.equals(initialValue)) {
                // Edited value hasn't changed. This isn't an error.
                return null;
            }

            // Reject URLs that are already in the source list.
            // URLs are generally case-insensitive (except for file:// where it all depends
            // on the current OS so we'll ignore this case.)
            for (SdkSource s : knownSources) {
                if (newText.equalsIgnoreCase(s.getUrl())) {
                    return "Error: This site is already listed.";
                }
            }

            return null;
        }
    });

    if (dlg.open() == Window.OK) {
        String url = dlg.getValue().trim();

        if (!url.equals(initialValue)) {
            if (isEdit && initialValue != null) {
                // Remove the old value before we add the new one, which is we just
                // asserted will be different.
                for (SdkSource source : sources.getSources(SdkSourceCategory.USER_ADDONS)) {
                    if (initialValue.equals(source.getUrl())) {
                        sources.remove(source);
                        break;
                    }
                }

            }

            // create the source, store it and update the list
            SdkAddonSource newSource = new SdkAddonSource(url, null/*uiName*/);
            sources.add(SdkSourceCategory.USER_ADDONS, newSource);
            setReturnValue(true);
            loadList();

            // select the new source
            IStructuredSelection newSel = new StructuredSelection(newSource);
            mTableViewer.setSelection(newSel, true /*reveal*/);
        }
    }
}

From source file:com.android.sdkuilib.internal.repository.sdkman2.AddonSitesDialog.java

License:Apache License

private void on_ButtonDelete_widgetSelected(SelectionEvent e) {
    IStructuredSelection sel = (IStructuredSelection) mTableViewer.getSelection();
    String selectedUrl = sel.isEmpty() ? null : sel.getFirstElement().toString();

    if (selectedUrl == null) {
        return;//from w  ww . j a  va  2  s . co  m
    }

    MessageBox mb = new MessageBox(getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION | SWT.APPLICATION_MODAL);
    mb.setText("Delete add-on site");
    mb.setMessage(String.format("Do you want to delete the URL %1$s?", selectedUrl));
    if (mb.open() == SWT.YES) {
        SdkSources sources = mUpdaterData.getSources();
        for (SdkSource source : sources.getSources(SdkSourceCategory.USER_ADDONS)) {
            if (selectedUrl.equals(source.getUrl())) {
                sources.remove(source);
                setReturnValue(true);
                loadList();
            }
        }
    }
}