public void setInput(IWorkbenchPart part, ISelection selection) { super.setInput(part, selection); txtNameDecorator.hide(); txtSharedNameDecorator.hide(); Object input = ((IStructuredSelection) selection).getFirstElement(); this.sectionProvider = (SectionProvider) input; AbstractGW4EEditPartProperties properties = (AbstractGW4EEditPartProperties) sectionProvider .getAdapter(IPropertySource.class); textName.setEnabled(properties.isUpdatable(ModelProperties.PROPERTY_NAME)); btnCheckShrd.setEnabled(properties.isUpdatable(ModelProperties.PROPERTY_VERTEX_SHARED)); btnCheckBlocked.setEnabled(properties.isUpdatable(ModelProperties.PROPERTY_BLOCKED)); textDescription.setEnabled(properties.isUpdatable(ModelProperties.PROPERTY_DESCRIPTION)); textRequirements.setEnabled(properties.isUpdatable(ModelProperties.PROPERTY_VERTEX_REQUIREMENTS)); textSharedName.setEnabled(properties.isUpdatable(ModelProperties.PROPERTY_VERTEX_SHAREDNAME)); ((GWNode) this.sectionProvider.getModel()).removePropertyChangeListener(this); ((GWNode) this.sectionProvider.getModel()).addPropertyChangeListener(this); }
@Override public void selectionChanged(SelectionChangedEvent event) { super.selectionChanged(event); ISelection selection = event.getSelection(); if (selection.isEmpty()) { sqlEditor.resetHighlightRange(); } else { Segments segment = (Segments) ((IStructuredSelection) selection) .getFirstElement(); int start = segment.getOffset(); int length = segment.getLength(); try { sqlEditor.setHighlightRange(start, length, true); sqlEditor.selectAndReveal(start, length); } catch (IllegalArgumentException x) { sqlEditor.resetHighlightRange(); } } }
public void openSelectedTreeItemInEditor(ISelection selection, boolean grabFocus) { if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; Object firstElement = ss.getFirstElement(); if (firstElement instanceof Item) { Item item = (Item) firstElement; int offset = item.getOffset(); int length = item.getLength(); if (length == 0) { /* fall back */ length = 1; } ignoreNextCaretMove = true; selectAndReveal(offset, length); if (grabFocus) { setFocus(); } } } }
/** * Get all {@link Item} instances from the current selection * * @param selection * the selection * @return the item instances */ public static Collection<Item> getSelection ( final ISelection selection ) { final Collection<Item> items = new LinkedList<Item> (); if ( selection == null || selection.isEmpty () ) { return items; } if ( selection instanceof IStructuredSelection ) { final Iterator<?> i = ( (IStructuredSelection)selection ).iterator (); while ( i.hasNext () ) { final Item item = AdapterHelper.adapt ( i.next (), Item.class ); if ( item != null ) { items.add ( item ); } } } return items; }
public static List<?> list ( final ISelection selection ) { final List<Object> result = new LinkedList<Object> (); if ( selection instanceof IStructuredSelection ) { final Iterator<?> i = ( (IStructuredSelection)selection ).iterator (); while ( i.hasNext () ) { final Object o = i.next (); if ( o == null ) { continue; } result.add ( o ); } } return result; }
/** * This deals with how we want selection in the outliner to affect the other views. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void handleContentOutlineSelection ( ISelection selection ) { if ( currentViewerPane != null && !selection.isEmpty () && selection instanceof IStructuredSelection ) { Iterator<?> selectedElements = ( (IStructuredSelection)selection ).iterator (); if ( selectedElements.hasNext () ) { // Get the first selected element. // Object selectedElement = selectedElements.next (); // If it's the selection viewer, then we want it to select the same selection as this selection. // if ( currentViewerPane.getViewer () == selectionViewer ) { ArrayList<Object> selectionList = new ArrayList<Object> (); selectionList.add ( selectedElement ); while ( selectedElements.hasNext () ) { selectionList.add ( selectedElements.next () ); } // Set the selection to the widget. // selectionViewer.setSelection ( new StructuredSelection ( selectionList ) ); } else { // Set the input to the widget. // if ( currentViewerPane.getViewer ().getInput () != selectedElement ) { currentViewerPane.getViewer ().setInput ( selectedElement ); currentViewerPane.setTitle ( selectedElement ); } } } } }
@Override public void launch(ISelection selection, String mode) { try { Object selectObj = ((IStructuredSelection) selection).getFirstElement(); if (selectObj instanceof IFile) { launchFile((IFile) selectObj, mode); } else { showDialogNotImplemented(selection.getClass().getName()); } } catch (CoreException e) { System.out.println(e.getLocalizedMessage() + "\n"); } }
@Override public void launch(ISelection selection, String mode) { Object selectObj = ((IStructuredSelection) selection).getFirstElement(); if (selectObj instanceof IFile) { generateBug((IFile) selectObj); } else { showDialogNotImplemented(selection.getClass().getName()); } }
/** * Returns the active tree resource selection if there is one. * * Examines the active workspace selection and if it is a resource inside of a tree returns it. * * @param event * The execution event * @returns The resource or {@code null} on failure. * */ private static IResource getActiveTreeResourceSelection(ExecutionEvent event) { ISelection activeSelection = HandlerUtil.getCurrentSelection(event); if (activeSelection instanceof TreeSelection) { Object firstElement = ((TreeSelection) activeSelection).getFirstElement(); if (firstElement instanceof IResource) { return (IResource) firstElement; } } return null; }
/** * Selection handler for moving up an external library location in the list. */ private void handleMoveUpButtonSelection(@SuppressWarnings("unused") final SelectionEvent e) { final ISelection selection = viewer.getSelection(); if (selection instanceof IStructuredSelection && !selection.isEmpty()) { final Object element = ((IStructuredSelection) selection).getFirstElement(); if (element instanceof URI) { store.moveUp((URI) element); updateInput(viewer, store.getLocations()); } } }
/** * This implements {@link org.eclipse.jface.viewers.ISelectionProvider} to set this editor's overall selection. * Calling this result will notify the listeners. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setSelection ( ISelection selection ) { editorSelection = selection; for ( ISelectionChangedListener listener : selectionChangedListeners ) { listener.selectionChanged ( new SelectionChangedEvent ( this, selection ) ); } setStatusLineManager ( selection ); }
/** * This generates a {@link org.eclipse.emf.edit.ui.action.CreateChildAction} for each object in <code>descriptors</code>, * and returns the collection of these actions. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected Collection<IAction> generateCreateChildActions ( Collection<?> descriptors, ISelection selection ) { Collection<IAction> actions = new ArrayList<IAction> (); if ( descriptors != null ) { for ( Object descriptor : descriptors ) { actions.add ( new CreateChildAction ( activeEditorPart, selection, descriptor ) ); } } return actions; }
public void selectionChanged(IAction action, ISelection selection) { try { boolean enable = false; super.selectionChanged(action, selection); IStructuredSelection structuredSelection = (IStructuredSelection) selection; TreeObject treeObject = (TreeObject) structuredSelection.getFirstElement(); if (treeObject instanceof DatabaseObjectTreeObject) { DatabaseObject dbo = (DatabaseObject) treeObject.getObject(); ActionModel actionModel = DatabaseObjectsAction.selectionChanged(getClass().getName(), dbo); enable = actionModel.isEnabled; } action.setEnabled(enable); } catch (Exception e) {} }
@Override public void doubleClick(DoubleClickEvent event) { if (editor == null) { return; } if (linkingWithEditorEnabled) { editor.setFocus(); // selection itself is already handled by single click return; } ISelection selection = event.getSelection(); editor.openSelectedTreeItemInEditor(selection, true); }
/** * Invoked when user double-clicks a result node in the UI. */ protected void onDoubleClick() { final ISelection selection = testTreeViewer.getSelection(); final ResultNode resultNode = (ResultNode) ((IStructuredSelection) selection).getFirstElement(); if (resultNode == null) { return; } TestElement testElement = resultNode.getElement(); if (testElement instanceof TestCase) { final URI testCaseURI = ((TestCase) testElement).getURI(); if (testCaseURI == null) { return; } final IN4JSEclipseProject project = core.findProject(testCaseURI).orNull(); if (null != project && project.exists()) { final URI moduleLocation = testCaseURI.trimFragment(); final String[] projectRelativeSegments = moduleLocation.deresolve(project.getLocation()).segments(); final String path = Joiner.on(SEPARATOR) .join(copyOfRange(projectRelativeSegments, 1, projectRelativeSegments.length)); final IFile module = project.getProject().getFile(path); if (null != module && module.isAccessible()) { uriOpener.open(testCaseURI, true); } else { openError(getShell(), "Cannot open editor", "Test class not found in selected project."); } } else { openError(getShell(), "Cannot open editor", "The container project not found in the workspace."); } } }
/** * Derives a location URI as expected by {@link TestDiscoveryHelper#collectTests(URI...)} from a selection. */ public static final URI getLocationForSelection(ISelection selection) { if (selection instanceof IStructuredSelection) { final Object selObj = ((IStructuredSelection) selection).getFirstElement(); if (selObj instanceof IResource) return getLocationForResource((IResource) selObj); } return null; }
/** * This deals with how we want selection in the outliner to affect the other views. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void handleContentOutlineSelection(ISelection selection) { if (currentViewerPane != null && !selection.isEmpty() && selection instanceof IStructuredSelection) { Iterator<?> selectedElements = ((IStructuredSelection)selection).iterator(); if (selectedElements.hasNext()) { // Get the first selected element. // Object selectedElement = selectedElements.next(); // If it's the selection viewer, then we want it to select the same selection as this selection. // if (currentViewerPane.getViewer() == selectionViewer) { ArrayList<Object> selectionList = new ArrayList<Object>(); selectionList.add(selectedElement); while (selectedElements.hasNext()) { selectionList.add(selectedElements.next()); } // Set the selection to the widget. // selectionViewer.setSelection(new StructuredSelection(selectionList)); } else { // Set the input to the widget. // if (currentViewerPane.getViewer().getInput() != selectedElement) { currentViewerPane.getViewer().setInput(selectedElement); currentViewerPane.setTitle(selectedElement); } } } } }
@Override public void launch(ISelection selection, String mode) { Object selectObj = ((IStructuredSelection) selection).getFirstElement(); if (selectObj instanceof IFile) { launchFile((IFile) selectObj, mode); } else { showDialogNotImplemented(selection.getClass().getName()); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setStatusLineManager ( ISelection selection ) { IStatusLineManager statusLineManager = currentViewer != null && currentViewer == contentOutlineViewer ? contentOutlineStatusLineManager : getActionBars ().getStatusLineManager (); if ( statusLineManager != null ) { if ( selection instanceof IStructuredSelection ) { Collection<?> collection = ( (IStructuredSelection)selection ).toList (); switch ( collection.size () ) { case 0: { statusLineManager.setMessage ( getString ( "_UI_NoObjectSelected" ) ); //$NON-NLS-1$ break; } case 1: { String text = new AdapterFactoryItemDelegator ( adapterFactory ).getText ( collection.iterator ().next () ); statusLineManager.setMessage ( getString ( "_UI_SingleObjectSelected", text ) ); //$NON-NLS-1$ break; } default: { statusLineManager.setMessage ( getString ( "_UI_MultiObjectSelected", Integer.toString ( collection.size () ) ) ); //$NON-NLS-1$ break; } } } else { statusLineManager.setMessage ( "" ); //$NON-NLS-1$ } } }
/** * This implements {@link org.eclipse.jface.viewers.ISelectionProvider} to set this editor's overall selection. * Calling this result will notify the listeners. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setSelection(ISelection selection) { editorSelection = selection; for (ISelectionChangedListener listener : selectionChangedListeners) { listener.selectionChanged(new SelectionChangedEvent(this, selection)); } setStatusLineManager(selection); }
public void setInput(IWorkbenchPart part, ISelection selection) { super.setInput(part, selection); textWeightDecorator.hide(); Object input = ((IStructuredSelection) selection).getFirstElement(); this.node = (SectionProvider) input; AbstractGW4EEditPartProperties properties = (AbstractGW4EEditPartProperties) node .getAdapter(IPropertySource.class); textName.setEnabled(properties.isUpdatable(ModelProperties.PROPERTY_NAME)); ((GWNode) this.node.getModel()).removePropertyChangeListener(this); ((GWNode) this.node.getModel()).addPropertyChangeListener(this); }
/** * This implements {@link org.eclipse.jface.viewers.ISelectionChangedListener}, * handling {@link org.eclipse.jface.viewers.SelectionChangedEvent}s by querying for the children and siblings * that can be added to the selected object and updating the menus accordingly. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void selectionChanged(SelectionChangedEvent event) { // Remove any menu items for old selection. // if (createChildMenuManager != null) { depopulateManager(createChildMenuManager, createChildActions); } if (createSiblingMenuManager != null) { depopulateManager(createSiblingMenuManager, createSiblingActions); } // Query the new selection for appropriate new child/sibling descriptors // Collection<?> newChildDescriptors = null; Collection<?> newSiblingDescriptors = null; ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection && ((IStructuredSelection)selection).size() == 1) { Object object = ((IStructuredSelection)selection).getFirstElement(); EditingDomain domain = ((IEditingDomainProvider)activeEditorPart).getEditingDomain(); newChildDescriptors = domain.getNewChildDescriptors(object, null); newSiblingDescriptors = domain.getNewChildDescriptors(null, object); } // Generate actions for selection; populate and redraw the menus. // createChildActions = generateCreateChildActions(newChildDescriptors, selection); createSiblingActions = generateCreateSiblingActions(newSiblingDescriptors, selection); if (createChildMenuManager != null) { populateManager(createChildMenuManager, createChildActions, null); createChildMenuManager.update(true); } if (createSiblingMenuManager != null) { populateManager(createSiblingMenuManager, createSiblingActions, null); createSiblingMenuManager.update(true); } }
/** * This generates a {@link org.eclipse.emf.edit.ui.action.CreateChildAction} for each object in <code>descriptors</code>, * and returns the collection of these actions. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected Collection<IAction> generateCreateChildActions(Collection<?> descriptors, ISelection selection) { Collection<IAction> actions = new ArrayList<IAction>(); if (descriptors != null) { for (Object descriptor : descriptors) { actions.add(new CreateChildAction(activeEditorPart, selection, descriptor)); } } return actions; }
/** * This generates a {@link org.eclipse.emf.edit.ui.action.CreateSiblingAction} for each object in <code>descriptors</code>, * and returns the collection of these actions. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected Collection<IAction> generateCreateSiblingActions(Collection<?> descriptors, ISelection selection) { Collection<IAction> actions = new ArrayList<IAction>(); if (descriptors != null) { for (Object descriptor : descriptors) { actions.add(new CreateSiblingAction(activeEditorPart, selection, descriptor)); } } return actions; }
protected String valueFromSelection(ISelection selection) { if (selection instanceof StructuredSelection) { Object firstElement = ((IStructuredSelection) selection).getFirstElement(); if (firstElement != null) return firstElement.toString(); } return null; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setStatusLineManager(ISelection selection) { IStatusLineManager statusLineManager = currentViewer != null && currentViewer == contentOutlineViewer ? contentOutlineStatusLineManager : getActionBars().getStatusLineManager(); if (statusLineManager != null) { if (selection instanceof IStructuredSelection) { Collection<?> collection = ((IStructuredSelection)selection).toList(); switch (collection.size()) { case 0: { statusLineManager.setMessage(getString("_UI_NoObjectSelected")); break; } case 1: { String text = new AdapterFactoryItemDelegator(adapterFactory).getText(collection.iterator().next()); statusLineManager.setMessage(getString("_UI_SingleObjectSelected", text)); break; } default: { statusLineManager.setMessage(getString("_UI_MultiObjectSelected", Integer.toString(collection.size()))); break; } } } else { statusLineManager.setMessage(""); } } }
@Override public void setSelection(ISelection selection) { this.selection = selection; for (ISelectionChangedListener iSelectionChangedListener : listeners) { iSelectionChangedListener.selectionChanged(new SelectionChangedEvent(this, selection)); } }
/** * Toggles a {@link DSLBreakpoint} for the given selection. * * @param selection * the {@link ISelection} * @throws CoreException * if {@link DSLBreakpoint} can't be retrieved or installed */ public void toggleBreakpoints(ISelection selection) throws CoreException { if (selection instanceof IStructuredSelection) { @SuppressWarnings("unchecked") final Iterator<Object> it = ((IStructuredSelection)selection).iterator(); while (it.hasNext()) { final Object selected = it.next(); EObject instruction = getInstruction(selected); if (instruction != null) { toggleBreakpoint(selected, instruction); } } } }
/** * {@inheritDoc} * * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { final ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); try { breakpointUtils.toggleBreakpoints(selection); } catch (CoreException e) { throw new ExecutionException("Error while toggling breakpoint.", e); } return null; }
public void selectionChanged(IAction action, ISelection selection) { super.selectionChanged(action, selection); IStructuredSelection structuredSelection = (IStructuredSelection) selection; TreeObject treeObject = (TreeObject) structuredSelection.getFirstElement(); if (treeObject instanceof DesignDocumentViewTreeObject) { DesignDocumentViewTreeObject ddvto = (DesignDocumentViewTreeObject)treeObject; action.setText(CouchKey.reduce.key() + " function"); action.setEnabled(!ddvto.hasReduce()); } }