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

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

Introduction

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

Prototype

public List toList();

Source Link

Document

Returns the elements in this selection as a List.

Usage

From source file:br.com.tecsinapse.glimpse.launch.RunGlimpseLaunchShortcut.java

License:Apache License

@Override
public void launch(ISelection selection, String mode) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection strSel = (IStructuredSelection) selection;
        List<?> files = strSel.toList();
        if (files.size() == 1) {
            IFile file = (IFile) Platform.getAdapterManager().getAdapter(files.get(0), IFile.class);
            try {
                String name = file.getName();
                String script = IOUtils.toString(file.getContents());
                launchJob(name, script);
            } catch (IOException e) {
                throw new IllegalStateException(e);
            } catch (CoreException e) {
                throw new IllegalStateException(e);
            }//from  w ww . j ava2 s  . c o m
        }
    }
}

From source file:ccw.launching.ClojureLaunchShortcut.java

License:Open Source License

public void launch(ISelection selection, final String mode, final boolean forceLeinLaunchWhenPossible) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection strSel = (IStructuredSelection) selection;
        final List<IFile> files = new ArrayList<IFile>();
        IProject proj = null;/*from   w w w.  ja  va2s. c  o  m*/
        for (Object o : strSel.toList()) {
            IResource r = (IResource) Platform.getAdapterManager().getAdapter(o, IResource.class);
            if (r != null) {
                if (r.getType() == IResource.FILE) {
                    files.add((IFile) r);
                }
                if (proj == null) {
                    proj = r.getProject();
                }
            }
        }
        if (proj != null) {
            final IProject theProj = proj;
            // a new thread ensures we're not in the UI thread
            new Thread(new Runnable() {
                @Override
                public void run() {
                    launchProjectCheckRunning(theProj, files.toArray(new IFile[] {}), mode,
                            forceLeinLaunchWhenPossible, null);
                }
            }).start();
        }
    }
}

From source file:ch.elexis.core.ui.dialogs.SelectBestellungDialog.java

License:Open Source License

