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

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

Introduction

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

Prototype

@Override
    public Object getFirstElement() 

Source Link

Usage

From source file:ch.wess.ezclipse.varbrowser.internal.VarBrowser.java

License:Open Source License

/**
 * This method is called everytime when the selection changed. We are only
 * interested to know when the TPL editor selection is changing because we
 * need to update the node id of the actual file.
 *//* ww w  .  ja  v a 2 s.c om*/
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    if (selection instanceof StructuredSelection) {
        StructuredSelection ss = (StructuredSelection) selection;
        Object element = ss.getFirstElement();
        if (element instanceof IFile) {
            IFile file = (IFile) element;
            IProject project = file.getProject();
            try {
                String nodeId = file.getPersistentProperty(IFileProperties.NODE_ID);
                if (nodeId != null && !nodeId.equals("")) { //$NON-NLS-1$
                    VariableTreeInput input = new VariableTreeInput(project, nodeId);
                    treeViewer.setInput(input);
                } else {
                    VariableTreeInput input = new VariableTreeInput(null, ""); //$NON-NLS-1$
                    treeViewer.setInput(input);
                }
            } catch (CoreException coreEx) {
                VariableTreeInput input = new VariableTreeInput(null, ""); //$NON-NLS-1$
                treeViewer.setInput(input);
            }

        }
    }
}

From source file:com.aerospike.core.navigator.ClusterPropertiesAction.java

License:Apache License

@Override
public void run(IAction action) {
    StructuredSelection ss = (StructuredSelection) selection;

    Object firstOne = ss.getFirstElement();
    if (!(firstOne instanceof IAsEntity))
        return;//from   ww w  .  j  av  a2  s  .c o m
    IAsEntity selectedEntity = (IAsEntity) firstOne;
    final AsCluster cluster = getCluster(selectedEntity);
    IProject project = cluster.getProject();
    if (this.window == null) {
        IWorkbench wb = PlatformUI.getWorkbench();
        this.window = wb.getActiveWorkbenchWindow();
    }
    PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn(window.getShell(), project,
            ClusterPropertyPage.ID, new String[] { ClusterPropertyPage.ID }, Collections.EMPTY_MAP);
    dialog.open();
}

From source file:com.aerospike.core.navigator.RefreshCluster.java

License:Apache License

@Override
public void run(IAction action) {
    // Refresh cluster
    StructuredSelection ss = (StructuredSelection) selection;

    Object firstOne = ss.getFirstElement();
    if (!(firstOne instanceof IAsEntity))
        return;/* w w  w.j a v a 2 s.c  om*/
    IAsEntity selectedEntity = (IAsEntity) firstOne;
    final AsCluster cluster = getCluster(selectedEntity);

    ClusterRefreshJob job = new ClusterRefreshJob(cluster);
    job.schedule();
}

From source file:com.agynamix.simidude.clipboard.ClipboardTable.java

License:Open Source License

private void hookListeners(final TableViewer tableViewer) {
    //    tableViewer.addDoubleClickListener(new IDoubleClickListener(){
    //      public void doubleClick(DoubleClickEvent event)
    //      {/*from  w w w  .  ja v a  2 s.c  o  m*/
    //        TableItem[] tableItems = tableViewer.getTable().getSelection();
    //        if ((tableItems != null) && (tableItems.length > 0))
    //        {
    //          IClipboardItem item = (IClipboardItem) tableItems[0].getData();
    //          sourceDataManager.activateItem(item); 
    //        }
    //      }
    //    });

    tableViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            if (event.getSelection() instanceof StructuredSelection) {
                StructuredSelection sel = (StructuredSelection) event.getSelection();
                IClipboardItem item = (IClipboardItem) sel.getFirstElement();
                if (SimidudeUtils.isModifierKeyPressed()) {
                    sourceDataManager.activateItem(item);
                } else {
                    openSelectedEntry(item);
                }
            }
        }
    });

    tableViewer.getTable().addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if ((e.keyCode == SWT.DEL) || (e.keyCode == KEY_BACKSPACE)) {
                TableItem[] selection = tableViewer.getTable().getSelection();
                if ((selection != null) && (selection.length > 0)) {
                    int currentSelectionIndex = sourceDataManager.getSelectionIndex();
                    IClipboardItem item = (IClipboardItem) selection[0].getData();
                    boolean isNetworkRemove = SimidudeUtils.isModifierKeyPressed();
                    sourceDataManager.removeItem(item);
                    if ((isNetworkRemove) && (item != null)) {
                        ((SimidudeApplicationContext) ApplicationBase.getContext()).getModelProvider()
                                .networkRemoveItem(item.getSourceData().getStub());
                    }
                    if (e.keyCode == KEY_BACKSPACE) {
                        sourceDataManager.selectPreviousEntry(currentSelectionIndex);
                    } else {
                        sourceDataManager.saveSelectEntry(currentSelectionIndex);
                    }
                }
            }
        }
    });
}

