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:ch.netcetera.eclipse.copyaspath.DefaultHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IResource resource = null;//from w  ww. ja  v a2s. c om
    ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    Object firstElement = null;
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) currentSelection;
        firstElement = ssel.getFirstElement();
    }
    if (firstElement instanceof IAdaptable) {
        IAdaptable adaptableFirstElement = (IAdaptable) firstElement;
        resource = (IResource) adaptableFirstElement.getAdapter(IResource.class);
    }

    if (resource == null) {
        IEditorInput activeEditorInput = HandlerUtil.getActiveEditorInput(event);
        if (activeEditorInput != null) {
            resource = (IResource) activeEditorInput.getAdapter(IResource.class);
        }
    }

    String path = null;

    if (resource != null) {
        path = resource.getLocation().toOSString();
    } else if (firstElement instanceof IJavaElement) {
        path = ((IJavaElement) firstElement).getPath().toOSString();
    }
    Clipboard clipboard = new Clipboard(HandlerUtil.getActiveShell(event).getDisplay());
    try {
        clipboard.setContents(new Object[] { path }, new Transfer[] { TextTransfer.getInstance() });
    } finally {
        clipboard.dispose();
    }
    return null;
}

From source file:ch.novcom.elexis.mednet.plugin.ui.commands.OpenFormView.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    String logPrefix = "execute() - ";//$NON-NLS-1$
    Patient pat = null;/*  w  ww  . j av  a 2 s  .  c om*/

    //First of all find the selected Patient
    ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
    IStructuredSelection strucSelection = (IStructuredSelection) selection;
    if (selection != null & selection instanceof IStructuredSelection) {
        pat = (Patient) strucSelection.getFirstElement();
    }

    String configuredGDTId = CoreHub.localCfg.get(GDTPreferenceConstants.CFG_GDT_ID, "");
    if (pat == null) {
        pat = ElexisEventDispatcher.getSelectedPatient();
    }
    if (pat == null) {
        return null;
    }

    String socialSecurityNumber = pat.getXid(XidConstants.DOMAIN_AHV); // AHV-Nummer
    String birthdate = "";
    try {
        birthdate = OpenFormView.toGDT.format(OpenFormView.fromDatabase.parse(pat.getGeburtsdatum()));
    } catch (ParseException pe) {
        LOGGER.error(logPrefix + "Unable to parse birthdate " + pat.getGeburtsdatum());//$NON-NLS-1$
    }

    //If we have the selected Patient, we can create a simple GDT File
    GDTSatzNachricht6301 gdt6301 = new GDTSatzNachricht6301(pat.get(Patient.FLD_PATID), pat.getName(),
            pat.getVorname(), birthdate, null, pat.get(Patient.TITLE), socialSecurityNumber,
            pat.get(Patient.FLD_ZIP) + " " + pat.get(Patient.FLD_PLACE), pat.get(Patient.FLD_STREET), null,
            GDTSatzNachrichtHelper.bestimmeGeschlechtsWert(pat.get(Patient.FLD_SEX)), null, null, null, null,
            configuredGDTId, GDTConstants.ZEICHENSATZ_IBM_CP_437 + "", GDTConstants.GDT_VERSION);

    File file = null;
    //Finally we can write this GDT to a temporary file that will be deleted after elexis has been stopped
    try {
        file = File.createTempFile("mednet-" + pat.get(Patient.FLD_PATID) + "-", ".gdt");//$NON-NLS-1$
        file.deleteOnExit();
        Files.write(file.toPath(), String.join("\n", gdt6301.getMessage()).getBytes(OpenFormView.GDT_ENCODING));
    } catch (IOException ioe) {
        //If there are some ioeException logs it
        LOGGER.error(logPrefix + "IOException creating gdtFile.", ioe);//$NON-NLS-1$
        MedNet.openFormview(null);
        return null;
    }

    //and we call mednet
    MedNet.openFormview(file.toPath());
    return null;
}

