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

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

Introduction

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

Prototype

public boolean isEmpty();

Source Link

Document

Returns whether this selection is empty.

Usage

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

License:Open Source License

public void doubleClick(DoubleClickEvent event) {
    if (dlListeners != null) {
        Iterator<DoubleClickListener> it = dlListeners.iterator();
        while (it.hasNext()) {
            DoubleClickListener dl = it.next();
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if ((sel != null) && (!sel.isEmpty())) {
                Object element = sel.getFirstElement();
                PersistentObject po;/*w w w .  j  a va 2  s  .  co m*/
                if (element instanceof Tree<?>) {
                    po = (PersistentObject) ((Tree<?>) element).contents;
                } else {
                    po = (PersistentObject) element;
                }
                dl.doubleClicked(po, this);
            }
        }

    }

}

From source file:ch.elexis.views.artikel.ArtikelSelektor.java

License:Open Source License

@Override
public void createPartControl(final Composite parent) {
    parent.setLayout(new GridLayout());
    ctab = new CTabFolder(parent, SWT.NONE);
    ctab.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    java.util.List<IConfigurationElement> list = Extensions.getExtensions("ch.elexis.Verrechnungscode"); //$NON-NLS-1$
    ctab.addSelectionListener(new TabSelectionListener());
    for (IConfigurationElement ice : list) {
        if ("Artikel".equals(ice.getName())) { //$NON-NLS-1$
            try {
                CodeSelectorFactory cs = (CodeSelectorFactory) ice
                        .createExecutableExtension("CodeSelectorFactory"); //$NON-NLS-1$
                CTabItem ci = new CTabItem(ctab, SWT.NONE);
                ci.setText(cs.getCodeSystemName());
                ci.setData("csf", cs); //$NON-NLS-1$
            } catch (Exception ex) {
                ExHandler.handle(ex);/*from   w  ww. j a v  a 2s .  c  o  m*/
            }
        }
    }
    CTabItem ci = new CTabItem(ctab, SWT.NONE);
    Composite c = new Composite(ctab, SWT.NONE);
    c.setLayout(new GridLayout());
    ci.setControl(c);
    ci.setText("Lagerartikel"); //$NON-NLS-1$
    Table table = new Table(c, SWT.SIMPLE | SWT.V_SCROLL);
    table.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tv = new TableViewer(table);
    tv.setContentProvider(new IStructuredContentProvider() {

        public Object[] getElements(final Object inputElement) {
            List<Artikel> lLager = Artikel.getLagerartikel();
            if (lLager != null) {
                return lLager.toArray();
            } else {
                return new Object[0];
            }
        }

        public void dispose() {
        }

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

    });
    // tv.setLabelProvider(new LagerLabelProvider());
    tv.setLabelProvider(new ArtikelLabelProvider());
    tv.addDragSupport(DND.DROP_COPY, new Transfer[] { TextTransfer.getInstance() }, new DragSourceAdapter() {
        @Override
        public void dragStart(final DragSourceEvent event) {
            IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
            if ((sel == null) || sel.isEmpty()) {
                event.doit = false;
            }
            Object s = sel.getFirstElement();
            if (s instanceof PersistentObject) {
                PersistentObject po = (PersistentObject) s;
                event.doit = po.isDragOK();
            } else {
                event.doit = false;
            }
        }

        @Override
        public void dragSetData(final DragSourceEvent event) {
            IStructuredSelection isel = (IStructuredSelection) tv.getSelection();
            StringBuilder sb = new StringBuilder();
            Object[] sel = isel.toArray();
            for (Object s : sel) {
                if (s instanceof PersistentObject) {
                    sb.append(((PersistentObject) s).storeToString()).append(","); //$NON-NLS-1$
                } else {
                    sb.append("error").append(","); //$NON-NLS-1$ //$NON-NLS-2$
                }
            }
            event.data = sb.toString().replace(",$", ""); //$NON-NLS-1$ //$NON-NLS-2$
        }

    });
    tv.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(final DoubleClickEvent event) {
            IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
            if ((sel != null) && (!sel.isEmpty())) {
                Artikel art = (Artikel) sel.getFirstElement();
                EditEigenartikelUi.executeWithParams(art);
            }
        }

    });
    tv.setInput(this);
}

