List of usage examples for org.eclipse.jface.viewers IStructuredSelection isEmpty
public boolean isEmpty();
From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.editor.ApplicationMasterPart.java
License:Open Source License
private void fillServicesContextMenu(IMenuManager manager) { IStructuredSelection selection = (IStructuredSelection) servicesViewer.getSelection(); if (selection.isEmpty()) { return;//w w w. j a v a 2 s .co m } // manager.add(new DeleteServicesAction(selection, cloudServer.getBehaviour(), editorPage)); // [87165642] - For now only support service binding/unbinding for one // selected // service if (selection.size() == 1) { manager.add(new ServiceToApplicationsBindingAction(selection, cloudServer.getBehaviour(), editorPage)); } }
From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.editor.ApplicationMasterPart.java
License:Open Source License
private void fillApplicationsContextMenu(IMenuManager manager) { IStructuredSelection selection = (IStructuredSelection) applicationsViewer.getSelection(); if (selection.isEmpty()) { return;//from w w w . j a va 2 s . c om } IModule module = (IModule) selection.getFirstElement(); if (module != null) { manager.add( new RemoveModuleAction(getSection().getShell(), editorPage.getServer().getOriginal(), module)); } }
From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.EnvironmentVariablesPart.java
License:Open Source License
protected List<EnvironmentVariable> getViewerSelection() { IStructuredSelection selection = (IStructuredSelection) envVariablesViewer.getSelection(); List<EnvironmentVariable> selectedVars = new ArrayList<EnvironmentVariable>(); if (!selection.isEmpty()) { Object[] servicesObjs = selection.toArray(); for (Object serviceObj : servicesObjs) { selectedVars.add((EnvironmentVariable) serviceObj); }//from w ww. ja va 2s. c o m } return selectedVars; }
From source file:cn.ieclipse.adt.ext.helpers.ProjectHelper.java
License:Apache License
/** * Utility method to inspect a selection to find a Java element. * //from w w w . j av a2 s .com * @param selection * the selection to be inspected * @return a Java element to be used as the initial selection, or * <code>null</code>, if no Java element exists in the given * selection */ public static IJavaElement getInitialJavaElement(IStructuredSelection selection) { IJavaElement jelem = null; if (selection != null && !selection.isEmpty()) { Object selectedElement = selection.getFirstElement(); System.out.println(selectedElement.getClass()); if (selectedElement instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) selectedElement; jelem = (IJavaElement) adaptable.getAdapter(IJavaElement.class); if (jelem == null || !jelem.exists()) { jelem = null; IResource resource = (IResource) adaptable.getAdapter(IResource.class); if (resource != null && resource.getType() != IResource.ROOT) { while (jelem == null && resource.getType() != IResource.PROJECT) { resource = resource.getParent(); jelem = (IJavaElement) resource.getAdapter(IJavaElement.class); } if (jelem == null) { jelem = JavaCore.create(resource); // java project } } } } } return jelem; }
From source file:cn.ieclipse.adt.ext.wizards.ElementTableSelector.java
License:Apache License
public ElementTableSelector(final Composite composite, GridData gridData, final String groupDescr, final String selectionMessage, final Object[] elements) { this.elements = elements; Group intentGroup = new Group(composite, SWT.NONE); intentGroup.setLayout(new GridLayout(2, false)); intentGroup.setLayoutData(gridData); intentGroup.setText(groupDescr);/*from w ww.j a v a2s . c o m*/ tv = new TableViewer(intentGroup, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION); table = tv.getTable(); table.setHeaderVisible(false); table.setLinesVisible(true); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); final Menu menu = new Menu(tv.getControl()); MenuItem add = new MenuItem(menu, SWT.PUSH); add.setText("&Add Custom"); add.setImage(ADD_IMG); add.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { addModel(new Model("custom")); tv.refresh(); } }); MenuItem up = new MenuItem(menu, SWT.PUSH); up.setText("&Up"); up.setImage(UP_IMG); up.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection sel = (IStructuredSelection) tv.getSelection(); if (!sel.isEmpty()) { Model m = (Model) sel.getFirstElement(); int idx = selectedElements.indexOf(m); if (idx > 0) { Model n = selectedElements.get(idx - 1); selectedElements.set(idx, n); selectedElements.set(idx - 1, m); tv.refresh(); } } } }); MenuItem down = new MenuItem(menu, SWT.PUSH); down.setText("&Down"); down.setImage(DOWN_IMG); down.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection sel = (IStructuredSelection) tv.getSelection(); if (!sel.isEmpty()) { Model m = (Model) sel.getFirstElement(); int idx = selectedElements.indexOf(m); if (idx < selectedElements.size() - 1) { Model n = selectedElements.get(idx + 1); selectedElements.set(idx, n); selectedElements.set(idx + 1, m); tv.refresh(); } } } }); table.setMenu(menu); tv.setContentProvider(new MyContentProvider()); ColumnViewerToolTipSupport.enableFor(tv, ToolTip.NO_RECREATE); // TableViewerFocusCellManager focusCellManager = new // TableViewerFocusCellManager( // tv, new FocusBorderCellHighlighter(tv)); ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(tv) { protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) { return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR) || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC; } }; TableViewerEditor.create(tv, null, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION); final TableViewerColumn col = new TableViewerColumn(tv, SWT.NONE); col.setLabelProvider(new MyCellLabelProvider()); col.setEditingSupport(new MyEditingSupport(tv)); // tv.getTable(). col.getColumn().setWidth(300); table.addControlListener(new ControlListener() { public void controlResized(ControlEvent e) { int w = table.getClientArea().width; if (w > 0) { col.getColumn().setWidth(w); } } public void controlMoved(ControlEvent e) { } }); tv.setInput(selectedElements); Composite buttonComp = new Composite(intentGroup, SWT.NONE); buttonComp.setLayout(new FillLayout(SWT.VERTICAL)); addButton = new Button(buttonComp, SWT.NONE); addButton.setText("Add..."); addButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { showSelectionDialog(composite, selectionMessage); } public void widgetDefaultSelected(SelectionEvent e) { } }); removeButton = new Button(buttonComp, SWT.NONE); removeButton.setText("Remove..."); removeButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int[] selection = table.getSelectionIndices(); if (selection != null) { IStructuredSelection sel = (IStructuredSelection) tv.getSelection(); if (!sel.isEmpty()) { for (Object object : sel.toArray()) { selectedElements.remove(object); } } tv.refresh(); } } }); }
From source file:cn.ieclipse.aorm.eclipse.helpers.ProjectHelper.java
License:Apache License
/** * Utility method to inspect a selection to find a Java element. * //from ww w .ja va2 s . co m * @param selection * the selection to be inspected * @return a Java element to be used as the initial selection, or * <code>null</code>, if no Java element exists in the given * selection */ public static IJavaElement getInitialJavaElement(IStructuredSelection selection) { IJavaElement jelem = null; 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 || !jelem.exists()) { jelem = null; IResource resource = (IResource) adaptable.getAdapter(IResource.class); if (resource != null && resource.getType() != IResource.ROOT) { while (jelem == null && resource.getType() != IResource.PROJECT) { resource = resource.getParent(); jelem = (IJavaElement) resource.getAdapter(IJavaElement.class); } if (jelem == null) { jelem = JavaCore.create(resource); // java project } } } } } return jelem; }
From source file:codeshine.utils.TableFieldEditor.java
License:Open Source License
/** * <p>/*from w w w .j av a2s .com*/ * Gets the currently selected value of this <code>TableFieldEditor</code>. * The value returned by this method depends on the selection column * set up as returned by {@link #getSelectionColumn()}. If the selection * column is set to <code>-1</code> the complete row represented as * domain object is returned by calling {@link #toString()} on it. * Otherwise the respective column value is queried and returned using * the <code>ITableLabelProvider</code> bound to this * <code>TableFieldEditor</code>. * </p> * * @return the currently selected value or an empty <code>String</code> * if no selection * * @see #setSelectionColumn(int) * @see #getSelectionColumn() */ public String getSelection() { IStructuredSelection selection = (IStructuredSelection) this.viewer.getSelection(); if (selection.isEmpty()) { /* Empty selection */ return (StringUtils.EMPTY_STRING); } else if (this.selectionColumn == -1) { /* Row selection */ return (selection.getFirstElement().toString()); } else { /* Column selection */ return (this.labelProvider.getColumnText(selection.getFirstElement(), this.selectionColumn)); } }
From source file:codeshine.utils.TableFieldEditor.java
License:Open Source License
/** * <p>//w ww. jav a 2s. co m * Informs this field editor's listener, if it has one, about a change to * the value (<code>VALUE</code> property) provided that the old and new * values are different. This hook is <em>not</em> called when the value is * initialized (or reset to the default value) from the preference store. * </p> */ protected void valueChanged() { System.out.println("Invocado ValueChanged"); this.setPresentsDefaultValue(false); final IStructuredSelection selection = (IStructuredSelection) this.viewer.getSelection(); String newValue; // System.out.println("NewVAlue: " + newValue); if (selection.isEmpty()) { newValue = StringUtils.EMPTY_STRING; } else if (this.selectionColumn == -1) { newValue = selection.getFirstElement().toString(); } else { newValue = this.labelProvider.getColumnText(selection.getFirstElement(), this.selectionColumn); } if (newValue.equals(oldValue)) { this.fireValueChanged(VALUE, oldValue, newValue); oldValue = newValue; } }
From source file:com.amalto.workbench.detailtabs.sections.composites.SimpleTypeConfigComposite.java
License:Open Source License
private XSDSimpleTypeDefinition getCurSelectedBuildInBaseType() { IStructuredSelection selection = (IStructuredSelection) comboBuildInTypes.getSelection(); if (selection == null || selection.isEmpty()) { return null; }//from ww w . j a v a 2 s . co m return (XSDSimpleTypeDefinition) selection.getFirstElement(); }
From source file:com.amalto.workbench.detailtabs.sections.composites.SimpleTypeConfigComposite.java
License:Open Source License
private XSDSimpleTypeDefinition getCurSelectedCustomBaseType() { IStructuredSelection selection = (IStructuredSelection) comboCustomTypes.getSelection(); if (selection == null || selection.isEmpty()) { return null; }//from w w w . j a v a2s .co m XSDSimpleTypeDefinition curSelectedCustomBaseType = xsdSimpleType.getSchema().resolveSimpleTypeDefinition( xsdSimpleType.getSchema().getSchemaForSchemaNamespace(), (String) selection.getFirstElement()); if (!xsdSimpleType.getSchema().getTypeDefinitions().contains(curSelectedCustomBaseType)) { return xsdSimpleType.getSchema() .resolveSimpleTypeDefinition(xsdSimpleType.getSchema().getSchemaForSchemaNamespace(), "string");//$NON-NLS-1$ } return curSelectedCustomBaseType; }