From source file:com.alibaba.antx.config.gui.dialog.SettingsDialog.java

License:Open Source License

private void remove() {
    StructuredSelection selection = (StructuredSelection) filesViewer.getSelection();

    if (!selection.isEmpty()) {
        File nextFile = removeAndGetNext(files, (File) selection.getFirstElement());

        filesViewer.refresh();/*  w  w  w . j  av  a2 s  . com*/
        updateCommandLine();

        if (nextFile != null) {
            filesViewer.setSelection(new StructuredSelection(nextFile));
        }
    }
}

From source file:com.alibaba.antx.config.gui.dialog.SettingsDialog.java

License:Open Source License

private File getCurrentDir() {
    StructuredSelection selection = (StructuredSelection) filesViewer.getSelection();
    File dir = null;/*from w w  w  .j av  a 2s.  c om*/

    if (!selection.isEmpty()) {
        File file = (File) selection.getFirstElement();
        File parent = file.getParentFile();

        if (parent != null) {
            dir = parent.getAbsoluteFile(); // ?
        } else if (file.isDirectory()) {
            dir = file.getAbsoluteFile(); // ?
        }
    }

    if (dir == null) {
        dir = new File("").getAbsoluteFile(); // ?
    }

    return dir;
}

From source file:com.amalto.workbench.dialogs.XpathSelectDialog.java

License:Open Source License

protected void provideViwerContent(XSDSchema xsdSchema, String filter) {
    drillDownAdapter = new DrillDownAdapter(domViewer);
    domViewer.setLabelProvider(new XSDTreeLabelProvider(selectionFilter));
    XPathTreeContentProvider provider = new XPathTreeContentProvider(this.site, xsdSchema, parent, filter);
    // filter the entity with the filter text but not the concept name.
    // provider.setConceptName(this.conceptName);
    domViewer.setContentProvider(provider);

    domViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent e) {
            StructuredSelection sel = (StructuredSelection) e.getSelection();
            xpath = getXpath(sel);/* w  w w.j  ava 2  s .c  o  m*/
            xpathText.setText(xpath);
            boolean enable = false;
            if (selectionFilter == null) {
                enable = xpath.length() > 0;
            } else {
                enable = xpath.length() > 0
                        && (selectionFilter.check(sel.getFirstElement()) == FilterResult.ENABLE);
            }
            getButton(IDialogConstants.OK_ID).setEnabled(enable);
        }
    });
    domViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
    domViewer.setSorter(new ViewerSorter() {

        @Override
        public int category(Object element) {
            // we want facets before Base TypeDefinitions in
            // SimpleTypeDefinition
            if (element instanceof XSDFacet) {
                return 100;
            }
            // unique keys after element declarations and before other keys
            if (element instanceof XSDIdentityConstraintDefinition) {
                XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) element;
                if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                    return 300;
                } else if (icd.getIdentityConstraintCategory()
                        .equals(XSDIdentityConstraintCategory.KEY_LITERAL)) {
                    return 301;
                } else {
                    return 302;
                }
            }
            return 200;
        }

        @Override
        public int compare(Viewer theViewer, Object e1, Object e2) {
            int cat1 = category(e1);
            int cat2 = category(e2);
            return cat1 - cat2;
        }
    });
    domViewer.setInput(site);
}