From source file:ch.elexis.views.BestellView.java

License:Open Source License

private void makeActions() {
    removeAction = new Action(Messages.getString("BestellView.RemoveArticle")) { //$NON-NLS-1$
        @Override/*from   w  ww.  j  a va  2  s.  c  o  m*/
        public void run() {
            IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
            if ((sel != null) && (!sel.isEmpty())) {
                if (actBestellung != null) {
                    actBestellung.removeItem((Item) sel.getFirstElement());
                }
                tv.refresh();
            }
        }
    };
    wizardAction = new Action(Messages.getString("BestellView.AutomaticOrder")) { //$NON-NLS-1$
        {
            setToolTipText(Messages.getString("BestellView.CreateAutomaticOrder")); //$NON-NLS-1$
            setImageDescriptor(Images.IMG_WIZARD.getImageDescriptor());
        }

        @Override
        public void run() {
            if (actBestellung == null) {
                setBestellung(new Bestellung(Messages.getString("BestellView.Automatic"), Hub.actUser)); //$NON-NLS-1$
            }
            /*
             * Query<Artikel> qbe=new Query<Artikel>(Artikel.class);
             * qbe.add("Minbestand","<>","0"); List<Artikel> l=qbe.execute();
             */

            int trigger = Hub.globalCfg.get(PreferenceConstants.INVENTORY_ORDER_TRIGGER,
                    PreferenceConstants.INVENTORY_ORDER_TRIGGER_DEFAULT);

            List<Artikel> l = Artikel.getLagerartikel();
            for (Artikel a : l) {
                if ((a == null) || (!a.exists())) {
                    continue;
                }
                // String name = a.getLabel();
                int ist = a.getIstbestand();
                int min = a.getMinbestand();
                int max = a.getMaxbestand();

                boolean order = false;
                switch (trigger) {
                case PreferenceConstants.INVENTORY_ORDER_TRIGGER_BELOW:
                    order = (ist < min);
                    break;
                case PreferenceConstants.INVENTORY_ORDER_TRIGGER_EQUAL:
                    order = (ist <= min);
                    break;
                default:
                    order = (ist < min);
                }
                if (order) {
                    Boolean alreadyOrdered = a.getExt(Bestellung.ISORDERED).equalsIgnoreCase("true");
                    int toOrder = max - ist;
                    if (toOrder > 0 && !alreadyOrdered) {
                        actBestellung.addItem(a, toOrder);
                    }
                }
            }
            tv.refresh(true);
        }
    };
    countAction = new Action(Messages.getString("BestellView.ChangeNumber")) { //$NON-NLS-1$
        @Override
        public void run() {
            IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
            if ((sel != null) && (!sel.isEmpty())) {
                Item it = (Item) sel.getFirstElement();
                int old = it.num;
                InputDialog in = new InputDialog(getViewSite().getShell(),
                        Messages.getString("BestellView.ChangeNumber"), //$NON-NLS-1$
                        Messages.getString("BestellView.EnterNewNumber"), //$NON-NLS-1$
                        Integer.toString(old), null);
                if (in.open() == Dialog.OK) {
                    it.num = Integer.parseInt(in.getValue());
                    tv.refresh(it, true);
                }
            }
        }
    };
    saveAction = new Action(Messages.getString("BestellView.SavelIst")) { //$NON-NLS-1$
        @Override
        public void run() {
            if (actBestellung != null) {
                actBestellung.save();
            }
        }
    };
    newAction = new Action(Messages.getString("BestellView.CreateNewOrder")) { //$NON-NLS-1$
        @Override
        public void run() {
            if (actBestellung != null) {
                actBestellung.save();
            }
            InputDialog dlg = new InputDialog(getViewSite().getShell(),
                    Messages.getString("BestellView.CreateNewOrder"), //$NON-NLS-1$
                    Messages.getString("BestellView.EnterOrderTitle"), //$NON-NLS-1$
                    Messages.getString("BestellView.Automatic"), null); //$NON-NLS-1$
            if (dlg.open() == Dialog.OK) {
                setBestellung(new Bestellung(dlg.getValue(), Hub.actUser));
            } else {
                return;
            }
            tv.refresh();
        }
    };
    printAction = new Action(Messages.getString("BestellView.PrintOrder")) { //$NON-NLS-1$
        @Override
        public void run() {
            if (actBestellung != null) {
                actBestellung.save();
                // make backup of list
                Item[] bkpList = actBestellung.asList().toArray(new Item[0]);

                List<Item> list = actBestellung.asList();
                ArrayList<Item> best = new ArrayList<Item>();
                Kontakt adressat = null;
                Iterator<Item> iter = list.iterator();
                while (iter.hasNext()) {
                    Item it = (Item) iter.next();
                    if (adressat == null) {
                        adressat = it.art.getLieferant();
                        if (!adressat.exists()) {
                            adressat = null;
                            continue;
                        }
                    }
                    if (it.art.getLieferant().getId().equals(adressat.getId())) {
                        best.add(it);
                        iter.remove();
                    }
                }

                try {
                    BestellBlatt bb = (BestellBlatt) getViewSite().getPage().showView(BestellBlatt.ID);
                    bb.createOrder(adressat, best);
                    tv.refresh();
                    // mark ordered articles
                    Bestellung.markAsOrdered(bkpList);
                } catch (PartInitException e) {
                    ExHandler.handle(e);

                }
            }
        }
    };
    sendAction = new Action(Messages.getString("BestellView.SendOrder")) { //$NON-NLS-1$
        @Override
        public void run() {
            if (actBestellung == null)
                return;
            actBestellung.save();
            // make backup of list
            Item[] bkpList = actBestellung.asList().toArray(new Item[0]);

            List<IConfigurationElement> list = Extensions.getExtensions("ch.elexis.Transporter"); //$NON-NLS-1$
            for (IConfigurationElement ic : list) {
                String handler = ic.getAttribute("type"); //$NON-NLS-1$

                if (handler != null && handler.contains("ch.elexis.data.Bestellung")) { //$NON-NLS-1$
                    try {
                        IDataSender sender = (IDataSender) ic.createExecutableExtension("ExporterClass"); //$NON-NLS-1$

                        sender.store(actBestellung);
                        sender.finalizeExport();
                        SWTHelper.showInfo(Messages.getString("BestellView.OrderSentCaption"), //$NON-NLS-1$
                                Messages.getString("BestellView.OrderSentBody")); //$NON-NLS-1$
                        tv.refresh();
                        // mark ordered articles
                        Bestellung.markAsOrdered(bkpList);
                    } catch (CoreException ex) {
                        ExHandler.handle(ex);
                    } catch (XChangeException xx) {
                        SWTHelper.showError(Messages.getString("BestellView.OrderNotPossible"), //$NON-NLS-1$
                                Messages.getString("BestellView.NoAutomaticOrderAvailable") //$NON-NLS-1$
                                        + xx.getLocalizedMessage());

                    }
                }
            }
        }
    };
    loadAction = new Action(Messages.getString("BestellView.OpenOrder")) { //$NON-NLS-1$
        @Override
        public void run() {

            SelectBestellungDialog dlg = new SelectBestellungDialog(getViewSite().getShell());
            dlg.setMessage(Messages.getString("BestellView.SelectOrder")); //$NON-NLS-1$
            dlg.setTitle(Messages.getString("BestellView.ReadOrder")); //$NON-NLS-1$

            if (dlg.open() == Dialog.OK) {
                // js: Only a non-empty result should be used any further.
                if (dlg.getResult().length > 0) {
                    Bestellung res = (Bestellung) dlg.getResult()[0];
                    setBestellung(res);
                }
            }
        }
    };
    printAction.setImageDescriptor(Images.IMG_PRINTER.getImageDescriptor());
    printAction.setToolTipText(Messages.getString("BestellView.PrintOrder")); //$NON-NLS-1$

    newAction.setImageDescriptor(Hub.getImageDescriptor("rsc/plaf/modern/icons/new.png")); //$NON-NLS-1$
    newAction.setToolTipText(Messages.getString("BestellView.CreateNewOrder")); //$NON-NLS-1$
    saveAction.setImageDescriptor(Hub.getImageDescriptor("rsc/save.gif")); //$NON-NLS-1$
    saveAction.setToolTipText(Messages.getString("BestellView.saveOrder")); //$NON-NLS-1$
    sendAction.setImageDescriptor(Images.IMG_NETWORK.getImageDescriptor());
    sendAction.setToolTipText(Messages.getString("BestellView.transmitOrder")); //$NON-NLS-1$
    // loadAction.setImageDescriptor(Hub.getImageDescriptor("rsc/open.gif"));
    loadAction.setImageDescriptor(Images.IMG_IMPORT.getImageDescriptor());
    loadAction.setToolTipText(Messages.getString("BestellView.loadEarlierOrder")); //$NON-NLS-1$

    exportClipboardAction = new Action(Messages.getString("BestellView.copyToClipboard")) { //$NON-NLS-1$
        {
            setToolTipText(Messages.getString("BestellView.copyToClipBioardForGalexis")); //$NON-NLS-1$
        }

        @Override
        public void run() {
            if (actBestellung != null) {
                List<Item> list = actBestellung.asList();
                ArrayList<Item> best = new ArrayList<Item>();
                Kontakt adressat = null;
                Iterator<Item> iter = list.iterator();
                while (iter.hasNext()) {
                    Item it = (Item) iter.next();
                    if (adressat == null) {
                        adressat = it.art.getLieferant();
                        if (!adressat.exists()) {
                            adressat = null;
                            continue;
                        }
                    }
                    if (it.art.getLieferant().getId().equals(adressat.getId())) {
                        best.add(it);
                        iter.remove();
                    }
                }

                StringBuffer export = new StringBuffer();
                for (Item item : best) {
                    String pharmaCode = item.art.get(Artikel.FLD_PHARMACODE);
                    int num = item.num;
                    String name = item.art.getName();
                    String line = pharmaCode + ", " + num + ", " + name; //$NON-NLS-1$ //$NON-NLS-2$

                    export.append(line);
                    export.append(System.getProperty("line.separator")); //$NON-NLS-1$
                }

                String clipboardText = export.toString();
                Clipboard clipboard = new Clipboard(Desk.getDisplay());
                TextTransfer textTransfer = TextTransfer.getInstance();
                Transfer[] transfers = new Transfer[] { textTransfer };
                Object[] data = new Object[] { clipboardText };
                clipboard.setContents(data, transfers);
                clipboard.dispose();
            }
        }
    };
    checkInAction = new Action(Messages.getString("BestellView.CheckInCaption")) { //$NON-NLS-1$
        {
            setImageDescriptor(Images.IMG_TICK.getImageDescriptor());
            setToolTipText(Messages.getString("BestellView.CheckInBody")); //$NON-NLS-1$
        }

        @Override
        public void run() {
            if (actBestellung != null && actBestellung.exists()) {
                OrderImportDialog dialog = new OrderImportDialog(getSite().getShell(), actBestellung);
                dialog.open();
            } else {
                SWTHelper.alert(Messages.getString("BestellView.NoOrder"), //$NON-NLS-1$
                        Messages.getString("BestellView.NoOrderLoaded")); //$NON-NLS-1$
            }
        }

    };
}