From source file:ch.novcom.elexis.mednet.plugin.ui.preferences.ContactLinkPreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {

    noDefaultAndApplyButton();//from w w w  .j a  v  a  2 s .  c  o m

    Composite tableComposite = new Composite(parent, SWT.NONE);
    GridData gd = new GridData();
    tableComposite.setLayoutData(gd);
    TableColumnLayout tableColumnLayout = new TableColumnLayout();
    tableComposite.setLayout(tableColumnLayout);
    tableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION);
    table = tableViewer.getTable();

    for (int i = 0; i < tableheaders.length; i++) {
        TableColumn tc = new TableColumn(table, SWT.LEFT);
        tc.setText(tableheaders[i]);
        tableColumnLayout.setColumnData(tc, new ColumnWeightData(tableColwidth[i], true));
        tc.setData(i);
        tc.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                tableViewer.refresh(true);
            }
        });
    }

    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    table.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tableViewer.setContentProvider(new IStructuredContentProvider() {

        public Object[] getElements(Object inputElement) {
            return ContactLinkRecord.getAllContactLinkRecords().toArray();
        }

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

    });
    tableViewer.setLabelProvider(new ReceivingListLabelProvider());
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection sel = (IStructuredSelection) tableViewer.getSelection();
            Object o = sel.getFirstElement();
            if (o instanceof ContactLinkRecord) {
                ContactLinkRecord li = (ContactLinkRecord) o;
                //It looks like the clean way should be to call following funktion
                //But since it is not working we open directly the Dialog
                //ContactLinkRecordEdit.executeWithParams(li);
                ContactLinkRecordEditDialog dialog = new ContactLinkRecordEditDialog(getShell(), li);
                if (dialog.open() == Dialog.OK) {
                    tableViewer.refresh();
                }
            }
        }

    });

    tableViewer.setInput(this);
    return tableComposite;
}

From source file:ch.novcom.elexis.mednet.plugin.ui.preferences.ContactLinkPreferencePage.java

License:Open Source License

@Override
protected void contributeButtons(Composite parent) {

    ((GridLayout) parent.getLayout()).numColumns++;
    Button bNewItem = new Button(parent, SWT.PUSH);
    bNewItem.setText(MedNetMessages.ContactLinkPreferences_new);
    bNewItem.addSelectionListener(new SelectionAdapter() {
        @Override//from w  w  w .j  a  v  a  2s. c om
        public void widgetSelected(SelectionEvent e) {
            try {
                // execute the command
                IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench()
                        .getActiveWorkbenchWindow().getService(IHandlerService.class);

                handlerService.executeCommand(ContactLinkRecordCreate.COMMANDID, null);
            } catch (Exception ex) {
                throw new RuntimeException(ContactLinkRecordCreate.COMMANDID, ex);
            }
            tableViewer.refresh();
        }
    });
    ((GridLayout) parent.getLayout()).numColumns++;
    Button bDelItem = new Button(parent, SWT.PUSH);
    bDelItem.setText(MedNetMessages.ContactLinkPreferences_delete);
    bDelItem.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) tableViewer.getSelection();
            Object o = sel.getFirstElement();
            if (o instanceof ContactLinkRecord) {
                ContactLinkRecord li = (ContactLinkRecord) o;
                if (MessageDialog.openQuestion(getShell(), MedNetMessages.ContactLinkPreferences_delete,
                        MessageFormat.format(MedNetMessages.ContactLinkPreferences_reallyDelete,
                                li.getLabel()))) {

                    if (deleteRecord(li)) {
                        li.removeFromDatabase();
                        tableViewer.remove(li);
                    } else {
                        MessageDialog.openWarning(getShell(), MedNetMessages.ContactLinkPreferences_delete,
                                MedNetMessages.ContactLinkPreferences_deleteFailed);
                    }
                }
            }
        }
    });
    ((GridLayout) parent.getLayout()).numColumns++;
    Button bDelAllItems = new Button(parent, SWT.PUSH);
    bDelAllItems.setText(MedNetMessages.ContactLinkPreferences_deleteAll);
    bDelAllItems.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (SWTHelper.askYesNo(MedNetMessages.ContactLinkPreferences_deleteAllTitle,
                    MedNetMessages.ContactLinkPreferences_deleteAllExplain)) {
                Query<ContactLinkRecord> qbli = new Query<ContactLinkRecord>(ContactLinkRecord.class);
                List<ContactLinkRecord> items = qbli.execute();
                boolean success = true;
                for (ContactLinkRecord li : items) {
                    if (deleteRecord(li)) {
                        li.removeFromDatabase();
                    } else {
                        success = false;
                    }
                }
                if (!success) {
                    MessageDialog.openWarning(getShell(), MedNetMessages.ContactLinkPreferences_deleteAll,
                            MedNetMessages.ContactLinkPreferences_deleteAllFailed);
                }
                tableViewer.refresh();
            }
        }
    });
    if (CoreHub.acl.request(AccessControlDefaults.DELETE_LABITEMS) == false) {
        bDelAllItems.setEnabled(false);
    }
}

