List of usage examples for org.eclipse.jface.viewers IStructuredSelection isEmpty
public boolean isEmpty();
From source file:com.iw.plugins.spindle.ui.properties.SearchForLibraryWidget.java
License:Mozilla Public License
public ISelection getSelection() { IStructuredSelection selection = (IStructuredSelection) super.getSelection(); if (selection == null || selection.isEmpty()) { return selection; }//w w w . ja v a2s . c om Object[] selectionData = selection.toArray(); String name = (String) selectionData[0]; IPackageFragment fragment = (IPackageFragment) selectionData[1]; String elementName = fragment.getElementName(); if (elementName == null || elementName.trim().length() == 0) { fResultString = "/" + name; } else { fResultString = "/" + elementName.replace('.', '/') + "/" + name; } return new StructuredSelection(fResultString); }
From source file:com.iw.plugins.spindle.ui.propertysheet.CopyPropertyAction.java
License:Open Source License
/** * Performs this action.//from w ww .j a v a2 s . c o m */ public void run() { // Get the selected property IStructuredSelection selection = (IStructuredSelection) getPropertySheet().getSelection(); if (selection.isEmpty()) return; // Assume single selection IPropertySheetEntry entry = (IPropertySheetEntry) selection.getFirstElement(); // Place text on the clipboard StringBuffer buffer = new StringBuffer(); buffer.append(entry.getDisplayName()); buffer.append("\t"); //$NON-NLS-1$ buffer.append(entry.getValueAsString()); Object[] data = new Object[] { buffer.toString() }; Transfer[] transferTypes = new Transfer[] { TextTransfer.getInstance() }; clipboard.setContents(data, transferTypes); }
From source file:com.iw.plugins.spindle.ui.propertysheet.CopyPropertyAction.java
License:Open Source License
/** * Updates enablement based on the current selection */ public void selectionChanged(IStructuredSelection sel) { setEnabled(!sel.isEmpty()); }
From source file:com.iw.plugins.spindle.ui.propertysheet.PropertySheetPage.java
License:Open Source License
public void createControl(Composite parent) { // create a new viewer viewer = new PropertySheetViewer(parent); // set the model for the viewer if (rootEntry == null) { // create a new root PropertySheetEntry root = new PropertySheetEntry(); if (provider != null) // set the property source provider root.setPropertySourceProvider(provider); rootEntry = root;/* www.java 2 s .com*/ } viewer.setRootEntry(rootEntry); viewer.addActivationListener(getCellEditorActivationListener()); // add a listener to track when the entry selection changes viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { handleEntrySelection((IStructuredSelection) event.getSelection()); } }); initDragAndDrop(); // Create the popup menu for the page. copyAction = new CopyPropertyAction(viewer, "copy"); //$NON-NLS-1$ copyAction.setImageDescriptor(getImageDescriptor("etool16/copy_edit.gif")); //$NON-NLS-1$ copyAction.setHoverImageDescriptor(getImageDescriptor("ctool16/copy_edit.gif")); //$NON-NLS-1$ MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ menuMgr.add(copyAction); Menu menu = menuMgr.createContextMenu(viewer.getControl()); viewer.getControl().setMenu(menu); // Set help on the viewer viewer.getControl().addHelpListener(new HelpListener() { /* * @see HelpListener#helpRequested(HelpEvent) */ public void helpRequested(HelpEvent e) { String contextId = null; // Get the context for the selected item IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (!selection.isEmpty()) { IPropertySheetEntry entry = (IPropertySheetEntry) selection.getFirstElement(); Object helpContextId = entry.getHelpContextIds(); if (helpContextId != null) { if (helpContextId instanceof String) { WorkbenchHelp.displayHelp((String) helpContextId); return; } // Since 2.0 the only valid type for helpContextIds // is a String (a single id). // However for backward compatibility we have to handle // and array of contexts (Strings and/or IContexts) // or a context computer. Object[] contexts = null; if (helpContextId instanceof IContextComputer) { // get local contexts contexts = ((IContextComputer) helpContextId).getLocalContexts(e); } else { contexts = (Object[]) helpContextId; } // Ignore all but the first element in the array if (contexts[0] instanceof IContext) WorkbenchHelp.displayHelp((IContext) contexts[0]); else WorkbenchHelp.displayHelp((String) contexts[0]); return; } } // No help for the selection so show page help WorkbenchHelp.displayHelp(HELP_CONTEXT_PROPERTY_SHEET_PAGE); } }); }
From source file:com.iw.plugins.spindle.ui.propertysheet.PropertySheetPage.java
License:Open Source License
/** * The user is attempting to drag. Add the appropriate * data to the event./*from w ww . ja va2 s. c o m*/ */ void performDragSetData(DragSourceEvent event) { // Get the selected property IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (selection.isEmpty()) return; // Assume single selection IPropertySheetEntry entry = (IPropertySheetEntry) selection.getFirstElement(); // Place text as the data StringBuffer buffer = new StringBuffer(); buffer.append(entry.getDisplayName()); buffer.append("\t"); //$NON-NLS-1$ buffer.append(entry.getValueAsString()); event.data = buffer.toString(); }
From source file:com.iw.plugins.spindle.ui.widgets.TypeChooserWidget.java
License:Mozilla Public License
public ISelection getSelection() { IStructuredSelection selection = (IStructuredSelection) super.getSelection(); if (selection == null || selection.isEmpty()) { return selection; }/* w ww . jav a2s .c o m*/ Object[] selectionData = selection.toArray(); String name = (String) selectionData[0]; IPackageFragment fragment = (IPackageFragment) selectionData[1]; fResultType = (IType) fragment.getCompilationUnit(name); if (fResultType == null) fResultType = (IType) fragment.getClassFile(name); return new StructuredSelection(fResultType); }
From source file:com.iw.plugins.spindle.ui.wizards.NewTapestryElementWizard.java
License:Mozilla Public License
protected IResource getInitResource() { IStructuredSelection selection = getSelection(); IResource resource = null;/* w ww . j a va 2 s . c o m*/ if (selection != null && !selection.isEmpty()) { Object selectedElement = selection.getFirstElement(); if (selectedElement instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) selectedElement; resource = (IResource) adaptable.getAdapter(IResource.class); } } if (resource == null) resource = UIPlugin.getActiveEditorFileInput(); return resource; }
From source file:com.iw.plugins.spindle.ui.wizards.NewTapestryElementWizard.java
License:Mozilla Public License
protected IJavaElement getInitJavaElement() { IStructuredSelection selection = getSelection(); IJavaElement jelem = null;//from w w w .ja v a 2 s. com if (selection != null && !selection.isEmpty()) { Object selectedElement = selection.getFirstElement(); if (selectedElement instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) selectedElement; jelem = (IJavaElement) adaptable.getAdapter(IJavaElement.class); if (jelem == null) { IResource resource = (IResource) adaptable.getAdapter(IResource.class); if (resource != null) { jelem = (IJavaElement) ((IAdaptable) resource.getParent()).getAdapter(IJavaElement.class); if (jelem == null) { IProject proj = resource.getProject(); if (proj != null) jelem = JavaCore.create(proj); } } } } } if (jelem == null) jelem = UIPlugin.getActiveEditorJavaInput(); return jelem; }
From source file:com.iw.plugins.spindle.ui.wizards.source.MoveImplicitAttributesPage.java
License:Mozilla Public License
public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); layout.marginHeight = 0;/* ww w .ja v a2 s . co m*/ layout.numColumns = 2; layout.makeColumnsEqualWidth = false; container.setLayout(layout); GridData gd; Control simpleIdControl = fTemplateComponentId.getControl(container); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; simpleIdControl.setLayoutData(gd); fTemplateComponentId.setTextValue(fInitialTemplateComponentId == null ? "" : fInitialTemplateComponentId); Composite leftColumn = new Composite(container, SWT.NULL); gd = new GridData(GridData.FILL_BOTH); gd.widthHint = convertWidthInCharsToPixels(30); leftColumn.setLayoutData(gd); GridLayout leftLayout = new GridLayout(); leftLayout.verticalSpacing = 10; leftLayout.marginWidth = 0; leftColumn.setLayout(leftLayout); Composite rightColumn = new Composite(container, SWT.NULL); gd = new GridData(GridData.FILL_BOTH); rightColumn.setLayoutData(gd); GridLayout rightLayout = new GridLayout(); rightLayout.verticalSpacing = 10; rightLayout.marginWidth = 0; rightColumn.setLayout(rightLayout); AttributesThatStaySection allSection = new AttributesThatStaySection("Attibutes that stay"); Control allSectionControl = allSection.createControl(leftColumn); gd = new GridData(GridData.FILL_BOTH); allSectionControl.setLayoutData(gd); AttributesThatMoveSection pageSection = new AttributesThatMoveSection("Attributes that move"); Control pageSectionControl = pageSection.createControl(rightColumn); gd = new GridData(GridData.FILL_BOTH); pageSectionControl.setLayoutData(gd); fAttributesThatStayViewer.setContentProvider(new IStructuredContentProvider() { public Object[] getElements(Object inputElement) { return fAttributesThatStay.toArray(); } public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } }); fAttributesThatStayViewer.setLabelProvider(new AttributesLabelProvider()); fAttributesThatStayViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { updateButtonsEnabled(); } }); fAttributesThatStayViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IStructuredSelection selection = (IStructuredSelection) fAttributesThatStayViewer.getSelection(); if (!selection.isEmpty()) { handleLeftRightChange(fAttributesThatStayViewer, selection.getFirstElement()); } } }); fAttributesThatMoveViewer.setContentProvider(new IStructuredContentProvider() { public Object[] getElements(Object inputElement) { return fAttributesThatMove.toArray(); } public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } }); fAttributesThatMoveViewer.setLabelProvider(new BindingsLabelProvider()); fAttributesThatMoveViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { updateButtonsEnabled(); } }); fAttributesThatMoveViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IStructuredSelection selection = (IStructuredSelection) fAttributesThatMoveViewer.getSelection(); if (!selection.isEmpty()) { handleLeftRightChange(fAttributesThatMoveViewer, selection.getFirstElement()); } } }); createUpDownButtons(container); fAttributesThatStayViewer.setInput(fAttributesThatStay); fAttributesThatMoveViewer.setInput(fAttributesThatMove); updateButtonsEnabled(); setControl(container); }
From source file:com.iw.plugins.spindle.ui.wizards.source.MoveImplicitAttributesPage.java
License:Mozilla Public License
private void handleLeftRightChange(Viewer fromViewer, Object changeObject) { IStructuredSelection selection = null; if (changeObject instanceof ISelection) { selection = (IStructuredSelection) changeObject; } else {/* w ww. j a v a2 s .c o m*/ selection = new StructuredSelection(changeObject); } List fromList = null; List toList = null; TableViewer toViewer = null; if (fromViewer == fAttributesThatStayViewer) { fromList = fAttributesThatStay; toList = fAttributesThatMove; toViewer = fAttributesThatMoveViewer; } else { fromList = fAttributesThatMove; toList = fAttributesThatStay; toViewer = fAttributesThatStayViewer; } if (!selection.isEmpty()) { List selectedObjects = selection.toList(); fromList.removeAll(selectedObjects); toList.addAll(selectedObjects); fromViewer.setInput(fromList); toViewer.setInput(toViewer); toViewer.getControl().setFocus(); toViewer.setSelection(selection); } updateButtonsEnabled(); updateStatus(); }