From source file:ch.elexis.views.LabNotSeenView.java

License:Open Source License

@Override
public void createPartControl(final Composite parent) {
    parent.setLayout(new FillLayout());
    Table table = new Table(parent, SWT.CHECK | SWT.V_SCROLL);
    for (int i = 0; i < columnHeaders.length; i++) {
        TableColumn tc = new TableColumn(table, SWT.NONE);
        tc.setText(columnHeaders[i]);/*from   w  ww .j a  v a  2s  . com*/
        tc.setWidth(colWidths[i]);
    }
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    tv = new CheckboxTableViewer(table);
    tv.setContentProvider(new LabNotSeenContentProvider());
    tv.setLabelProvider(new LabNotSeenLabelProvider());
    tv.setUseHashlookup(true);
    tv.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(final SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (!sel.isEmpty()) {
                if (sel.getFirstElement() instanceof LabResult) {
                    LabResult lr = (LabResult) sel.getFirstElement();
                    ElexisEventDispatcher.fireSelectionEvent(lr.getPatient());
                }
            }

        }
    });
    tv.addCheckStateListener(new ICheckStateListener() {
        boolean bDaempfung;

        public void checkStateChanged(final CheckStateChangedEvent event) {
            if (bDaempfung == false) {
                bDaempfung = true;
                LabResult lr = (LabResult) event.getElement();
                boolean state = event.getChecked();
                if (state) {
                    if (Hub.acl.request(AccessControlDefaults.LAB_SEEN)) {
                        lr.removeFromUnseen();
                    } else {
                        tv.setChecked(lr, false);
                    }
                } else {
                    lr.addToUnseen();
                }
                bDaempfung = false;
            }
        }

    });
    makeActions();
    ViewMenus menu = new ViewMenus(getViewSite());
    menu.createToolbar(markPersonAction, markAllAction);
    heartbeat();
    Hub.heart.addListener(this, Hub.localCfg.get(LabSettings.LABNEW_HEARTRATE, Heartbeat.FREQUENCY_HIGH));

    tv.setInput(this);
}

