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

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

Introduction

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

Prototype

public StructuredSelection(List elements) 

Source Link

Document

Creates a structured selection from the given List.

Usage

From source file:ch.elexis.core.ui.laboratory.preferences.LabGroupPrefs.java

License:Open Source License

private void selectFirstGroup() {
    Object element = groupsViewer.getElementAt(0);
    if (element != null) {
        groupsViewer.setSelection(new StructuredSelection(element));
    }/*  ww  w . ja v  a 2  s .  c  o m*/
}

From source file:ch.elexis.core.ui.stock.dialogs.ImportArticleDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    reportBuilder = null;//from  www .j  a v  a2s  .  c  o m
    Composite ret = new Composite(parent, SWT.NONE);
    ret.setLayout(new GridLayout(3, false));
    ret.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    new Label(ret, SWT.NONE).setText("Import in Lager");

    comboStockType = new ComboViewer(ret, SWT.BORDER | SWT.READ_ONLY);
    comboStockType.setContentProvider(ArrayContentProvider.getInstance());
    comboStockType.setInput(new Query<Stock>(Stock.class).execute());
    comboStockType.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof StructuredSelection) {
                if (!selection.isEmpty()) {
                    Object o = ((StructuredSelection) selection).getFirstElement();
                }
            }
        }
    });
    comboStockType.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof Stock) {
                Stock stock = (Stock) element;
                return stock.getLabel();
            }
            return super.getText(element);
        }
    });
    comboStockType.getCombo().setLayoutData(SWTHelper.getFillGridData(2, false, 1, false));

    comboStockType.setSelection(new StructuredSelection(Stock.load(Stock.DEFAULT_STOCK_ID)));

    new Label(ret, SWT.NONE).setText("Quelldatei auswhlen");

    tFilePath = new Text(ret, SWT.BORDER);
    tFilePath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    tFilePath.setText("");
    Button btnBrowse = new Button(ret, SWT.NONE);
    btnBrowse.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
            fd.setFilterExtensions(new String[] { "*.xls" });
            String selected = fd.open();
            tFilePath.setText(selected);
        }
    });
    btnBrowse.setText("auswhlen..");

    reportLink = new Link(ret, SWT.NONE);
    reportLink.setText("");
    reportLink.setVisible(false);
    reportLink.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, true, 3, 1));
    // Event handling when users click on links.
    reportLink.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(getShell(), SWT.SAVE);
            fd.setFilterExtensions(new String[] { "*.csv" });
            fd.setFileName("report.csv");
            String path = fd.open();
            if (path != null) {
                try {
                    FileUtils.writeStringToFile(new File(path), reportBuilder.toString(), "UTF-8");
                } catch (IOException e1) {
                    MessageDialog.openError(getShell(), "Report Error",
                            "Report konnte nicht gespeichert werden.\n\n" + e1.getMessage());
                    LoggerFactory.getLogger(ImportArticleDialog.class).error("report save error", e1);
                }
            }
        }

    });

    return ret;
}

From source file:ch.elexis.core.ui.text.XrefExtension.java

License:Open Source License

private void startLocalEdit(Brief brief) {
    if (brief != null) {
        ICommandService commandService = (ICommandService) PlatformUI.getWorkbench()
                .getService(ICommandService.class);
        Command command = commandService.getCommand("ch.elexis.core.ui.command.startEditLocalDocument"); //$NON-NLS-1$

        PlatformUI.getWorkbench().getService(IEclipseContext.class).set(command.getId().concat(".selection"),
                new StructuredSelection(brief));
        try {/*from w w  w.  ja  v a 2  s .c o  m*/
            command.executeWithChecks(new ExecutionEvent(command, Collections.EMPTY_MAP, this, null));
        } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
            MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.BriefAuswahl_errorttile,
                    Messages.BriefAuswahl_erroreditmessage);
        }
    }
}

From source file:ch.elexis.core.ui.util.viewers.CommonViewer.java

License:Open Source License

/**
 * Das selektierte Element des Viewers einstellen
 * //from  www.  j  ava2  s . c  om
 * @param o
 *            Das Element
 */