From source file:ch.novcom.elexis.mednet.plugin.ui.preferences.DocumentPreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {

    noDefaultAndApplyButton();/*from   w  ww.  ja  v  a  2 s .  com*/

    Composite tableComposite = new Composite(parent, SWT.NONE);
    GridData gd = new GridData();
    tableComposite.setLayoutData(gd);
    TableColumnLayout tableColumnLayout = new TableColumnLayout();
    tableComposite.setLayout(tableColumnLayout);
    tableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION);
    table = tableViewer.getTable();

    for (int i = 0; i < tableheaders.length; i++) {
        TableColumn tc = new TableColumn(table, SWT.LEFT);
        tc.setText(tableheaders[i]);
        tableColumnLayout.setColumnData(tc, new ColumnWeightData(tableColwidth[i], true));
        tc.setData(i);
        tc.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                tableViewer.refresh(true);
            }
        });
    }

    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    table.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tableViewer.setContentProvider(new IStructuredContentProvider() {

        public Object[] getElements(Object inputElement) {
            return DocumentSettingRecord.getAllDocumentSettingRecords().toArray();
        }

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

    });
    tableViewer.setLabelProvider(new ReceivingListLabelProvider());
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection sel = (IStructuredSelection) tableViewer.getSelection();
            Object o = sel.getFirstElement();
            if (o instanceof DocumentSettingRecord) {
                DocumentSettingRecord li = (DocumentSettingRecord) o;
                DocumentSettingRecordEdit.executeWithParams(li);
                tableViewer.refresh();
            }
        }

    });

    tableViewer.setInput(this);
    return tableComposite;
}

From source file:ch.novcom.elexis.mednet.plugin.ui.preferences.DocumentPreferencePage.java

License:Open Source License

@Override
protected void contributeButtons(Composite parent) {

    ((GridLayout) parent.getLayout()).numColumns++;
    Button bNewItem = new Button(parent, SWT.PUSH);
    bNewItem.setText(MedNetMessages.DocumentPreferences_new);
    bNewItem.addSelectionListener(new SelectionAdapter() {
        @Override//from  ww w. j  a  v  a  2  s.c  o m
        public void widgetSelected(SelectionEvent e) {
            try {
                // execute the command
                IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench()
                        .getActiveWorkbenchWindow().getService(IHandlerService.class);

                handlerService.executeCommand(DocumentSettingRecordCreate.COMMANDID, null);
            } catch (Exception ex) {
                throw new RuntimeException(DocumentSettingRecordCreate.COMMANDID, ex);
            }
            tableViewer.refresh();
        }
    });
    ((GridLayout) parent.getLayout()).numColumns++;
    Button bDelItem = new Button(parent, SWT.PUSH);
    bDelItem.setText(MedNetMessages.DocumentPreferences_delete);
    bDelItem.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) tableViewer.getSelection();
            Object o = sel.getFirstElement();
            if (o instanceof DocumentSettingRecord) {
                DocumentSettingRecord li = (DocumentSettingRecord) o;
                if (MessageDialog.openQuestion(getShell(), MedNetMessages.DocumentPreferences_delete,
                        MessageFormat.format(MedNetMessages.DocumentPreferences_reallyDelete, li.getLabel()))) {

                    if (deleteRecord(li)) {
                        li.delete();
                        tableViewer.remove(li);
                    } else {
                        MessageDialog.openWarning(getShell(), MedNetMessages.DocumentPreferences_delete,
                                MedNetMessages.DocumentPreferences_deleteFailed);
                    }
                }
            }
        }
    });
    ((GridLayout) parent.getLayout()).numColumns++;
    Button bDelAllItems = new Button(parent, SWT.PUSH);
    bDelAllItems.setText(MedNetMessages.DocumentPreferences_deleteAll);
    bDelAllItems.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (SWTHelper.askYesNo(MedNetMessages.DocumentPreferences_reallyDeleteAll,
                    MedNetMessages.DocumentPreferences_deleteAllExplain)) {
                Query<DocumentSettingRecord> qbli = new Query<DocumentSettingRecord>(
                        DocumentSettingRecord.class);
                List<DocumentSettingRecord> items = qbli.execute();
                boolean success = true;
                for (DocumentSettingRecord li : items) {
                    if (deleteRecord(li)) {
                        li.delete();
                    } else {
                        success = false;
                    }
                }
                if (!success) {
                    MessageDialog.openWarning(getShell(), MedNetMessages.DocumentPreferences_deleteAll,
                            MedNetMessages.DocumentPreferences_deleteAllFailed);
                }
                tableViewer.refresh();
            }
        }
    });
    if (CoreHub.acl.request(AccessControlDefaults.DELETE_LABITEMS) == false) {
        bDelAllItems.setEnabled(false);
    }
}

