Java Code Examples for org.eclipse.jface.viewers.ISelection

The following are top voted examples for showing how to use org.eclipse.jface.viewers.ISelection. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: gw4e.project   File: VertexDefaultSection.java   View source code 6 votes vote down vote up
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);
}
 
Example 2
Project: pgcodekeeper   File: SQLEditorContentOutlinePage.java   View source code 6 votes vote down vote up
@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();
        }
    }
}
 
Example 3
Project: eclipse-batch-editor   File: BatchEditor.java   View source code 6 votes vote down vote up
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();
			}
		}
	}
}
 
Example 4
Project: neoscada   File: ItemSelectionHelper.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
Project: neoscada   File: SelectionHelper.java   View source code 6 votes vote down vote up
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;
}
 
Example 6
Project: neoscada   File: ItemEditor.java   View source code 5 votes vote down vote up
/**
 * 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 );
                }
            }
        }
    }
}
 
Example 7
Project: n4js   File: LaunchXpectShortcut.java   View source code 5 votes vote down vote up
@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");
	}
}
 
Example 8
Project: n4js   File: GenerateXpectReportShortcut.java   View source code 5 votes vote down vote up
@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());
	}
}
 
Example 9
Project: neoscada   File: VisualInterfaceEditor.java   View source code 5 votes vote down vote up
/**
 * 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 );
                }
            }
        }
    }
}
 
Example 10
Project: n4js   File: CreateNewN4JSElementInModuleHandler.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 11
Project: n4js   File: ExternalLibraryPreferencePage.java   View source code 5 votes vote down vote up
/**
 * 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());
		}
	}
}
 
Example 12
Project: neoscada   File: RecipeEditor.java   View source code 5 votes vote down vote up
/**
 * 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 );
}
 
Example 13
Project: neoscada   File: ComponentEditor.java   View source code 5 votes vote down vote up
/**
 * 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 );
                }
            }
        }
    }
}
 
Example 14
Project: neoscada   File: ItemActionBarContributor.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 15
Project: convertigo-eclipse   File: ChangeToAttributeStepAction.java   View source code 5 votes vote down vote up
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) {}
}
 
Example 16
Project: eclipse-bash-editor   File: BashEditorContentOutlinePage.java   View source code 5 votes vote down vote up
@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);
}
 
Example 17
Project: n4js   File: TestResultsView.java   View source code 5 votes vote down vote up
/**
 * 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.");
		}

	}
}
 
Example 18
Project: neoscada   File: OsgiEditor.java   View source code 5 votes vote down vote up
/**
 * 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 );
}
 
Example 19
Project: n4js   File: TestDiscoveryUIUtils.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 20
Project: time4sys   File: GqamEditor.java   View source code 5 votes vote down vote up
/**
 * 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);
				}
			}
		}
	}
}
 
Example 21
Project: n4js   File: AbstractRunnerLaunchShortcut.java   View source code 5 votes vote down vote up
@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());
	}
}
 
Example 22
Project: neoscada   File: WorldEditor.java   View source code 5 votes vote down vote up
/**
 * <!-- 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$
        }
    }
}
 
Example 23
Project: time4sys   File: SrmEditor.java   View source code 5 votes vote down vote up
/**
 * 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);
}
 
Example 24
Project: neoscada   File: ItemEditor.java   View source code 5 votes vote down vote up
/**
 * 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 );
}
 
Example 25
Project: neoscada   File: ConfigurationEditor.java   View source code 5 votes vote down vote up
/**
 * 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 );
                }
            }
        }
    }
}
 
Example 26
Project: gw4e.project   File: EdgeDefaultSection.java   View source code 5 votes vote down vote up
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);
}
 
Example 27
Project: time4sys   File: SrmActionBarContributor.java   View source code 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example 28
Project: OCCI-Studio   File: SlaActionBarContributor.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 29
Project: SimQRI   File: MetamodelActionBarContributor.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 30
Project: OCCI-Studio   File: SlaEditor.java   View source code 5 votes vote down vote up
/**
 * 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);
				}
			}
		}
	}
}
 
Example 31
Project: com.onpositive.prefeditor   File: NewPreferenceDialog.java   View source code 5 votes vote down vote up
protected String valueFromSelection(ISelection selection) {
  	if (selection instanceof StructuredSelection) {
   	Object firstElement = ((IStructuredSelection) selection).getFirstElement();
       if (firstElement != null)
       	return firstElement.toString();
  	}
return null;
  }
 
Example 32
Project: time4sys   File: GqamEditor.java   View source code 5 votes vote down vote up
/**
 * <!-- 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("");
		}
	}
}
 
Example 33
Project: gw4e.project   File: TemplateComposite.java   View source code 5 votes vote down vote up
@Override
public void setSelection(ISelection selection) {
	this.selection = selection;
	for (ISelectionChangedListener iSelectionChangedListener : listeners) {
		iSelectionChangedListener.selectionChanged(new SelectionChangedEvent(this, selection));
	}
}
 
Example 34
Project: time4sys   File: NfpEditor.java   View source code 5 votes vote down vote up
/**
 * <!-- 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("");
		}
	}
}
 
Example 35
Project: gemoc-studio-modeldebugging   File: DSLToggleBreakpointsUtils.java   View source code 5 votes vote down vote up
/**
 * 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);
			}
		}
	}
}
 
Example 36
Project: time4sys   File: NfpActionBarContributor.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 37
Project: time4sys   File: Time4sysActionBarContributor.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 38
Project: gemoc-studio-modeldebugging   File: AbstractToggleBreakpointHandler.java   View source code 5 votes vote down vote up
/**
 * {@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;
}
 
Example 39
Project: convertigo-eclipse   File: CreateDesignDocumentViewReduceAction.java   View source code 5 votes vote down vote up
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());
	}
}
 
Example 40
Project: xmontiarc   File: RuntimeActionBarContributor.java   View source code 5 votes vote down vote up
/**
 * 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;
}