public void setSelection(Object o, boolean fireEvents) {
    if (fireEvents == false) {
        viewer.removeSelectionChangedListener(this);
        viewer.setSelection(new StructuredSelection(o), true);
        viewer.addSelectionChangedListener(this);
    } else {
        viewer.setSelection(new StructuredSelection(o), true);
    }

}

From source file:ch.elexis.core.ui.views.BBSView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    SashForm sash = new SashForm(parent, SWT.NONE);
    qbe = new Query<BBSEntry>(BBSEntry.class);
    loader = new LazyTreeLoader<BBSEntry>("BBS", qbe, "reference", new String[] { //$NON-NLS-1$ //$NON-NLS-2$
            "datum", "time", "Thema" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    });// w  w w  . j  a va  2 s .c  o  m
    headlines = new CommonViewer();
    vc = new ViewerConfigurer(new TreeContentProvider(headlines, loader),
            new ViewerConfigurer.TreeLabelProvider(),
            new DefaultControlFieldProvider(headlines, new String[] { "Thema" //$NON-NLS-1$
            }), new NewThread(), new SimpleWidgetProvider(SimpleWidgetProvider.TYPE_TREE, SWT.NONE, null));
    headlines.create(vc, sash, SWT.NONE, getViewSite());

    tk = UiDesk.getToolkit();
    form = tk.createScrolledForm(sash);
    form.getBody().setLayout(new GridLayout(1, false));
    form.setText(Messages.BBSView_PleaseEnterSubject); //$NON-NLS-1$
    origin = tk.createLabel(form.getBody(), ""); //$NON-NLS-1$
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    origin.setLayoutData(gd);
    msg = tk.createFormText(form.getBody(), false);
    gd = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL | GridData.FILL_VERTICAL);
    msg.setLayoutData(gd);
    msg.setColor(Messages.BBSView_rot, UiDesk.getColor(UiDesk.COL_RED)); //$NON-NLS-1$
    msg.setColor(Messages.BBSView_gruen, UiDesk.getColor(UiDesk.COL_GREEN)); //$NON-NLS-1$
    msg.setColor(Messages.BBSView_blau, UiDesk.getColor(UiDesk.COL_BLUE)); //$NON-NLS-1$
    input = tk.createText(form.getBody(), "", SWT.WRAP | SWT.MULTI | SWT.BORDER); //$NON-NLS-1$
    gd = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    input.setLayoutData(gd);
    Button send = tk.createButton(form.getBody(), Messages.BBSView_DoSend, SWT.PUSH); //$NON-NLS-1$
    send.addSelectionListener(new SelectionAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {

            Object[] sel = headlines.getSelection();
            if (sel == null || sel.length == 0) {
                return;
            }
            Tree item = (Tree) sel[0];
            BBSEntry en = (BBSEntry) (item).contents;
            BBSEntry ne = new BBSEntry(en.getTopic(), CoreHub.actUser, en, input.getText());
            Tree child = item.add(ne);
            ((TreeViewer) headlines.getViewerWidget()).add(sel[0], child);
            ((TreeViewer) headlines.getViewerWidget()).setSelection(new StructuredSelection(child), true);
        }

    });
    headlines.getViewerWidget().addSelectionChangedListener(this);
    ((TreeContentProvider) headlines.getConfigurer().getContentProvider()).startListening();
    setDisplay();
}

From source file:ch.elexis.core.ui.views.BriefAuswahl.java

License:Open Source License