From source file:com.amazonaws.eclipse.datatools.enablement.simpledb.editor.SDBTextEditor.java

License:Apache License

private Object getCellValue(final TableDataEditor editor) {
    int col = editor.getCursor().getColumn();
    StructuredSelection selection = (StructuredSelection) editor.getSelectionProvider().getSelection();
    TableDataCell firstElement = (TableDataCell) selection.getFirstElement();
    Object row = firstElement.getRow();
    if (row instanceof RowDataImpl) {
        RowDataImpl rowData = (RowDataImpl) row;
        Object value = rowData.getValue(col);
        return value;
    } else {/*from w w  w . ja va 2  s  .  c  o  m*/
        //This usually means that the row was just created and no RowDataImpl have been created yet.
        return ""; //$NON-NLS-1$
    }
}

From source file:com.amazonaws.eclipse.datatools.enablement.simpledb.editor.wizard.SDBTableDataWizardPage.java

License:Apache License

@SuppressWarnings("unchecked")
private void createContent() {
    this.col = this.editor.getCursor().getColumn();
    StructuredSelection selection = (StructuredSelection) this.editor.getSelectionProvider().getSelection();
    TableDataCell firstElement = (TableDataCell) selection.getFirstElement();
    Object value = null;//from   w  ww  . j a  v a 2  s.c o  m

    if (firstElement.getRow() instanceof RowDataImpl) {
        this.rowData = (RowDataImpl) firstElement.getRow();
        value = this.rowData.getValue(this.col);
    } else {
        //There is no rowData yet, we need to create it ourselves
        //      ITableData tableData = this.editor.getTableData();
        this.rowData = (RowDataImpl) this.editor.getOrCreateRow();
        value = firstElement.getRow();
    }

    if (value instanceof String) {
        createItem((String) value);
    } else if (value instanceof String[]) {
        String[] strings = (String[]) value;
        for (String s : strings) {
            createItem(s);
        }
    } else if (value instanceof ArrayList) {
        List<String> strings = (List<String>) value;
        for (String s : strings) {
            createItem(s);
        }
    }

    if (this.table.getItems().length > 0) {
        this.table.setSelection(0);
        this.remove.setEnabled(true);
        this.edit.setEnabled(true);
    } else {
        this.remove.setEnabled(false);
        this.edit.setEnabled(false);
    }
}

From source file:com.amazonaws.eclipse.datatools.enablement.simpledb.editor.wizard.SDBTableIdDataWizardPage.java

License:Apache License

private void createContent() {
    Object value;/*from   w w  w .  j a v  a  2  s.c  o  m*/

    this.col = this.editor.getCursor().getColumn();
    StructuredSelection selection = (StructuredSelection) this.editor.getSelectionProvider().getSelection();
    TableDataCell firstElement = (TableDataCell) selection.getFirstElement();
    Object row = firstElement.getRow();
    if (row instanceof RowDataImpl) {
        this.rowData = (RowDataImpl) row;
        value = this.rowData.getValue(this.col);
    } else {
        //This usually means that the row was just created and no RowDataImpl have been created yet.
        this.rowData = (RowDataImpl) this.editor.getOrCreateRow();
        value = ""; //$NON-NLS-1$
    }
    if (value == null) {
        this.t.setText(""); //$NON-NLS-1$
        setPageComplete(true);
    } else if (value instanceof String) {
        this.t.setText((String) value);
        setPageComplete(true);
    } else if (value instanceof SimpleDBItemName) {
        this.t.setText(((SimpleDBItemName) value).getItemName());
        setPageComplete(true);
    } else {
        setErrorMessage(
                (MessageFormat.format(Messages.incorrectDataType, value.getClass().getCanonicalName())));
        this.t.setEnabled(false);
        setPageComplete(false);
    }

}