List of usage examples for org.eclipse.jface.viewers StructuredSelection isEmpty
@Override public boolean isEmpty()
From source file:org.eclipse.jpt.jpa.eclipselink.ui.internal.dialogs.EclipseLinkAddVirtualAttributeDialog.java
License:Open Source License
public String getMappingKey() { StructuredSelection selection = (StructuredSelection) this.mappingCombo.getSelection(); return (selection.isEmpty()) ? null : ((MappingUiDefinition) selection.getFirstElement()).getKey(); }
From source file:org.eclipse.jpt.jpa.ui.internal.dialogs.AddPersistentAttributeToXmlAndMapDialog.java
License:Open Source License
public String getMappingKey() { StructuredSelection selection = (StructuredSelection) mappingCombo.getSelection(); return (selection.isEmpty()) ? null : ((MappingUiDefinition) selection.getFirstElement()).getKey(); }
From source file:org.eclipse.jpt.jpa.ui.internal.wizards.gen.JoinColumnsPage.java
License:Open Source License
private void createAddRemoveButtonComposite(Composite tablesGroup, final TableViewer joinColumnsTable, final ArrayList<SimpleJoin> tableDataModel) { //Add and Remove JoinColumns buttons Composite buttonComposite = new Composite(tablesGroup, SWT.NULL); GridLayout buttonLayout = new GridLayout(1, false); buttonComposite.setLayout(buttonLayout); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; data.verticalAlignment = GridData.BEGINNING; buttonComposite.setLayoutData(data); Button addButton = new Button(buttonComposite, SWT.PUSH); addButton.setText(JptJpaUiWizardsEntityGenMessages.add); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; addButton.setLayoutData(gridData);// ww w. j a v a 2s. c om addButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } @SuppressWarnings("unchecked") public void widgetSelected(SelectionEvent e) { SimpleJoin join = getDefaultNewJoin(joinColumnsTable); tableDataModel.add(join); joinColumnsTable.refresh(); //Update Wizard model TreeMap<String, String> joins = null; if (joinColumnsTable == joinColumnsTable1) { joins = (TreeMap<String, String>) getWizardDataModel() .get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS1); } else { joins = (TreeMap<String, String>) getWizardDataModel() .get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS2); } joins.put(join.foreignKey, join.primaryKey); updatePageComplete(); } }); Button removeButton = new Button(buttonComposite, SWT.PUSH); removeButton.setText(JptJpaUiWizardsEntityGenMessages.remove); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; removeButton.setLayoutData(gridData); removeButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } @SuppressWarnings("unchecked") public void widgetSelected(SelectionEvent e) { StructuredSelection selection = (StructuredSelection) joinColumnsTable.getSelection(); if (selection.isEmpty()) return; SimpleJoin join = (SimpleJoin) selection.getFirstElement(); //Update TableViewer model tableDataModel.remove(join); //Update Wizard model TreeMap<String, String> joins = null; if (joinColumnsTable == joinColumnsTable1) { joins = (TreeMap<String, String>) getWizardDataModel() .get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS1); } else { joins = (TreeMap<String, String>) getWizardDataModel() .get(NewAssociationWizard.ASSOCIATION_JOIN_COLUMNS2); } joins.remove(join.foreignKey); joinColumnsTable.refresh(); } }); addButton.setFocus(); }
From source file:org.eclipse.jst.jsf.ui.internal.classpath.JSFLibraryContainerWizardPage.java
License:Open Source License
private JSFLibrary getCurrentLibrarySelection() { JSFLibrary lib = null;/*from w ww . j ava2 s . c o m*/ StructuredSelection ssel = (StructuredSelection) lv.getSelection(); if (ssel != null && !ssel.isEmpty()) { lib = (JSFLibrary) ssel.getFirstElement(); } return lib; }
From source file:org.eclipse.jst.jsf.ui.internal.classpath.JSFLibraryContainerWizardPage.java
License:Open Source License
public void createControl(Composite parent) { //Build UI to display JSF Lib components from registry Composite c = new Composite(parent, SWT.NONE); c.setLayout(new GridLayout(2, false)); c.setLayoutData(new GridData(GridData.FILL_BOTH)); //disable wizard if this is not a valid JSF project if (!isJSFProject) { Label warning = new Label(c, SWT.NONE); warning.setText(Messages.JSFLibraryContainerWizardPage_WarningNoJSFFacet); setControl(c);/*ww w. j av a 2s . co m*/ return; } Label lblViewer = new Label(c, SWT.NONE); lblViewer.setText(Messages.JSFLibraryContainerWizardPage_JSFLibraries); GridData gd1 = new GridData(GridData.BEGINNING); gd1.horizontalSpan = 2; lblViewer.setLayoutData(gd1); lv = createTableViewer(c); lv.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); lvAdapter = new JSFLibrariesTableViewerAdapter(); lvLabelProvider = new JSFLibrariesListLabelProvider(); lv.setContentProvider(lvAdapter); lv.setLabelProvider(lvLabelProvider); lv.addSelectionChangedListener(lvAdapter); lv.addDoubleClickListener(lvAdapter); lv.setComparator(lvAdapter); Composite buttons = new Composite(c, SWT.NONE); buttons.setLayout(new GridLayout(1, false)); buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL)); final Button addButton = new Button(buttons, SWT.NONE); addButton.setText(Messages.JSFLibraryContainerWizardPage_Add); addButton.setLayoutData(new GridData(GridData.END | GridData.VERTICAL_ALIGN_BEGINNING)); addButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { openJSFLibraryWizard(null); } }); final Button editButton = new Button(buttons, SWT.NONE); editButton.setText(Messages.JSFLibraryContainerWizardPage_Edit); editButton.setLayoutData(new GridData(GridData.END | GridData.VERTICAL_ALIGN_BEGINNING)); editButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { StructuredSelection sel = (StructuredSelection) lv.getSelection(); if ((sel == null || sel.isEmpty()) && containerEntry != null) { JSFLibrary jsfLib = getJSFLibraryForEdit(containerEntry); sel = new StructuredSelection(jsfLib); } openJSFLibraryWizard(sel); } }); editButton.setVisible(false); lv.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { setEditButton(event.getSelection()); } private void setEditButton(final ISelection selection) { IStructuredSelection sel = (IStructuredSelection) selection; editButton.setVisible(sel.size() == 1); if (sel.size() == 1) { JSFLibrary lib = (JSFLibrary) sel.getFirstElement(); boolean pp = lib instanceof PluginProvidedJSFLibrary; editButton.setEnabled(!pp); if (isEditReference()) { lv.setAllChecked(false); lv.setChecked(lib, true); } } } }); setControl(c); if (isEditReference()) { JSFLibrary lib = getJSFLibraryForEdit(containerEntry); lv.setInput(getAllUnselectedJSFLibrariesExceptReferencedLib(lib)); selectAndCheckCurrentLib(lib); setDescription(Messages.JSFLibraryContainerWizardPage_EditLibrary_DescriptionText); } else { lv.setInput(getAllJSFLibraries()); lv.setCheckedElements(getSelectedJSFLibariesForProject().values().toArray(new Object[0])); } }
From source file:org.eclipse.jst.jsf.ui.internal.jsflibraryconfig.JSFLibraryConfigControl.java
License:Open Source License
private void createCompLibControls(Composite parent) { final Composite cmpCompLibs = new Composite(parent, SWT.NONE); final GridLayout gridLayoutCompLibs = new GridLayout(); gridLayoutCompLibs.numColumns = 4;/* w w w .ja v a 2 s. co m*/ gridLayoutCompLibs.marginWidth = 0; gridLayoutCompLibs.marginHeight = 0; cmpCompLibs.setLayout(gridLayoutCompLibs); GridData gdComp = new GridData(); gdComp.horizontalAlignment = SWT.FILL; gdComp.grabExcessHorizontalSpace = true; cmpCompLibs.setLayoutData(gdComp); tvCompLib = new TreeViewer(cmpCompLibs, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); tvAdapter = new TreeViewerAdapter(); tvLabelProvider = new TreeLabelProvider(); tvCompLib.setContentProvider(tvAdapter); tvCompLib.setLabelProvider(tvLabelProvider); tvCompLib.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { resetComponentLibSelection((StructuredSelection) event.getSelection(), tvCompLib, ctvSelCompLib, true); fireChangedEvent(event); } }); tvCompLib.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); tvCompLib.addFilter(new TreeViewerFilter()); final Composite composite_buttons = new Composite(cmpCompLibs, SWT.NONE); composite_buttons.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); composite_buttons.setLayout(new GridLayout()); final Composite composite_Single = new Composite(composite_buttons, SWT.None); composite_Single.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final GridLayout gl_Single = new GridLayout(); gl_Single.marginHeight = 4; composite_Single.setLayout(new GridLayout()); final Button btnAdd = new Button(composite_Single, SWT.NONE); btnAdd.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); btnAdd.setText(Messages.JSFLibraryConfigControl_Add); btnAdd.setEnabled(false); final Button btnRemove = new Button(composite_Single, SWT.NONE); btnRemove.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); btnRemove.setText(Messages.JSFLibraryConfigControl_Remove); btnRemove.setEnabled(false); final Composite composite_All = new Composite(composite_buttons, SWT.None); composite_All.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final GridLayout gl_All = new GridLayout(); gl_Single.marginHeight = 4; composite_All.setLayout(gl_All); btnAddAll = new Button(composite_All, SWT.NONE); btnAddAll.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); btnAddAll.setText(Messages.JSFLibraryConfigControl_AddAll); btnRemoveAll = new Button(composite_All, SWT.NONE); btnRemoveAll.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); btnRemoveAll.setText(Messages.JSFLibraryConfigControl_RemoveAll); final Composite composite_New = new Composite(composite_buttons, SWT.None); composite_New.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final GridLayout gl_New = new GridLayout(); gl_Single.marginHeight = 4; composite_New.setLayout(gl_New); final Button btnNewCompLib = new Button(composite_New, SWT.NONE); btnNewCompLib.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false)); btnNewCompLib.setText(Messages.JSFLibraryConfigControl_NewComponentLibrary); btnNewCompLib.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { JSFLibraryWizard wizard = new JSFLibraryWizard(); IWorkbench wb = PlatformUI.getWorkbench(); wizard.init(wb, null); WizardDialog dialog = new WizardDialog(wb.getActiveWorkbenchWindow().getShell(), wizard); int ret = dialog.open(); if (ret == Window.OK) { JSFLibraryInternalReference lib = new JSFLibraryInternalReference(wizard.getJSFLibrary(), true, true); JSFLibraryRegistryUtil.getInstance().addJSFLibrary(lib); workingCopyModel.getJSFComponentLibraries().add(lib); loadJSFCompList(); setCompListModelProperty(); ctvSelCompLib.setChecked(lib, true); } } }); ctvSelCompLib = CheckboxTableViewer.newCheckList(cmpCompLibs, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER); ctvSelCompLib.addFilter(new CheckedTableViewerFilter()); final Table table = ctvSelCompLib.getTable(); table.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); table.setHeaderVisible(true); final TableColumn tcDeploy = new TableColumn(table, SWT.LEFT); tcDeploy.setWidth(50); tcDeploy.setText(Messages.JSFLibraryConfigControl_TH_Deploy); tcDeploy.setToolTipText(Messages.JSFLibraryConfigControl_DeployJAR); final TableColumn tcLibName = new TableColumn(table, SWT.LEFT); tcLibName.setWidth(150); tcLibName.setText(Messages.JSFLibraryConfigControl_TH_LibraryName); //ctvSelCompLib.setCellModifier(new CellModifierCTVSelCompLib()); ctvSelCompLib.setSorter(new SelectedCompLibCTVSorter()); ctvSelCompLib.setLabelProvider(new SelectedCompLibCTVLabelProvider()); ctvSelCompLib.setContentProvider(new CompLibCTVContentProvider()); ctvSelCompLib.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { resetComponentLibSelection((StructuredSelection) event.getSelection(), tvCompLib, ctvSelCompLib, false); fireChangedEvent(event); } }); ctvSelCompLib.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { JSFLibraryInternalReference changedItem = (JSFLibraryInternalReference) event.getElement(); boolean isChecked4Deploy = event.getChecked(); List list = workingCopyModel.getJSFComponentLibraries(); Iterator it = list.iterator(); JSFLibraryInternalReference crtjsflib = null; while (it.hasNext()) { crtjsflib = (JSFLibraryInternalReference) it.next(); if (crtjsflib.getID().equals(changedItem.getID())) { crtjsflib.setToBeDeployed(isChecked4Deploy); fireChangedEvent(event); break; } } } }); btnAdd.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { resetComponentLibSelection((StructuredSelection) tvCompLib.getSelection(), tvCompLib, ctvSelCompLib, true); fireChangedEvent(e); } }); btnAddAll.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { resetCompontLibSelectionAll(tvCompLib, ctvSelCompLib, true); fireChangedEvent(e); } }); btnRemove.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { resetComponentLibSelection((StructuredSelection) ctvSelCompLib.getSelection(), tvCompLib, ctvSelCompLib, false); fireChangedEvent(e); } }); btnRemoveAll.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { resetCompontLibSelectionAll(tvCompLib, ctvSelCompLib, false); fireChangedEvent(e); } }); tvCompLib.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection sel = (StructuredSelection) event.getSelection(); btnAdd.setEnabled(!sel.isEmpty() && sel.getFirstElement() instanceof JSFLibraryInternalReference); btnAddAll.setEnabled(tvCompLib.getTree().getItemCount() > 0); } }); ctvSelCompLib.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection sel = (StructuredSelection) event.getSelection(); btnRemove.setEnabled(!sel.isEmpty()); btnRemoveAll.setEnabled(ctvSelCompLib.getTable().getItemCount() > 0); } }); }
From source file:org.eclipse.jst.jsf.ui.internal.jsflibraryconfig.JSFLibraryConfigControl.java
License:Open Source License
private void resetComponentLibSelection(StructuredSelection item, TreeViewer srcViewer, CheckboxTableViewer destViewer, boolean state) { if (item != null && !item.isEmpty()) { List selected = new ArrayList(item.size()); for (Iterator sel = item.iterator(); sel.hasNext();) { JSFLibraryInternalReference jsfLibDctr = (JSFLibraryInternalReference) sel.next(); selected.add(jsfLibDctr);//from w w w .j a v a2s . c om List list = workingCopyModel.getJSFComponentLibraries(); Iterator it = list.iterator(); JSFLibraryInternalReference crtjsfLibDctr = null; while (it.hasNext()) { crtjsfLibDctr = (JSFLibraryInternalReference) it.next(); if (crtjsfLibDctr.getID().equals(jsfLibDctr.getID())) { crtjsfLibDctr.setToBeDeployed(state); crtjsfLibDctr.setSelected(state); } } } loadJSFCompList(); srcViewer.refresh(); destViewer.refresh(); for (Iterator it = selected.iterator(); it.hasNext();) { destViewer.setChecked(it.next(), state); } setCompListModelProperty(); } }
From source file:org.eclipse.jst.servlet.ui.internal.wizard.NewFilterClassOptionsWizardPage.java
License:Open Source License
public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); // if the selection is empty, then the remove button is disabled if (selection.isEmpty()) { removeButton.setEnabled(false);/*from ww w .j a v a2 s.c o m*/ return; } // if the selection is non-empty and the filter extends a class which // implements javax.servlet.Filter, then the remove button is enabled if (FilterSupertypesValidator.isFilterSuperclass(model)) { removeButton.setEnabled(true); return; } // if the selection is non-empty and the filter does not extend a class // which implements javax.servlet.Filter, then the remove button is // disabled only if the Filter interface is in the selection Iterator iter = selection.iterator(); while (iter.hasNext()) { if (QUALIFIED_FILTER.equals(iter.next())) removeButton.setEnabled(false); return; } // in all other cases the remove button is enabled removeButton.setEnabled(true); }
From source file:org.eclipse.launchbar.ui.controls.internal.CSelector.java
License:Open Source License
protected void openPopup() { Object[] elements = contentProvider.getElements(input); if (elements.length == 0 && !hasActionArea()) return;//from w w w . ja v a 2s . c om arrowTransition.to(-arrowMax); if (popup != null && !popup.isDisposed()) { popup.dispose(); } popup = new Shell(getShell(), SWT.TOOL | SWT.ON_TOP | SWT.RESIZE); popup.setLayout(GridLayoutFactory.fillDefaults().spacing(0, 0).create()); popup.setBackground(getBackground()); listViewer = new LaunchBarListViewer(popup); initializeListViewer(listViewer); listViewer.setFilterVisible(elements.length > 7); listViewer.setInput(input); listViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { if (!listViewer.isFinalSelection()) return; StructuredSelection ss = (StructuredSelection) event.getSelection(); if (!ss.isEmpty()) { setSelection(ss.getFirstElement()); fireSelectionChanged(); } closePopup(); } }); if (hasActionArea()) createActionArea(popup); Rectangle buttonBounds = getBounds(); Point popupLocation = popup.getDisplay().map(this, null, 0, buttonBounds.height); popup.setLocation(popupLocation.x, popupLocation.y + 5); restoreShellSize(); popup.setVisible(true); popup.setFocus(); getDisplay().addFilter(SWT.FocusIn, focusOutListener); getDisplay().addFilter(SWT.FocusOut, focusOutListener); getDisplay().addFilter(SWT.MouseUp, focusOutListener); popup.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { getDisplay().removeFilter(SWT.FocusIn, focusOutListener); getDisplay().removeFilter(SWT.FocusOut, focusOutListener); getDisplay().removeFilter(SWT.MouseUp, focusOutListener); saveShellSize(); } }); }
From source file:org.eclipse.launchbar.ui.internal.controls.CSelector.java
License:Open Source License
protected void openPopup() { Object[] elements = contentProvider.getElements(input); if (elements.length == 0 && !hasActionArea()) return;/* w w w . j a v a2 s .c om*/ arrowTransition.to(-arrowMax); if (popup != null && !popup.isDisposed()) { popup.dispose(); } popup = new Shell(getShell(), SWT.TOOL | SWT.ON_TOP | SWT.RESIZE); popup.setLayout(GridLayoutFactory.fillDefaults().spacing(0, 0).create()); listViewer = new LaunchBarListViewer(popup); initializeListViewer(listViewer); listViewer.setFilterVisible(elements.length > 7); listViewer.setInput(input); listViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { if (!listViewer.isFinalSelection()) return; StructuredSelection ss = (StructuredSelection) event.getSelection(); if (!ss.isEmpty()) { setSelection(ss.getFirstElement()); fireSelectionChanged(); } closePopup(); } }); if (hasActionArea()) createActionArea(popup); Rectangle buttonBounds = getBounds(); Point popupLocation = popup.getDisplay().map(this, null, 0, buttonBounds.height); popup.setLocation(popupLocation.x, popupLocation.y + 5); restoreShellSize(); popup.setVisible(true); popup.setFocus(); getDisplay().addFilter(SWT.FocusIn, focusOutListener); getDisplay().addFilter(SWT.FocusOut, focusOutListener); getDisplay().addFilter(SWT.MouseUp, focusOutListener); popup.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { getDisplay().removeFilter(SWT.FocusIn, focusOutListener); getDisplay().removeFilter(SWT.FocusOut, focusOutListener); getDisplay().removeFilter(SWT.MouseUp, focusOutListener); saveShellSize(); } }); if (hoverProvider != null) { hoverProvider.dismissHover(selection != null ? selection : null, true); } }