private void makeActions() {
    briefNeuAction = new Action(Messages.BriefAuswahlNewButtonText) { //$NON-NLS-1$
        @Override// ww w . j  a  v  a2 s.c o m
        public void run() {
            Patient pat = ElexisEventDispatcher.getSelectedPatient();
            if (pat == null) {
                MessageDialog.openInformation(UiDesk.getTopShell(), Messages.BriefAuswahlNoPatientSelected,
                        Messages.BriefAuswahlNoPatientSelected);
                return;
            }

            Fall selectedFall = (Fall) ElexisEventDispatcher.getSelected(Fall.class);
            if (selectedFall == null) {
                SelectFallDialog sfd = new SelectFallDialog(UiDesk.getTopShell());
                sfd.open();
                if (sfd.result != null) {
                    ElexisEventDispatcher.fireSelectionEvent(sfd.result);
                } else {
                    MessageDialog.openInformation(UiDesk.getTopShell(), Messages.TextView_NoCaseSelected, //$NON-NLS-1$
                            Messages.TextView_SaveNotPossibleNoCaseAndKonsSelected); //$NON-NLS-1$
                    return;
                }
            }

            Konsultation selectedKonsultation = (Konsultation) ElexisEventDispatcher
                    .getSelected(Konsultation.class);
            if (selectedKonsultation == null) {
                Konsultation k = pat.getLetzteKons(false);
                if (k == null) {
                    k = ((Fall) ElexisEventDispatcher.getSelected(Fall.class)).neueKonsultation();
                    k.setMandant(CoreHub.actMandant);
                }
                ElexisEventDispatcher.fireSelectionEvent(k);
            }

            TextView tv = null;
            try {
                DocumentSelectDialog bs = new DocumentSelectDialog(getViewSite().getShell(), CoreHub.actMandant,
                        DocumentSelectDialog.TYPE_CREATE_DOC_WITH_TEMPLATE);
                if (bs.open() == Dialog.OK) {
                    tv = (TextView) getSite().getPage().showView(TextView.ID);
                    // trick: just supply a dummy address for creating the doc
                    Kontakt address = null;
                    if (DocumentSelectDialog.getDontAskForAddresseeForThisTemplate(bs.getSelectedDocument()))
                        address = Kontakt.load("-1"); //$NON-NLS-1$
                    tv.createDocument(bs.getSelectedDocument(), bs.getBetreff(), address);
                    tv.setName();
                    CTabItem sel = ctab.getSelection();
                    if (sel != null) {
                        CommonViewer cv = (CommonViewer) sel.getData();
                        cv.notify(CommonViewer.Message.update_keeplabels);
                    }

                }
            } catch (Exception ex) {
                ExHandler.handle(ex);
            }
        }
    };

    briefLadenAction = new Action(Messages.BriefAuswahlOpenButtonText) { //$NON-NLS-1$
        @Override
        public void run() {
            try {
                CTabItem sel = ctab.getSelection();
                if (sel != null) {
                    CommonViewer cv = (CommonViewer) sel.getData();
                    Object[] o = cv.getSelection();
                    if ((o != null) && (o.length > 0)) {
                        Brief brief = (Brief) o[0];
                        if (CoreHub.localCfg.get(Preferences.P_TEXT_EDIT_LOCAL, false)) {
                            startLocalEditAction.run();
                        } else {
                            TextView tv = (TextView) getViewSite().getPage().showView(TextView.ID);
                            if (brief.getMimeType().equalsIgnoreCase("pdf")) { //$NON-NLS-1$
                                try {
                                    File temp = File.createTempFile("letter_", ".pdf"); //$NON-NLS-1$ //$NON-NLS-2$
                                    temp.deleteOnExit();
                                    FileOutputStream fos = new FileOutputStream(temp);

                                    fos.write(brief.loadBinary());
                                    fos.close();
                                    Program.launch(temp.getAbsolutePath());
                                } catch (IOException e) {
                                    SWTHelper.alert(Messages.BriefAuswahlErrorHeading, //$NON-NLS-1$
                                            Messages.BriefAuswahlCouldNotLoadText); //$NON-NLS-1$
                                }
                            } else if (tv.openDocument(brief) == false) {
                                SWTHelper.alert(Messages.BriefAuswahlErrorHeading, //$NON-NLS-1$
                                        Messages.BriefAuswahlCouldNotLoadText); //$NON-NLS-1$
                            }
                        }
                    } else {
                        TextView tv = (TextView) getViewSite().getPage().showView(TextView.ID);
                        tv.createDocument(null, null);
                    }
                    cv.notify(CommonViewer.Message.update);
                }
            } catch (PartInitException e) {
                ExHandler.handle(e);
            }

        }
    };
    deleteAction = new LockRequestingAction<Brief>(Messages.BriefAuswahlDeleteButtonText) { //$NON-NLS-1$
        @Override
        public void doRun(Brief brief) {
            if (brief != null && SWTHelper.askYesNo(Messages.BriefAuswahlDeleteConfirmHeading, //$NON-NLS-1$
                    Messages.BriefAuswahlDeleteConfirmText)) {
                brief.delete();
                CTabItem sel = ctab.getSelection();
                CommonViewer cv = (CommonViewer) sel.getData();
                cv.notify(CommonViewer.Message.update);
            }
        }

        @Override
        public Brief getTargetedObject() {
            CTabItem sel = ctab.getSelection();
            if ((sel != null)) { //$NON-NLS-1$
                CommonViewer cv = (CommonViewer) sel.getData();
                Object[] o = cv.getSelection();
                if ((o != null) && (o.length > 0)) {
                    if (o[0] instanceof Brief) {
                        return (Brief) o[0];
                    }
                }
            }
            return null;
        }
    };
    editNameAction = new LockRequestingAction<Brief>(Messages.BriefAuswahlRenameButtonText) { //$NON-NLS-1$
        @Override
        public void doRun(Brief brief) {
            if (brief != null) {
                InputDialog id = new InputDialog(getViewSite().getShell(),
                        Messages.BriefAuswahlNewSubjectHeading, //$NON-NLS-1$
                        Messages.BriefAuswahlNewSubjectText, //$NON-NLS-1$
                        brief.getBetreff(), null);
                if (id.open() == Dialog.OK) {
                    brief.setBetreff(id.getValue());
                }
                CTabItem sel = ctab.getSelection();
                CommonViewer cv = (CommonViewer) sel.getData();
                cv.notify(CommonViewer.Message.update);
            }
        }

        @Override
        public Brief getTargetedObject() {
            CTabItem sel = ctab.getSelection();
            if (sel != null) { //$NON-NLS-1$
                CommonViewer cv = (CommonViewer) sel.getData();
                Object[] o = cv.getSelection();
                if ((o != null) && (o.length > 0)) {
                    if (o[0] instanceof Brief) {
                        return (Brief) o[0];
                    }
                }
            }
            return null;
        }
    };
    startLocalEditAction = new Action() {
        @Override
        public ImageDescriptor getImageDescriptor() {
            return Images.IMG_EDIT.getImageDescriptor();
        }

        @Override
        public String getText() {
            return Messages.BriefAuswahl_actionlocaledittext;
        }

        @Override
        public void run() {
            Brief brief = getSelectedBrief();
            if (brief != null) {
                ICommandService commandService = (ICommandService) PlatformUI.getWorkbench()
                        .getService(ICommandService.class);
                Command command = commandService.getCommand("ch.elexis.core.ui.command.startEditLocalDocument"); //$NON-NLS-1$
                PlatformUI.getWorkbench().getService(IEclipseContext.class)
                        .set(command.getId().concat(".selection"), new StructuredSelection(brief));
                try {
                    command.executeWithChecks(new ExecutionEvent(command, Collections.EMPTY_MAP, this, null));
                } catch (ExecutionException | NotDefinedException | NotEnabledException
                        | NotHandledException e) {
                    MessageDialog.openError(getSite().getShell(), Messages.BriefAuswahl_errorttile,
                            Messages.BriefAuswahl_erroreditmessage);
                }
                refreshSelectedViewer();
            }
        }
    };
    endLocalEditAction = new Action() {
        @Override
        public ImageDescriptor getImageDescriptor() {
            return Images.IMG_EDIT_DONE.getImageDescriptor();
        }

        @Override
        public String getText() {
            return Messages.BriefAuswahl_actionlocaleditstopmessage;
        }

        @Override
        public void run() {
            Brief brief = getSelectedBrief();
            if (brief != null) {
                ICommandService commandService = (ICommandService) PlatformUI.getWorkbench()
                        .getService(ICommandService.class);
                Command command = commandService.getCommand("ch.elexis.core.ui.command.endLocalDocument"); //$NON-NLS-1$

                PlatformUI.getWorkbench().getService(IEclipseContext.class)
                        .set(command.getId().concat(".selection"), new StructuredSelection(brief));
                try {
                    command.executeWithChecks(new ExecutionEvent(command, Collections.EMPTY_MAP, this, null));
                } catch (ExecutionException | NotDefinedException | NotEnabledException
                        | NotHandledException e) {
                    MessageDialog.openError(getSite().getShell(), Messages.BriefAuswahl_errortitle,
                            Messages.BriefAuswahl_errorlocaleditendmessage);
                }
            }
            refreshSelectedViewer();
        }
    };
    cancelLocalEditAction = new Action() {
        @Override
        public ImageDescriptor getImageDescriptor() {
            return Images.IMG_EDIT_ABORT.getImageDescriptor();
        }

        @Override
        public String getText() {
            return Messages.BriefAuswahl_actionlocaleditabortmessage;
        }

        @Override
        public void run() {
            Brief brief = getSelectedBrief();
            if (brief != null) {
                ICommandService commandService = (ICommandService) PlatformUI.getWorkbench()
                        .getService(ICommandService.class);
                Command command = commandService.getCommand("ch.elexis.core.ui.command.abortLocalDocument"); //$NON-NLS-1$

                PlatformUI.getWorkbench().getService(IEclipseContext.class)
                        .set(command.getId().concat(".selection"), new StructuredSelection(brief));
                try {
                    command.executeWithChecks(new ExecutionEvent(command, Collections.EMPTY_MAP, this, null));
                } catch (ExecutionException | NotDefinedException | NotEnabledException
                        | NotHandledException e) {
                    MessageDialog.openError(getSite().getShell(), Messages.BriefAuswahl_errortitle,
                            Messages.BriefAuswahl_errorlocaleditabortmessage);
                }
            }
            refreshSelectedViewer();
        }
    };
    /*
     * importAction=new Action("Importieren..."){ public void run(){
     * 
     * } };
     */
    briefLadenAction.setImageDescriptor(Images.IMG_DOCUMENT_TEXT.getImageDescriptor());
    briefLadenAction.setToolTipText(Messages.BriefAuswahlOpenLetterForEdit); //$NON-NLS-1$
    briefNeuAction.setImageDescriptor(Images.IMG_DOCUMENT_ADD.getImageDescriptor());
    briefNeuAction.setToolTipText(Messages.BriefAuswahlCreateNewDocument); //$NON-NLS-1$
    editNameAction.setImageDescriptor(Images.IMG_DOCUMENT_WRITE.getImageDescriptor());
    editNameAction.setToolTipText(Messages.BriefAuswahlRenameDocument); //$NON-NLS-1$
    deleteAction.setImageDescriptor(Images.IMG_DOCUMENT_REMOVE.getImageDescriptor());
    deleteAction.setToolTipText(Messages.BriefAuswahlDeleteDocument); //$NON-NLS-1$
}