From source file:ch.elexis.views.rechnung.KonsZumVerrechnenView.java

License:Open Source License

private void makeActions() {
    billAction = new Action(Messages.getString("KonsZumVerrechnenView.createInvoices")) { //$NON-NLS-1$
        {/*w  ww  .j  ava2  s  .  c om*/
            setImageDescriptor(Hub.getImageDescriptor("rsc/rechnung.gif")); //$NON-NLS-1$
            setToolTipText(Messages.getString("KonsZumVerrechnenView.createInvoices")); //$NON-NLS-1$
        }

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            if (((StructuredSelection) tvSel.getSelection()).size() > 0) {
                if (!SWTHelper.askYesNo(Messages.getString("KonsZumVerrechnenView.RealleCreateBillsCaption"), //$NON-NLS-1$
                        Messages.getString("KonsZumVerrechnenView.ReallyCreateBillsBody"))) { //$NON-NLS-1$
                    return;
                }
            }
            // Handler.execute(getViewSite(), "bill.create", tSelection);
            ErstelleRnnCommand.ExecuteWithParams(getViewSite(), tSelection);
            /*
             * IHandlerService handlerService = (IHandlerService)
             * getViewSite().getService(IHandlerService.class); ICommandService cmdService =
             * (ICommandService) getViewSite().getService(ICommandService.class); try {
             * Command command = cmdService.getCommand("bill.create"); Parameterization px =
             * new Parameterization(command.getParameter
             * ("ch.elexis.RechnungErstellen.parameter" ), new
             * TreeToStringConverter().convertToString(tSelection)); ParameterizedCommand
             * parmCommand = new ParameterizedCommand(command, new Parameterization[] { px
             * });
             * 
             * handlerService.executeCommand(parmCommand, null);
             * 
             * } catch (Exception ex) { throw new RuntimeException("add.command not found");
             * }
             */

            tvSel.refresh();
        }
    };
    clearAction = new Action(Messages.getString("KonsZumVerrechnenView.clearSelection")) { //$NON-NLS-1$
        {
            setImageDescriptor(Desk.getImageDescriptor("delete")); //$NON-NLS-1$
            setToolTipText(Messages.getString("KonsZumVerrechnenView.deleteList")); //$NON-NLS-1$

        }

        @Override
        public void run() {
            tSelection.clear();
            tvSel.refresh();
        }
    };
    refreshAction = new Action(Messages.getString("KonsZumVerrechnenView.reloadAction")) { //$NON-NLS-1$
        {
            setImageDescriptor(Images.IMG_REFRESH.getImageDescriptor());
            setToolTipText(Messages.getString("KonsZumVerrechnenView.reloadToolTip")); //$NON-NLS-1$
        }

        @Override
        public void run() {
            tAll.clear();
            cv.notify(CommonViewer.Message.update);
            tvSel.refresh(true);
        }
    };
    wizardAction = new Action(Messages.getString("KonsZumVerrechnenView.autoAction")) { //$NON-NLS-1$
        {
            setImageDescriptor(Images.IMG_WIZARD.getImageDescriptor());
            setToolTipText(Messages.getString("KonsZumVerrechnenView.autoToolTip")); //$NON-NLS-1$
        }

        @Override
        public void run() {
            KonsZumVerrechnenWizardDialog kzvd = new KonsZumVerrechnenWizardDialog(getViewSite().getShell());
            if (kzvd.open() == Dialog.OK) {
                IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
                try {
                    progressService.runInUI(progressService, new Rechnungslauf(self, kzvd.bMarked,
                            kzvd.ttFirstBefore, kzvd.ttLastBefore, kzvd.mAmount, kzvd.bQuartal, kzvd.bSkip),
                            null);
                } catch (Throwable ex) {
                    ExHandler.handle(ex);
                }
                tvSel.refresh();
                cv.notify(CommonViewer.Message.update);
            }
        }
    };
    printAction = new Action(Messages.getString("KonsZumVerrechnenView.printSelection")) { //$NON-NLS-1$
        {
            setImageDescriptor(Images.IMG_PRINTER.getImageDescriptor());
            setToolTipText(Messages.getString("KonsZumVerrechnenView.printToolTip")); //$NON-NLS-1$
        }

        @Override
        public void run() {
            new SelectionPrintDialog(getViewSite().getShell()).open();

        }
    };
    removeAction = new Action(Messages.getString("KonsZumVerrechnenView.removeFromSelection")) { //$NON-NLS-1$
        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            IStructuredSelection sel = (IStructuredSelection) tvSel.getSelection();
            if (!sel.isEmpty()) {
                for (Object o : sel.toList()) {
                    if (o instanceof Tree) {
                        Tree t = (Tree) o;
                        if (t.contents instanceof Patient) {
                            selectPatient((Patient) t.contents, tSelection, tAll);
                        } else if (t.contents instanceof Fall) {
                            selectFall((Fall) t.contents, tSelection, tAll);
                        } else if (t.contents instanceof Konsultation) {
                            selectBehandlung((Konsultation) t.contents, tSelection, tAll);
                        }
                    }
                }
                tvSel.refresh();
                cv.notify(CommonViewer.Message.update);
            }
        }
    };

    // expand action for tvSel
    expandSelAction = new Action(Messages.getString("KonsZumVerrechnenView.expand")) { //$NON-NLS-1$
        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            IStructuredSelection sel = (IStructuredSelection) tvSel.getSelection();
            if (!sel.isEmpty()) {
                for (Object o : sel.toList()) {
                    if (o instanceof Tree) {
                        Tree t = (Tree) o;
                        tvSel.expandToLevel(t, TreeViewer.ALL_LEVELS);
                    }
                }
            }
        }
    };
    // expandAll action for tvSel
    expandSelAllAction = new Action(Messages.getString("KonsZumVerrechnenView.expandAll")) { //$NON-NLS-1$
        @Override
        public void run() {
            tvSel.expandAll();
        }
    };

    selectByDateAction = new Action(Messages.getString("KonsZumVerrechnenView.selectByDateAction")) { //$NON-NLS-1$
        TimeTool fromDate;
        TimeTool toDate;

        {
            setImageDescriptor(Images.IMG_WIZARD.getImageDescriptor());
            setToolTipText(Messages.getString("KonsZumVerrechnenView.selectByDateActionToolTip")); //$NON-NLS-1$
        }

        @Override
        public void run() {
            // select date
            SelectDateDialog dialog = new SelectDateDialog(getViewSite().getShell());
            if (dialog.open() == TitleAreaDialog.OK) {
                fromDate = dialog.getFromDate();
                toDate = dialog.getToDate();

                IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
                try {
                    progressService.runInUI(PlatformUI.getWorkbench().getProgressService(),
                            new IRunnableWithProgress() {
                                public void run(final IProgressMonitor monitor) {
                                    doSelectByDate(monitor, fromDate, toDate);
                                }
                            }, null);
                } catch (Throwable ex) {
                    ExHandler.handle(ex);
                }
                tvSel.refresh();
                cv.notify(CommonViewer.Message.update);
            }
        }

    };
    detailAction = new RestrictedAction(AccessControlDefaults.LSTG_VERRECHNEN,
            Messages.getString("KonsZumVerrechnenView.billingDetails")) { //$NON-NLS-1$
        @SuppressWarnings("unchecked")
        @Override
        public void doRun() {
            Object[] sel = cv.getSelection();
            if ((sel != null) && (sel.length > 0)) {
                new VerrDetailDialog(getViewSite().getShell(), (Tree) sel[0]).open();
            }
        }
    };
}

