Example usage for org.eclipse.jface.viewers IStructuredSelection getFirstElement

List of usage examples for org.eclipse.jface.viewers IStructuredSelection getFirstElement

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection getFirstElement.

Prototype

public Object getFirstElement();

Source Link

Document

Returns the first element in this selection, or null if the selection is empty.

Usage

From source file:ca.uwaterloo.gp.fmp.presentation.FmpEditor.java

License:Open Source License

/**
 * This implements {@link org.eclipse.jface.action.IMenuListener} to help fill the context menus with contributions from the Edit menu.
 * <!-- begin-user-doc -->/*from   w  w  w .  jav  a  2 s . c  o m*/
 * Michal: add Go Into, Go Back and Go Home actions to the menu
 * Add expand subtree action
 * <!-- end-user-doc -->
 * @generated NOT
 */
public void menuAboutToShow(IMenuManager menuManager) {
    menuAboutToShowGen(menuManager);
    if (getActivePage() == 0)
        drillDownAdapter.addNavigationActions(menuManager);
    /**
     * Michal: this add an action to fully expand a subtree of a node 
     */
    if (editorSelection instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) editorSelection;
        Object object = selection.getFirstElement();
        if (object instanceof Node && ((Node) object).getChildren().size() > 0) {
            menuManager.insertAfter("additions", new ExpandSubtreeAction(object, currentViewer));
        }
    }
}

From source file:ca.uwaterloo.gp.fmp.system.drillDown.FmpDrillDownAdapter.java

License:Open Source License

/**
 * Returns whether "go into" is possible for child tree.  This is only possible 
 * if the current selection in the client has one item and it has children.
 *
 * @return <code>true</code> if "go into" is possible; <code>false</code> otherwise
 *///ww  w  . ja  v  a  2  s  . c o  m
public boolean canGoInto() {
    IStructuredSelection oSelection = (IStructuredSelection) fChildTree.getSelection();
    if (oSelection == null || oSelection.size() != 1)
        return false;
    Object anElement = oSelection.getFirstElement();
    return (RoleQuery.INSTANCE.getNodeType((Node) anElement) == RoleQuery.ROOT_FEATURE);
}

From source file:ca.uwaterloo.gp.fmp.system.drillDown.FmpDrillDownAdapter.java

License:Open Source License

/**
 * Sets the input for the tree to the current selection.
 * <p>//from w  w w.  j ava  2  s  .c  o m
 * The current input and expansion state are saved in a frame and added to the 
 * drill stack.  Then the input for the tree is changed to be the current selection.  
 * The expansion state for the tree is maintained during the operation.
 * </p><p>
 * On return the client may revert back to the previous state by invoking 
 * <code>goBack</code> or <code>goHome</code>.
 * </p>
 */
public void goInto() {
    IStructuredSelection sel = (IStructuredSelection) fChildTree.getSelection();
    Object element = sel.getFirstElement();
    if (RoleQuery.INSTANCE.getNodeType((Node) element) == RoleQuery.ROOT_FEATURE) {
        Feature selected = (Feature) element;

        ProxyItemProvider root = new ProxyItemProvider(adapterFactory, selected.eContainer(), selected);
        goInto(root);
    }
}

From source file:cane.brothers.e4.commander.part.DynamicTab.java

License:Open Source License

@Override
public void selectionChanged(SelectionChangedEvent event) {
    Object prevSelection = selectionService.getSelection();
    if (log.isDebugEnabled()) {
        log.debug("Prev selection is {}", prevSelection); //$NON-NLS-1$
    }/*from  w w  w  .ja  v  a2 s  .co m*/

    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    boolean hasSelection = selection != null && selection.isEmpty() == false;

    if (hasSelection) {
        Object firstElement = selection.getFirstElement();
        if (log.isDebugEnabled()) {
            log.debug("Current selection is {}", firstElement); //$NON-NLS-1$
        }

        // set the selection to the service
        selectionService.setSelection(firstElement);

        if (log.isDebugEnabled()) {
            log.debug("Selection changed:"); //$NON-NLS-1$
        }

        // trace selected objects
        for (Object sel : selection.toArray()) {
            if (sel instanceof PathFixture) {
                PathFixture fixture = (PathFixture) sel;
                if (log.isDebugEnabled()) {
                    log.debug("   " + fixture); //$NON-NLS-1$
                }
            }
        }
    }
}

From source file:carisma.modeltype.bpmn2.popup.ConvertEmfAction.java

License:Open Source License

/**
 * @see IActionDelegate#selectionChanged(IAction, ISelection)
 *//*from w  w  w .  j av  a2s.c  o  m*/
@Override
public void selectionChanged(final IAction action, final ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        this.selectedFile = (IFile) structuredSelection.getFirstElement();
    }
}

From source file:carisma.ui.eclipse.editors.AdfEditorCheckDetailsPage.java

License:Open Source License

@Override
public final void selectionChanged(final IFormPart part, final ISelection selection) {
    if (selection != null && !selection.isEmpty()) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() == 1) {
            this.input = (CheckReference) ssel.getFirstElement();
            if (this.descriptionSection != null) {
                this.descriptionSection.dispose();
            }//from w w  w . java 2  s .  c om
            if (this.parameterSection != null) {
                this.parameterSection.dispose();
            }
            createDescriptionSection(this.input);
            createParameterSection(this.input);
            this.parentComposite.layout(); // refresh
        }
    } else {
        createDescriptionSection(null);
    }
}