From source file:ch.elexis.core.ui.views.controls.DaysOrDateSelectionComposite.java

License:Open Source License

@Override
public ISelection getSelection() {
    if (dateValue != null) {
        return new StructuredSelection(dateValue);
    }/*from   w  w w .j a  v a  2s .  co  m*/
    return StructuredSelection.EMPTY;
}

From source file:ch.elexis.core.ui.views.controls.TimeSpanSelectionComposite.java

License:Open Source License

@Override
public ISelection getSelection() {
    if (timeSpan != null) {
        return new StructuredSelection(timeSpan);
    }//  w w  w  . jav  a  2 s .co m
    return StructuredSelection.EMPTY;
}

From source file:ch.elexis.core.ui.views.FaelleView.java

License:Open Source License

@Override
public void setFocus() {
    Fall currentFall = (Fall) ElexisEventDispatcher.getSelected(Fall.class);
    if (currentFall != null) {
        tv.setSelection(new StructuredSelection(currentFall));
    }/* w ww  .ja  v  a2  s  . c  o m*/
}

From source file:ch.elexis.core.ui.views.KonsDetailView.java

License:Open Source License

private void updateFallCombo() {
    Patient pat = ElexisEventDispatcher.getSelectedPatient();
    if (pat != null && comboViewerFall != null) {
        Fall[] faelle = pat.getFaelle();
        Arrays.sort(faelle, new FallComparator());
        comboViewerFall.setInput(faelle);
        if (actKons != null) {
            comboFallSelectionListener.ignoreSelectionEventOnce();
            comboViewerFall.setSelection(new StructuredSelection(actKons.getFall()));
        }/* www. j a  v  a 2s .  com*/
    }
}