From source file:ch.netcetera.eclipse.projectconfig.ui.handler.RunProjectConfigurationScriptHandler.java

License:Open Source License

/**
 * Gets the selected projects./* w ww  .  j av  a  2  s . c  o  m*/
 *
 * @param selection the current selection
 * @return the selected projects
 */
private List<IProject> getProjectsFromSelection(ISelection selection) {
    List<IProject> projectList = new ArrayList<IProject>();

    if (selection instanceof IStructuredSelection) {
        IStructuredSelection currentSelection = (IStructuredSelection) selection;
        if (!currentSelection.isEmpty()) {
            Iterator<IProject> iterator = currentSelection.iterator();

            while (iterator.hasNext()) {
                IAdaptable selectedObject = iterator.next();
                if (selectedObject instanceof IJavaProject) {
                    IJavaProject javaProject = (IJavaProject) selectedObject;
                    projectList.add(javaProject.getProject());
                } else if (selectedObject instanceof IProject) {
                    projectList.add(((IProject) selectedObject).getProject());
                }
            }
        }
    }
    return projectList;
}

From source file:cideplus.ui.astview.ASTView.java

License:Open Source License

protected void performCollapse() {
    IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection();
    if (selection.isEmpty()) {
        fViewer.collapseAll();//w w w . j  ava 2 s.c o m
    } else {
        Object[] selected = selection.toArray();
        fViewer.getTree().setRedraw(false);
        for (int i = 0; i < selected.length; i++) {
            fViewer.collapseToLevel(selected[i], AbstractTreeViewer.ALL_LEVELS);
        }
        fViewer.getTree().setRedraw(true);
    }
}