From source file:ch.parisi.e4.advancedlaunch.dialog.MultiLaunchConfigurationSelectionDialog.java

License:Open Source License

public ILaunchConfiguration getSelectedLaunchConfiguration() {
    if (currentSelection != null && !currentSelection.isEmpty()) {
        IStructuredSelection selection = (IStructuredSelection) currentSelection;
        return (ILaunchConfiguration) selection.getFirstElement();
    }/*from  ww  w.j  a v a  2s  . c o m*/
    return null;
}

From source file:ch.parisi.e4.advancedlaunch.dialog.MultiLaunchConfigurationSelectionDialog.java

License:Open Source License

protected void validate() {
    Button btnOk = getButton(IDialogConstants.OK_ID);
    isValid = true;/*w  w  w.j a  va2s  . co m*/

    if (isValid) {
        setErrorMessage(null);
        if (action == PostLaunchAction.DELAY) {
            try {
                isValid = ((Integer.parseInt(actionParam.toString()) > 0));
            } catch (Exception e) {
                isValid = false;
                setErrorMessage(isValid ? null : LaunchMessages.LaunchGroupConfigurationSelectionDialog_10);
            }
        } else if (action == PostLaunchAction.WAIT_FOR_CONSOLESTRING) {
            isValid = (!String.valueOf(actionParam).trim().isEmpty());
            setErrorMessage(isValid ? null : LaunchMessages.LaunchGroupConfigurationSelectionDialog_10_2);
        }
        if (currentSelection == null) {
            isValid = false;
        } else {
            IStructuredSelection selection = (IStructuredSelection) currentSelection;
            if (selection.getFirstElement() instanceof ILaunchConfigurationType) {
                isValid = false;
                setErrorMessage(
                        isValid ? null : LaunchMessages.LaunchGroupConfiguration_NotALaunchConfiguration);
            }
        }
    }

    if (btnOk != null) {
        btnOk.setEnabled(isValid);
    }
}

From source file:ch.powerunit.poweruniteclipse.PowerUnitResultView.java

License:Open Source License

private void createDisplay(Composite parent) {
    Composite comp = new Composite(parent, SWT.NONE);

    GridLayout topLayout = new GridLayout();
    topLayout.numColumns = 2;/* w  w w. ja  v  a 2s.co  m*/
    comp.setLayout(topLayout);

    resultViewer = new TreeViewer(comp, SWT.BORDER | SWT.SINGLE);
    resultViewer.setContentProvider(new TreeResulContentProvider());
    resultViewer.setLabelProvider(new TreeResultLabelProvider());
    resultViewer.setInput(results);
    resultViewer.expandAll();

    GridData gridData = new GridData();
    gridData.widthHint = 200;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalSpan = 1;
    resultViewer.getTree().setLayoutData(gridData);

    stackTrace = new Text(comp, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
    stackTrace.setEditable(false);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalSpan = 1;
    stackTrace.setLayoutData(gridData);

    resultViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {

            if (event.getSelection().isEmpty()) {
                stackTrace.setText("");
            } else if (event.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                Object s = selection.getFirstElement();
                if (s instanceof Testcase) {
                    Testcase tc = (Testcase) s;
                    if (!tc.getError().isEmpty()) {
                        stackTrace.setText(tc.getError().get(0).getContent());
                    } else if (!tc.getFailure().isEmpty()) {
                        stackTrace.setText(tc.getFailure().get(0).getContent());
                    } else {
                        stackTrace.setText("");
                    }
                } else {
                    stackTrace.setText("");
                }
            }

        }
    });

}

From source file:ch.uzh.ifi.seal.permo.history.git.ui.view.detail.FileDiffTable.java

License:Apache License

private void registerListener() {
    getTable().addMouseListener(new MouseAdapter() {
        @Override/*from   w  ww . j av  a 2s.  c om*/
        public void mouseDoubleClick(final MouseEvent event) {
            if (getSelection() instanceof IStructuredSelection) {
                final IStructuredSelection selection = (IStructuredSelection) getSelection();
                if (selection.getFirstElement() instanceof DiffViewModel) {
                    final DiffViewModel selectedDiff = (DiffViewModel) selection.getFirstElement();
                    final GitFileDiffEditorInput editorInput = new GitFileDiffEditorInput(
                            selectedDiff.getDiff());
                    if ((event.stateMask & SWT.CTRL) != 0) {
                        CompareUtil.openNewCompareEditor(editorInput);
                    } else {
                        CompareUtil.openExistingCompareEditor(editorInput);
                    }

                }
            }
            getSelection();
        }
    });
}