From source file:carisma.ui.eclipse.popup.actions.RunAnalysisAction.java

License:Open Source License

@Override
public final void selectionChanged(final IAction action, final ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        this.selectedFile = (IFile) structuredSelection.getFirstElement();
    }/*  w  ww. j  a v a 2 s.  co m*/

}

From source file:carisma.ui.eclipse.popup.actions.RunAnalysisAction.java

License:Open Source License

/**
 * Selection in Project navigator, not in editor. 
 * @return true, if an resource was selected
 *//*w w w .  j a  v a2s  .com*/
public final boolean initSelectionByService() {
    try {
        IWorkbenchWindow ww = org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        ISelection selection = ww.getSelectionService().getSelection();
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        this.selectedFile = (IFile) structuredSelection.getFirstElement();

        return true;

    } catch (NullPointerException npe) {
        Logger.log(LogLevel.INFO, "No resource selected");
    }
    return false;
}

From source file:cc.warlock.rcp.prefs.HighlightStringsPreferencePage.java

License:Open Source License

private void createStringsTable(Composite main) {
    Group stringsGroup = new Group(main, SWT.NONE);
    stringsGroup.setLayout(new GridLayout(2, false));
    stringsGroup.setText(getDisplayName());
    stringsGroup.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));

    Composite filterComposite = new Composite(stringsGroup, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = layout.marginHeight = 0;
    filterComposite.setLayout(layout);/*from   w  w  w  . j  av  a 2s.  c  o  m*/
    filterComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    new Label(filterComposite, SWT.NONE).setText("Filter: ");
    filterText = new Text(filterComposite, SWT.BORDER);
    filterText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            stringTable.refresh();
        }
    });
    filterText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    new Label(stringsGroup, SWT.NONE);

    try {
        WarlockPreferencesScope.getInstance().getNode().sync();
    } catch (BackingStoreException e) {
        e.printStackTrace();
    }

    stringTable = new TableViewer(stringsGroup, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
    TableColumn column = new TableColumn(stringTable.getTable(), SWT.NONE, 0);
    column.setWidth(400);

    stringTable.setUseHashlookup(true);
    stringTable.setColumnProperties(new String[] { "highlightString" });

    CellEditor editors[] = new CellEditor[] { new TextCellEditor(stringTable.getTable()) };

    stringTable.setCellEditors(editors);
    stringTable.setCellModifier(new ICellModifier() {
        public boolean canModify(Object element, String property) {
            return true;
        }

        public Object getValue(Object element, String property) {
            return ((PatternSetting) element).getText();
        }

        public void modify(Object element, String property, Object value) {
            TableItem item = (TableItem) element;
            PatternSetting string = (PatternSetting) item.getData();
            String pattern = ((String) value).trim();

            try {
                string.setText(pattern);
            } catch (PatternSyntaxException e) {
                e.printStackTrace();
            }
            stringTable.refresh(string);
        }
    });

    stringTable.addFilter(new ViewerFilter() {
        public boolean select(Viewer viewer, Object parentElement, Object element) {

            PatternSetting string = (PatternSetting) element;
            String str = string.getText();

            if (str.equals(""))
                return true;

            return (str.toLowerCase().contains(filterText.getText().toLowerCase()));
        }
    });

    stringTable.setLabelProvider(new StringsLabelProvider());
    stringTable.setContentProvider(ArrayContentProvider.getInstance());

    int listHeight = stringTable.getTable().getItemHeight() * 8;
    Rectangle trim = stringTable.getTable().computeTrim(0, 0, 0, listHeight);
    GridData data = new GridData(GridData.FILL, GridData.FILL, true, true);
    data.heightHint = trim.height;
    stringTable.getTable().setLayoutData(data);

    stringTable.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            PatternSetting string = (PatternSetting) selection.getFirstElement();

            if (string != selectedString) {
                stringTable.cancelEditing();
            }

            highlightStringSelected(string);
        }
    });

    Composite buttonsComposite = new Composite(stringsGroup, SWT.NONE);
    buttonsComposite.setLayout(new GridLayout(1, true));
    buttonsComposite.setLayoutData(new GridData(GridData.CENTER, GridData.BEGINNING, true, true));

    addString = createButton(buttonsComposite, "Add", SWT.LEFT | SWT.PUSH);
    addString.setImage(WarlockSharedImages.getImage(WarlockSharedImages.IMG_ADD));
    addString.setLayoutData(new GridData(GridData.FILL_BOTH));

    removeString = createButton(buttonsComposite, "Remove", SWT.LEFT | SWT.PUSH);
    removeString.setImage(WarlockSharedImages.getImage(WarlockSharedImages.IMG_REMOVE));
    removeString.setEnabled(false);
}

From source file:cc.warlock.rcp.prefs.ScriptingPreferencePage.java

License:Open Source License

protected void removeDirectoryClicked() {
    IStructuredSelection selection = (IStructuredSelection) scriptDirectories.getSelection();
    DirectorySetting directory = (DirectorySetting) selection.getFirstElement();

    ScriptConfiguration.instance().getScriptDirectoryConfiguration().removeSetting(directory);
    scriptDirectories.remove(directory);
}