List of usage examples for org.eclipse.jface.viewers IStructuredSelection isEmpty
public boolean isEmpty();
From source file:at.spardat.xma.guidesign.presentation.NewComponentWizard.java
License:Open Source License
public static IResource getSelectedResource(IStructuredSelection selection) { // Try and get the resource selection to determine a current directory for the file dialog. IResource selectedResource = null;// w w w . j a va 2 s . co m if (selection != null && !selection.isEmpty()) { // Get the resource... // Object selectedElement = selection.iterator().next(); if (selectedElement instanceof IResource) { // Get the resource parent, if its a file. // selectedResource = (IResource) selectedElement; if (selectedResource.getType() == IResource.FILE) { selectedResource = selectedResource.getParent(); } } } return selectedResource; }
From source file:au.gov.ga.earthsci.common.ui.dialogs.SpatialReferenceSelectorDialog.java
License:Apache License
private void wireReferenceSelectionListener() { referencesView.addSelectionChangedListener(new ISelectionChangedListener() { @Override/* www . jav a 2s . c om*/ public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (selection.isEmpty()) { getButton(IDialogConstants.OK_ID).setEnabled(false); selectedSummary = null; } else { getButton(IDialogConstants.OK_ID).setEnabled(true); selectedSummary = (SpatialReferenceSummary) selection.getFirstElement(); } } }); }
From source file:au.gov.ga.earthsci.layer.ui.DrawOrderDragSourceListener.java
License:Apache License
@Override public void dragStart(DragSourceEvent event) { event.doit = false;/* w ww. j a v a2 s. co m*/ IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (selection.isEmpty()) { return; } List<?> selectionList = selection.toList(); for (Object item : selectionList) { if (!(item instanceof DrawOrderModel.LayerDrawOrderModelElement)) { return; } } event.doit = true; }
From source file:bndtools.editor.components.ComponentDetailsPage.java
License:Open Source License
void fillReferenceSection(FormToolkit toolkit, Section section) { ToolBar toolbar = new ToolBar(section, SWT.FLAT); section.setTextClient(toolbar);/* w w w.j av a2s . c om*/ final ToolItem addItem = new ToolItem(toolbar, SWT.PUSH); addItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD)); final ToolItem editItem = new ToolItem(toolbar, SWT.PUSH); editItem.setImage(imgEdit); editItem.setToolTipText("Edit"); editItem.setEnabled(false); final ToolItem removeItem = new ToolItem(toolbar, SWT.PUSH); removeItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE)); removeItem.setDisabledImage( PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE_DISABLED)); removeItem.setToolTipText("Remove"); removeItem.setEnabled(false); Composite composite = toolkit.createComposite(section); section.setClient(composite); tableReferences = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER); tableReferences.setHeaderVisible(true); tableReferences.setLinesVisible(false); TableColumn col; col = new TableColumn(tableReferences, SWT.NONE); col.setWidth(100); col.setText("Name"); col = new TableColumn(tableReferences, SWT.NONE); col.setWidth(200); col.setText("Interface"); col = new TableColumn(tableReferences, SWT.NONE); col.setWidth(35); col.setText("Card."); col = new TableColumn(tableReferences, SWT.NONE); col.setWidth(100); col.setText("Target"); viewerReferences = new TableViewer(tableReferences); viewerReferences.setContentProvider(new ArrayContentProvider()); viewerReferences.setLabelProvider(new ComponentSvcRefTableLabelProvider()); // Listeners viewerReferences.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) viewerReferences.getSelection(); editItem.setEnabled(selection.size() == 1); removeItem.setEnabled(!selection.isEmpty()); } }); addItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { doAddReference(); }; }); editItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { doEditReference(); }; }); removeItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { doRemoveReference(); } }); // Layout GridData gd; GridLayout layout; layout = new GridLayout(1, false); layout.verticalSpacing = 5; layout.horizontalSpacing = 0; layout.marginWidth = 0; layout.marginHeight = 0; composite.setLayout(layout); gd = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 3); gd.widthHint = 250; gd.heightHint = 70; tableReferences.setLayoutData(gd); }
From source file:bndtools.editor.components.ComponentListPart.java
License:Open Source License
void createSection(Section section, FormToolkit toolkit) { section.setText(Messages.ComponentListPart_listSectionTitle); Composite composite = toolkit.createComposite(section); section.setClient(composite);/*from ww w . j a v a 2 s . c om*/ table = toolkit.createTable(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER); viewer = new TableViewer(table); viewer.setUseHashlookup(true); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new ServiceComponentLabelProvider()); final Button btnAdd = toolkit.createButton(composite, Messages.ComponentListPart_addButton, SWT.PUSH); final Button btnRemove = toolkit.createButton(composite, Messages.ComponentListPart_RemoveButton, SWT.PUSH); toolkit.paintBordersFor(section); // Listeners viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); ArrayList<ServiceComponent> selectedComponents = new ArrayList<ServiceComponent>(selection.size()); @SuppressWarnings("rawtypes") Iterator iterator = selection.iterator(); while (iterator.hasNext()) { String name = (String) iterator.next(); ServiceComponent component = componentMap.get(name); if (component != null) selectedComponents.add(component); } managedForm.fireSelectionChanged(ComponentListPart.this, new StructuredSelection(selectedComponents)); btnRemove.setEnabled(!selection.isEmpty()); } }); viewer.addOpenListener(new IOpenListener() { public void open(OpenEvent event) { String name = (String) ((IStructuredSelection) event.getSelection()).getFirstElement(); if (name != null) { doOpenComponent(name); } } }); viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { ResourceTransfer.getInstance() }, new ComponentListDropAdapter(viewer)); btnAdd.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { try { doAdd(); } catch (Exception x) { Plugin.logError("Error adding component", x); } } }); btnRemove.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { doRemove(); } }); // Layout GridData gd; section.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setLayout(new GridLayout(2, false)); gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3); gd.widthHint = 250; table.setLayoutData(gd); btnAdd.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); }
From source file:bndtools.editor.contents.PrivatePackagesPart.java
License:Open Source License
private void doRemovePackages() { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (!selection.isEmpty()) { Iterator<?> elements = selection.iterator(); List<Object> removed = new LinkedList<Object>(); while (elements.hasNext()) { Object pkg = elements.next(); if (packages.remove(pkg)) removed.add(pkg);// w w w .java 2 s . c o m } if (!removed.isEmpty()) { viewer.remove(removed.toArray()); markDirty(); } } }
From source file:bndtools.editor.pkgpatterns.PkgPatternsListPart.java
License:Open Source License
private void doAddClausesAfterSelection(Collection<? extends C> newClauses) { if (newClauses != null && !newClauses.isEmpty()) { int selectedIndex = -1; IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (!selection.isEmpty()) { // find the highest selected index for (Iterator<?> iter = selection.iterator(); iter.hasNext();) { int index = this.clauses.indexOf(iter.next()); if (index > selectedIndex) selectedIndex = index; }/*from ww w . j a v a 2s . com*/ } doAddClauses(newClauses, selectedIndex, true); } }
From source file:bndtools.editor.pkgpatterns.PkgPatternsListPart.java
License:Open Source License
private void doInsertClausesAtSelection(Collection<? extends C> newClauses) { if (newClauses != null && !newClauses.isEmpty()) { int selectedIndex; IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (selection.isEmpty()) return; selectedIndex = this.clauses.indexOf(selection.getFirstElement()); doAddClauses(newClauses, selectedIndex, true); }//from w ww . j a va2 s . c o m }
From source file:ca.mcgill.cs.swevo.ppa.ui.actions.PPAOnCuAction.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { IStructuredSelection sSelection = (IStructuredSelection) selection; if (!sSelection.isEmpty()) { icu = (ICompilationUnit) sSelection.getFirstElement(); }/* ww w . j a v a 2 s. c o m*/ }
From source file:ca.mcgill.cs.swevo.ppa.ui.actions.PPAOnFileAction.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { IStructuredSelection sSelection = (IStructuredSelection) selection; if (!sSelection.isEmpty()) { file = (IFile) sSelection.getFirstElement(); }// w w w. jav a2 s .com }