From source file:cideplus.ui.astview.ASTView.java

License:Open Source License

protected void performExpand() {
    IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection();
    if (selection.isEmpty()) {
        fViewer.expandToLevel(3);//from  w ww.  j a v a 2  s.co m
    } else {
        Object[] selected = selection.toArray();
        fViewer.getTree().setRedraw(false);
        for (int i = 0; i < selected.length; i++) {
            fViewer.expandToLevel(selected[i], 3);
        }
        fViewer.getTree().setRedraw(true);
    }
}

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.actions.MenuActionHandler.java

License:Open Source License

/**
 * Returns a list of applicable context menu actions based on the given
 * context. Always returns a non-null list, although the list may be empty
 * if no actions are applicable to the given context.
 * /*from  ww w  . j  a  va  2 s  . c  o m*/
 * @param context to evaluate for the creation of actions. If null, an
 * attempt will be made to obtain the context directly from the Servers view
 * @return non-null list of actions corresponding to the given evaluation
 * context. May be empty if context is invalid.
 */
@SuppressWarnings("unchecked")
protected T getSelectionFromContext(Object context) {
    T selection = null;

    // First check if the context is an evaluation context, and attempt to
    // obtain the server module from the context
    if (context instanceof IEvaluationContext) {

        Object evalContext = ((IEvaluationContext) context).getDefaultVariable();

        if (evalContext instanceof List<?>) {
            List<?> content = (List<?>) evalContext;
            if (!content.isEmpty()) {
                Object obj = content.get(0);
                if (selectionClass.isAssignableFrom(obj.getClass())) {
                    selection = (T) obj;
                }
            }
        }
    }

    // Failed to get context selection from context.
    // Try the servers view directly
    if (selection == null) {

        IStructuredSelection strucSelection = CloudUiUtil.getServersViewSelection();
        if (strucSelection != null && !strucSelection.isEmpty()) {
            Object selectObj = strucSelection.getFirstElement();
            if (selectionClass.isAssignableFrom(selectObj.getClass())) {
                selection = (T) selectObj;
            }
        }
    }

    return selection;
}

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.editor.ApplicationDetailsPart.java

License:Open Source License

private void fillServicesContextMenu(IMenuManager manager) {
    IStructuredSelection selection = (IStructuredSelection) servicesViewer.getSelection();
    if (selection.isEmpty())
        return;/*from  ww  w .j av  a  2  s.c  o m*/

    try {
        DockerFoundryApplicationModule appModule = getExistingApplication();
        manager.add(new RemoveServicesFromApplicationAction(selection, appModule, serverBehaviour, editorPage));
    } catch (CoreException ce) {
        logApplicationModuleFailureError(Messages.ApplicationDetailsPart_ERROR_DETERMINE_BOUND_SERVICE);
    }
}