protected void okPressed() {
    // Build a list of selected children.
    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
    setResult(selection.toList());
    super.okPressed();
}

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

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    composite.setLayout(new GridLayout(1, false));

    Label label;// ww w  . j  a  v a  2 s. c  o m
    GridLayout layout;

    Composite topArea = new Composite(composite, SWT.NONE);
    topArea.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
    layout = new GridLayout(3, false);
    layout.verticalSpacing = 20;
    topArea.setLayout(layout);

    label = new Label(topArea, SWT.NONE);
    label.setText(Messages.LabGroupPrefs_ExplanationsLine1 + Messages.LabGroupPrefs_ExplanationsLine2
            + Messages.LabGroupPrefs_ExplanationsLine3);
    label.setLayoutData(SWTHelper.getFillGridData(3, true, 1, false));

    GridData gd;

    label = new Label(topArea, SWT.NONE);
    label.setText(Messages.LabGroupPrefs_group);
    gd = SWTHelper.getFillGridData(1, false, 1, false);
    gd.verticalAlignment = GridData.BEGINNING;
    label.setLayoutData(gd);

    groupsViewer = new ComboViewer(topArea, SWT.READ_ONLY);
    gd = SWTHelper.getFillGridData(1, true, 1, false);
    gd.verticalAlignment = GridData.BEGINNING;
    groupsViewer.getControl().setLayoutData(gd);

    groupsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) groupsViewer.getSelection();
            Object element = sel.getFirstElement();
            if (element instanceof LabGroup) {
                actGroup = (LabGroup) element;

                itemsViewer.refresh();
            }

            updateButtonsState();
        }
    });

    groupsViewer.setContentProvider(new GroupsContentProvider());
    groupsViewer.setLabelProvider(new DefaultLabelProvider());

    groupsViewer.setInput(this);

    Composite groupButtonArea = new Composite(topArea, SWT.PUSH);
    layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    groupButtonArea.setLayout(layout);

    newButton = new Button(groupButtonArea, SWT.PUSH);
    newButton.setText(Messages.LabGroupPrefs_new);
    newButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            InputDialog dialog = new InputDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    Messages.LabGroupPrefs_newLabGroup, Messages.LabGroupPrefs_selectNameForLabGroup, "", null); //$NON-NLS-1$
            int rc = dialog.open();
            if (rc == Window.OK) {
                String name = dialog.getValue();
                LabGroup group = new LabGroup(name, null);

                groupsViewer.refresh();
                groupsViewer.setSelection(new StructuredSelection(group));
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    removeButton = new Button(groupButtonArea, SWT.PUSH);
    removeButton.setText(Messages.LabGroupPrefs_delete);
    removeButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (actGroup != null) {
                if (SWTHelper.askYesNo(Messages.LabGroupPrefs_deleteGroup,
                        MessageFormat.format(Messages.LabGroupPrefs_reallyDeleteGroup, actGroup.getLabel())))
                    ;
                {

                    actGroup.delete();
                    actGroup = null;
                    groupsViewer.refresh();
                    itemsViewer.refresh();
                    selectFirstGroup();
                }
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    final Button showGroups = new Button(topArea, SWT.NONE | SWT.CHECK);
    showGroups.setText(Messages.LabGroupPrefs_showLabGroupsOnly);
    showGroups.setSelection(CoreHub.userCfg.get(SHOW_GROUPS_ONLY, false));
    showGroups.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            CoreHub.userCfg.set(SHOW_GROUPS_ONLY, showGroups.getSelection());
        }
    });

    Composite bottomArea = new Composite(composite, SWT.NONE);
    bottomArea.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    bottomArea.setLayout(new GridLayout(1, false));

    label = new Label(bottomArea, SWT.NONE);
    label.setText(Messages.LabGroupPrefs_containingLabItems);

    itemsViewer = new ListViewer(bottomArea, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    itemsViewer.getControl().setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));

    itemsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateItemButtonsState();
        }
    });

    itemsViewer.setContentProvider(new GroupItemsContentProvider());
    itemsViewer.setLabelProvider(new ItemsLabelProvider());

    itemsViewer.setInput(this);

    Composite buttonArea = new Composite(bottomArea, SWT.NONE);
    buttonArea.setLayoutData(SWTHelper.getFillGridData(1, false, 1, false));
    buttonArea.setLayout(new GridLayout(2, true));

    addItemButton = new Button(buttonArea, SWT.PUSH);
    addItemButton.setText(Messages.LabGroupPrefs_add);
    addItemButton.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));

    removeItemButton = new Button(buttonArea, SWT.PUSH);
    removeItemButton.setText(Messages.LabGroupPrefs_remove);
    removeItemButton.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));

    addItemButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (actGroup != null) {
                LabItemSelektor selektor = new LabItemSelektor(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
                if (selektor.open() == Dialog.OK) {
                    List<LabItem> items = selektor.getSelection();

                    // list of existing items
                    List<LabItem> existingItems = actGroup.getItems();

                    for (Object obj : items) {
                        if (obj instanceof LabItem) {
                            LabItem item = (LabItem) obj;
                            if (!existingItems.contains(item)) {
                                actGroup.addItem(item);
                            }
                        }
                    }
                    itemsViewer.refresh();
                }
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    removeItemButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (actGroup != null) {
                IStructuredSelection sel = (IStructuredSelection) itemsViewer.getSelection();
                for (Object obj : sel.toList()) {
                    if (obj instanceof LabItem) {
                        LabItem item = (LabItem) obj;
                        actGroup.removeItem(item);
                    }
                }

                itemsViewer.refresh();
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    selectFirstGroup();

    return composite;
}

From source file:ch.elexis.core.ui.util.PersistentObjectDragSource.java

License:Open Source License

public PersistentObjectDragSource(final StructuredViewer v) {
    dragSource = v.getControl();/*w  w w  . ja v a 2s  .c o  m*/
    renderer = new ISelectionRenderer() {

        public List<PersistentObject> getSelection() {
            IStructuredSelection sel = (IStructuredSelection) v.getSelection();
            return sel.toList();
        }

    };
    setup();
}

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

License:Open Source License

private void makeActions() {
    removeAction = new Action(Messages.BestellView_RemoveArticle) { //$NON-NLS-1$
        @Override// w w  w  .ja v a  2s .  c o  m
        public void run() {
            IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
            if ((sel != null) && (!sel.isEmpty())) {
                if (actBestellung != null) {
                    @SuppressWarnings("unchecked")
                    List<BestellungEntry> selections = sel.toList();
                    for (BestellungEntry entry : selections) {
                        actBestellung.removeEntry(entry);
                    }
                    tv.refresh();
                }
            }
        }
    };
    dailyWizardAction = new Action(Messages.BestellView_AutomaticDailyOrder) {
        {
            setToolTipText(Messages.BestellView_CreateAutomaticDailyOrder);
            setImageDescriptor(Images.IMG_WIZ_DAY.getImageDescriptor());
        }

        @Override
        public void run() {
            if (actBestellung == null) {
                setBestellung(new Bestellung(Messages.BestellView_AutomaticDaily, CoreHub.actUser)); //$NON-NLS-1$
            }

            DailyOrderDialog doDlg = new DailyOrderDialog(UiDesk.getTopShell(), actBestellung);
            doDlg.open();
            tv.refresh(true);
        }
    };

    wizardAction = new Action(Messages.BestellView_AutomaticOrder) { //$NON-NLS-1$
        {
            setToolTipText(Messages.BestellView_CreateAutomaticOrder); //$NON-NLS-1$
            setImageDescriptor(Images.IMG_WIZARD.getImageDescriptor());
        }

        @Override
        public void run() {
            if (actBestellung == null) {
                setBestellung(new Bestellung(Messages.BestellView_Automatic, CoreHub.actUser));
            }

            int trigger = CoreHub.globalCfg.get(ch.elexis.core.constants.Preferences.INVENTORY_ORDER_TRIGGER,
                    ch.elexis.core.constants.Preferences.INVENTORY_ORDER_TRIGGER_DEFAULT);
            boolean isInventoryBelow = trigger == ch.elexis.core.constants.Preferences.INVENTORY_ORDER_TRIGGER_BELOW;

            Query<StockEntry> qbe = new Query<StockEntry>(StockEntry.class, null, null, StockEntry.TABLENAME,
                    new String[] { StockEntry.FLD_CURRENT, StockEntry.FLD_MAX });
            qbe.add(StockEntry.FLD_CURRENT, isInventoryBelow ? Query.LESS : Query.LESS_OR_EQUAL,
                    StockEntry.FLD_MIN);
            List<StockEntry> stockEntries = qbe.execute();
            for (StockEntry se : stockEntries) {
                CoreHub.getOrderService().addRefillForStockEntryToOrder(se, actBestellung);
            }
            tv.refresh(true);
        }
    };
    newAction = new Action(Messages.BestellView_CreateNewOrder) { //$NON-NLS-1$
        @Override
        public void run() {
            NeueBestellungDialog nbDlg = new NeueBestellungDialog(getViewSite().getShell(),
                    Messages.BestellView_CreateNewOrder, Messages.BestellView_EnterOrderTitle);
            if (nbDlg.open() == Dialog.OK) {
                setBestellung(new Bestellung(nbDlg.getTitle(), CoreHub.actUser));
            } else {
                return;
            }
            tv.refresh();
        }
    };
    printAction = new Action(Messages.BestellView_PrintOrder) { //$NON-NLS-1$
        @Override
        public void run() {
            if (actBestellung != null) {

                Kontakt receiver = null;
                List<BestellungEntry> best = prepareOrderList(receiver);

                try {
                    BestellBlatt bb = (BestellBlatt) getViewSite().getPage().showView(BestellBlatt.ID);
                    bb.createOrder(receiver, best);
                    tv.refresh();

                    Bestellung.markAsOrdered(best);
                } catch (PartInitException e) {
                    ExHandler.handle(e);

                }
            }
        }
    };
    sendAction = new Action(Messages.BestellView_SendOrder) {
        @Override
        public void run() {
            if (actBestellung == null)
                return;

            // organise items in supplier and non-supplier lists
            List<BestellungEntry> orderableItems = new ArrayList<BestellungEntry>();
            List<BestellungEntry> noSupplierItems = new ArrayList<BestellungEntry>();
            for (BestellungEntry item : actBestellung.getEntries()) {
                Kontakt supplier = item.getProvider();
                if (supplier != null && supplier.exists()) {
                    orderableItems.add(item);
                } else {
                    noSupplierItems.add(item);
                }
            }

            boolean runOrder = true;
            if (!noSupplierItems.isEmpty()) {
                StringBuilder sb = new StringBuilder();
                for (BestellungEntry noSupItem : noSupplierItems) {
                    sb.append(noSupItem.getArticle().getLabel());
                    sb.append("\n");
                }
                runOrder = SWTHelper.askYesNo(Messages.BestellView_NoSupplierArticle,
                        MessageFormat.format(Messages.BestellView_NoSupplierArticleMsg, sb.toString()));
            }

            if (runOrder) {
                List<IConfigurationElement> list = Extensions
                        .getExtensions(ExtensionPointConstantsUi.TRANSPORTER);
                for (IConfigurationElement ic : list) {
                    String handler = ic.getAttribute("type");
                    if (handler != null && handler.contains(Bestellung.class.getName())) {
                        try {
                            IDataSender sender = (IDataSender) ic
                                    .createExecutableExtension(ExtensionPointConstantsUi.TRANSPORTER_EXPC);

                            sender.store(actBestellung);
                            sender.finalizeExport();
                            SWTHelper.showInfo(Messages.BestellView_OrderSentCaption,
                                    Messages.BestellView_OrderSentBody);
                            tv.refresh();

                            Bestellung.markAsOrdered(orderableItems);

                        } catch (CoreException ex) {
                            ExHandler.handle(ex);
                        } catch (XChangeException xx) {
                            SWTHelper.showError(Messages.BestellView_OrderNotPossible,
                                    Messages.BestellView_NoAutomaticOrderAvailable + xx.getLocalizedMessage());

                        }
                    }
                }
            }
        }
    };
    loadAction = new Action(Messages.BestellView_OpenOrder) {
        @Override
        public void run() {

            SelectBestellungDialog dlg = new SelectBestellungDialog(getViewSite().getShell());
            dlg.setMessage(Messages.BestellView_SelectOrder); //$NON-NLS-1$
            dlg.setTitle(Messages.BestellView_ReadOrder); //$NON-NLS-1$

            if (dlg.open() == Dialog.OK) {
                if (dlg.getResult().length > 0) {
                    Bestellung res = (Bestellung) dlg.getResult()[0];
                    setBestellung(res);
                }
            }
        }
    };
    printAction.setImageDescriptor(Images.IMG_PRINTER.getImageDescriptor());
    printAction.setToolTipText(Messages.BestellView_PrintOrder);
    newAction.setImageDescriptor(Images.IMG_ADDITEM.getImageDescriptor());
    newAction.setToolTipText(Messages.BestellView_CreateNewOrder);
    sendAction.setImageDescriptor(Images.IMG_NETWORK.getImageDescriptor());
    sendAction.setToolTipText(Messages.BestellView_transmitOrder);
    loadAction.setImageDescriptor(Images.IMG_IMPORT.getImageDescriptor());
    loadAction.setToolTipText(Messages.BestellView_loadEarlierOrder);

    exportClipboardAction = new Action(Messages.BestellView_copyToClipboard) {
        {
            setToolTipText(Messages.BestellView_copyToClipBioardForGalexis);
        }

        @Override
        public void run() {
            if (actBestellung != null) {
                Kontakt receiver = null;
                List<BestellungEntry> best = prepareOrderList(receiver);

                StringBuffer export = new StringBuffer();
                for (BestellungEntry item : best) {
                    String pharmaCode = item.getArticle().getPharmaCode();
                    int num = item.getCount();
                    String name = item.getArticle().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(UiDesk.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.BestellView_CheckInCaption) { //$NON-NLS-1$
        {
            setImageDescriptor(Images.IMG_TICK.getImageDescriptor());
            setToolTipText(Messages.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.BestellView_NoOrder, //$NON-NLS-1$
                        Messages.BestellView_NoOrderLoaded); //$NON-NLS-1$
            }
        }

    };
}

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

License:Open Source License

private void makeActions() {
    billAction = new Action(Messages.KonsZumVerrechnenView_createInvoices) { //$NON-NLS-1$
        {/*from ww w .j  av  a  2s.co  m*/
            setImageDescriptor(Images.IMG_BILL.getImageDescriptor()); //$NON-NLS-1$
            setToolTipText(Messages.KonsZumVerrechnenView_createInvoices); //$NON-NLS-1$
        }

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            if (((StructuredSelection) tvSel.getSelection()).size() > 0) {
                if (!SWTHelper.askYesNo(Messages.KonsZumVerrechnenView_RealleCreateBillsCaption, //$NON-NLS-1$
                        Messages.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.KonsZumVerrechnenView_clearSelection) { //$NON-NLS-1$
        {
            setImageDescriptor(Images.IMG_REMOVEITEM.getImageDescriptor()); //$NON-NLS-1$
            setToolTipText(Messages.KonsZumVerrechnenView_deleteList); //$NON-NLS-1$

        }

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

        @Override
        public void run() {
            tAll.clear();
            cv.notify(CommonViewer.Message.update);
            tvSel.refresh(true);
        }
    };
    wizardAction = new Action(Messages.KonsZumVerrechnenView_autoAction) { //$NON-NLS-1$
        {
            setImageDescriptor(Images.IMG_WIZARD.getImageDescriptor());
            setToolTipText(Messages.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, kzvd.ttFrom, kzvd.ttTo,
                                    kzvd.accountSys),
                            null);
                } catch (Throwable ex) {
                    ExHandler.handle(ex);
                }
                tvSel.refresh();
                cv.notify(CommonViewer.Message.update);
            }
        }
    };
    printAction = new Action(Messages.KonsZumVerrechnenView_printSelection) { //$NON-NLS-1$
        {
            setImageDescriptor(Images.IMG_PRINTER.getImageDescriptor());
            setToolTipText(Messages.KonsZumVerrechnenView_printToolTip); //$NON-NLS-1$
        }

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

        }
    };
    removeAction = new Action(Messages.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.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.KonsZumVerrechnenView_expandAll) { //$NON-NLS-1$
        @Override
        public void run() {
            tvSel.expandAll();
        }
    };

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

        {
            setImageDescriptor(Images.IMG_WIZARD.getImageDescriptor());
            setToolTipText(Messages.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.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.elexis.core.ui.views.rechnung.RechnungsListeView.java

License:Open Source License

@SuppressWarnings("unchecked")
List<Rechnung> createList() {
    IStructuredSelection sel = (IStructuredSelection) cv.getViewerWidget().getSelection();
    List<Tree> at = sel.toList();
    List<Rechnung> ret = new LinkedList<Rechnung>();
    for (Tree<PersistentObject> t : at) {
        if (t.contents instanceof Patient) {
            for (Tree<PersistentObject> tp : t.getChildren()) {
                for (Tree<PersistentObject> tf : tp.getChildren()) {
                    Rechnung rn = (Rechnung) tf.contents;
                    if (!ret.contains(rn)) {
                        ret.add(rn);/*w w w. j  a v  a  2  s . com*/
                    }
                }
            }
        } else if (t.contents instanceof Fall) {
            for (Tree<PersistentObject> tr : t.getChildren()) {
                Rechnung rn = (Rechnung) tr.contents;
                if (!ret.contains(rn)) {
                    ret.add(rn);
                }
            }
        } else if (t.contents instanceof Rechnung) {
            Rechnung rn = (Rechnung) t.contents;
            if (!ret.contains(rn)) {
                ret.add(rn);
            }
        }
    }
    return ret;
}

From source file:ch.elexis.preferences.LabGroupPrefs.java

License:Open Source License

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    composite.setLayout(new GridLayout(1, false));

    Label label;/*from   w w  w .  jav a2s  .  com*/
    GridLayout layout;

    Composite topArea = new Composite(composite, SWT.NONE);
    topArea.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
    layout = new GridLayout(3, false);
    layout.verticalSpacing = 20;
    topArea.setLayout(layout);

    label = new Label(topArea, SWT.NONE);
    label.setText(Messages.LabGroupPrefs_ExplanationsLine1 + Messages.LabGroupPrefs_ExplanationsLine2
            + Messages.LabGroupPrefs_ExplanationsLine3);
    label.setLayoutData(SWTHelper.getFillGridData(3, true, 1, false));

    GridData gd;

    label = new Label(topArea, SWT.NONE);
    label.setText(Messages.LabGroupPrefs_group);
    gd = SWTHelper.getFillGridData(1, false, 1, false);
    gd.verticalAlignment = GridData.BEGINNING;
    label.setLayoutData(gd);

    groupsViewer = new ComboViewer(topArea, SWT.READ_ONLY);
    gd = SWTHelper.getFillGridData(1, true, 1, false);
    gd.verticalAlignment = GridData.BEGINNING;
    groupsViewer.getControl().setLayoutData(gd);

    groupsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) groupsViewer.getSelection();
            Object element = sel.getFirstElement();
            if (element instanceof LabGroup) {
                actGroup = (LabGroup) element;

                itemsViewer.refresh();
            }

            updateButtonsState();
        }
    });

    groupsViewer.setContentProvider(new GroupsContentProvider());
    groupsViewer.setLabelProvider(new DefaultLabelProvider());

    groupsViewer.setInput(this);

    Composite groupButtonArea = new Composite(topArea, SWT.PUSH);
    layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    groupButtonArea.setLayout(layout);

    newButton = new Button(groupButtonArea, SWT.PUSH);
    newButton.setText(Messages.LabGroupPrefs_new);
    newButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            InputDialog dialog = new InputDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    Messages.LabGroupPrefs_newLabGroup, Messages.LabGroupPrefs_selectNameForLabGroup, "", null); //$NON-NLS-1$
            int rc = dialog.open();
            if (rc == Window.OK) {
                String name = dialog.getValue();
                LabGroup group = new LabGroup(name, null);

                groupsViewer.refresh();
                groupsViewer.setSelection(new StructuredSelection(group));
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    removeButton = new Button(groupButtonArea, SWT.PUSH);
    removeButton.setText(Messages.LabGroupPrefs_delete);
    removeButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            if (actGroup != null) {
                if (SWTHelper.askYesNo(Messages.LabGroupPrefs_deleteGroup,
                        MessageFormat.format(Messages.LabGroupPrefs_reallyDeleteGroup, actGroup.getLabel())))
                    ;
                {

                    actGroup.delete();
                    actGroup = null;
                    groupsViewer.refresh();
                    itemsViewer.refresh();
                    selectFirstGroup();
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    Composite bottomArea = new Composite(composite, SWT.NONE);
    bottomArea.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    bottomArea.setLayout(new GridLayout(1, false));

    label = new Label(bottomArea, SWT.NONE);
    label.setText(Messages.LabGroupPrefs_containingLabItems);

    itemsViewer = new ListViewer(bottomArea, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    itemsViewer.getControl().setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));

    itemsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateItemButtonsState();
        }
    });

    itemsViewer.setContentProvider(new GroupItemsContentProvider());
    itemsViewer.setLabelProvider(new ItemsLabelProvider());

    itemsViewer.setInput(this);

    Composite buttonArea = new Composite(bottomArea, SWT.NONE);
    buttonArea.setLayoutData(SWTHelper.getFillGridData(1, false, 1, false));
    buttonArea.setLayout(new GridLayout(2, true));

    addItemButton = new Button(buttonArea, SWT.PUSH);
    addItemButton.setText(Messages.LabGroupPrefs_add);
    addItemButton.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));

    removeItemButton = new Button(buttonArea, SWT.PUSH);
    removeItemButton.setText(Messages.LabGroupPrefs_remove);
    removeItemButton.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));

    addItemButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            if (actGroup != null) {
                ItemsSelectionDialog dialog = new ItemsSelectionDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), actGroup);
                if (dialog.open() == ItemsSelectionDialog.OK) {
                    itemsViewer.refresh();
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    removeItemButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            if (actGroup != null) {
                IStructuredSelection sel = (IStructuredSelection) itemsViewer.getSelection();
                for (Object obj : sel.toList()) {
                    if (obj instanceof LabItem) {
                        LabItem item = (LabItem) obj;
                        actGroup.removeItem(item);
                    }
                }

                itemsViewer.refresh();
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    selectFirstGroup();

    return composite;
}

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$
        {// ww  w .  j a  v a2s  . c o m
            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();
            }
        }
    };
}