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

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

Introduction

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

Prototype

public ComboViewer(Composite parent, int style) 

Source Link

Document

Creates a combo viewer on a newly-created combo control under the given parent.

Usage

From source file:ca.piggott.p2.site.webview.ui.P2SiteBuilderDialog.java

License:Open Source License

/**
 * Create contents of the dialog.//from ww  w. j  a  v a 2s .com
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    setTitle("p2 Site Builder");
    this.getShell().setText("p2 Site Builder");
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(3, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    Label lblRepository = new Label(container, SWT.NONE);
    lblRepository.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblRepository.setText("Repository:");

    comboViewer = new ComboViewer(container, SWT.NONE);
    Combo combo = comboViewer.getCombo();
    combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    comboViewer.setContentProvider(this);
    comboViewer.setLabelProvider(this);
    comboViewer.setInput(ProvisioningUI.getDefaultUI().getRepositoryTracker());
    Label lblDestination = new Label(container, SWT.NONE);
    lblDestination.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblDestination.setText("Destination");

    text = new Text(container, SWT.BORDER);
    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    text.addModifyListener(this);

    Button btnBrowse = new Button(container, SWT.NONE);
    btnBrowse.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fDialog = new FileDialog(getShell(), SWT.SAVE);
            if (text.getText().length() > 0) {
                fDialog.setFileName(text.getText());
            }
            fDialog.setOverwrite(true);
            fDialog.setFilterExtensions(new String[] { "*.html", "*.htm" });

            String selection = fDialog.open();
            if (selection != null) {
                text.setText(selection);
            }
        }
    });
    btnBrowse.setText("Browse");
    new Label(container, SWT.NONE);
    new Label(container, SWT.NONE);

    return area;
}

From source file:ca.uvic.chisel.logging.eclipse.internal.ui.WorkbenchLoggerPreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(2, false));

    // create a list viewer that will display all of the
    // different loggers

    viewer = CheckboxTableViewer.newCheckList(page, SWT.BORDER | SWT.SINGLE);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LoggingCategoryLabelProvider());
    viewer.setInput(WorkbenchLoggingPlugin.getDefault().getCategoryManager().getCategories());
    // set all of the enabled categories to the checked state
    boolean stale = false;
    for (ILoggingCategory category : WorkbenchLoggingPlugin.getDefault().getCategoryManager().getCategories()) {
        if (category.isEnabled()) {
            enabledCategories.add(category.getCategoryID());
            viewer.setChecked(category, true);
        }/*w  w w.  jav  a  2 s.com*/
        // also set the stale state... used for enabling the upload button.
        stale |= ((LoggingCategory) category).isStale();
    }
    viewer.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getElement() instanceof ILoggingCategory) {
                ILoggingCategory category = (ILoggingCategory) event.getElement();
                if (event.getChecked()) {
                    enabledCategories.add(category.getCategoryID());
                } else {
                    enabledCategories.remove(category.getCategoryID());
                }
            }
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            if (aboutButton != null && !aboutButton.isDisposed()) {
                aboutButton.setEnabled(!event.getSelection().isEmpty());
            }
        }
    });

    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    // create a button area
    Composite buttonArea = new Composite(page, SWT.NONE);
    buttonArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    buttonArea.setLayout(new GridLayout());

    GridDataFactory gdf = GridDataFactory.createFrom(new GridData(SWT.FILL, SWT.FILL, true, false));
    Button selectAll = new Button(buttonArea, SWT.PUSH);
    selectAll.setText("Select All");
    selectAll.setLayoutData(gdf.create());
    selectAll.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            viewer.setAllChecked(true);
            for (ILoggingCategory category : WorkbenchLoggingPlugin.getDefault().getCategoryManager()
                    .getCategories()) {
                enabledCategories.add(category.getCategoryID());
            }
        }
    });

    Button selectNone = new Button(buttonArea, SWT.PUSH);
    selectNone.setText("Select None");
    selectNone.setLayoutData(gdf.create());
    selectNone.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            viewer.setAllChecked(false);
            enabledCategories.clear();
        }
    });

    Control spacer = new Composite(buttonArea, SWT.NONE);
    GridData d = gdf.create();
    d.heightHint = 40;
    spacer.setLayoutData(d);

    aboutButton = new Button(buttonArea, SWT.PUSH);
    aboutButton.setText("About...");
    aboutButton.setLayoutData(gdf.create());
    aboutButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = viewer.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection ss = (IStructuredSelection) selection;
                if (!ss.isEmpty() && ss.getFirstElement() instanceof ILoggingCategory) {
                    AboutCategoryDialog dialog = new AboutCategoryDialog(getShell(),
                            (ILoggingCategory) ss.getFirstElement());
                    dialog.open();
                }
            }
        }
    });
    aboutButton.setEnabled(false);

    spacer = new Composite(buttonArea, SWT.NONE);
    d = gdf.create();
    d.heightHint = 40;
    spacer.setLayoutData(d);

    Button uploadButton = new Button(buttonArea, SWT.PUSH);
    uploadButton.setText("Upload Now...");
    uploadButton.setLayoutData(gdf.create());
    uploadButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            WizardDialog dialog = new WizardDialog(getShell(), new UploadWizard());
            dialog.open();
        }
    });
    uploadButton.setEnabled(stale);
    Composite intervalComposite = new Composite(page, SWT.NONE);
    GridData gd = gdf.create();
    gd.grabExcessVerticalSpace = false;
    gd.grabExcessHorizontalSpace = true;
    intervalComposite.setLayoutData(gd);
    intervalComposite.setLayout(new GridLayout(2, false));
    Label intervalLabel = new Label(intervalComposite, SWT.NONE);
    intervalLabel.setText("Upload Interval: ");
    gd = gdf.create();
    gd.grabExcessVerticalSpace = false;
    gd.grabExcessHorizontalSpace = false;
    intervalLabel.setLayoutData(gd);
    intervalViewer = new ComboViewer(intervalComposite, SWT.BORDER | SWT.SINGLE);
    Long[] intervals = new Long[] { UploadJob.UPLOAD_INTERVAL_DAILY, UploadJob.UPLOAD_INTERVAL_WEEKLY,
            UploadJob.UPLOAD_INTERVAL_MONTHLY };
    intervalViewer.setContentProvider(new ArrayContentProvider());
    intervalViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof Long) {
                long interval = (Long) element;
                if (interval == UploadJob.UPLOAD_INTERVAL_DAILY) {
                    return "Daily";
                } else if (interval == UploadJob.UPLOAD_INTERVAL_WEEKLY) {
                    return "Every Seven Days";
                } else if (interval == UploadJob.UPLOAD_INTERVAL_MONTHLY) {
                    return "Every Thirty Days";
                }
            }
            return super.getText(element);
        }
    });
    intervalViewer.setInput(intervals);
    long interval = WorkbenchLoggingPlugin.getDefault().getPreferenceStore()
            .getLong(UploadJob.UPLOAD_INTERVAL_KEY);
    if (interval <= 0) {
        interval = WorkbenchLoggingPlugin.getDefault().getPreferenceStore()
                .getDefaultLong(UploadJob.UPLOAD_INTERVAL_KEY);
    }
    intervalViewer.setSelection(new StructuredSelection(interval));
    intervalViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    spacer = new Composite(page, SWT.NONE);
    gd = gdf.create();
    gd.grabExcessVerticalSpace = false;
    gd.grabExcessHorizontalSpace = false;
    gd.heightHint = 2;
    spacer.setLayoutData(gd);
    Composite uidComposite = new Composite(page, SWT.NONE);
    uidComposite.setLayout(new GridLayout(2, false));
    gd = gdf.create();
    gd.grabExcessVerticalSpace = false;
    gd.grabExcessHorizontalSpace = false;
    gd.horizontalSpan = 2;
    uidComposite.setLayoutData(gd);
    Label uidLabel = new Label(uidComposite, SWT.NONE);
    uidLabel.setText("User ID:");
    gd = gdf.create();
    gd.grabExcessVerticalSpace = false;
    gd.grabExcessHorizontalSpace = false;
    uidLabel.setLayoutData(gd);
    final Text uidText = new Text(uidComposite, SWT.SINGLE | SWT.READ_ONLY);
    uidText.setText(WorkbenchLoggingPlugin.getDefault().getLocalUser());
    uidText.addMouseListener(new MouseAdapter() {
        /* (non-Javadoc)
         * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
         */
        @Override
        public void mouseUp(MouseEvent e) {
            uidText.selectAll();
        }
    });
    MenuManager manager = new MenuManager();
    Menu menu = manager.createContextMenu(uidText);
    uidText.setMenu(menu);
    CommandContributionItemParameter parameters = new CommandContributionItemParameter(
            WorkbenchLoggingPlugin.getDefault().getWorkbench(), null, EDIT_COPY, SWT.PUSH);
    manager.add(new CommandContributionItem(parameters));
    return page;
}

From source file:ch.elexis.agenda.preferences.Tageseinteilung.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    Composite ret = new Composite(parent, SWT.NONE);
    ret.setLayout(new GridLayout());
    new Label(ret, SWT.None).setText(Messages.Tageseinteilung_enterPeriods);
    final Combo cbBereich = new Combo(ret, SWT.READ_ONLY | SWT.SINGLE);
    cbBereich.setItems(bereiche);/*from  w w  w.j a va  2 s. co m*/

    Composite grid = new Composite(ret, SWT.BORDER);
    grid.setLayout(new GridLayout(7, true));
    grid.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    new Label(grid, SWT.CENTER).setText(Messages.Tageseinteilung_mo);
    new Label(grid, SWT.CENTER).setText(Messages.Tageseinteilung_tu);
    new Label(grid, SWT.CENTER).setText(Messages.Tageseinteilung_we);
    new Label(grid, SWT.CENTER).setText(Messages.Tageseinteilung_th);
    new Label(grid, SWT.NONE).setText(Messages.Tageseinteilung_fr);
    new Label(grid, SWT.NONE).setText(Messages.Tageseinteilung_sa);
    new Label(grid, SWT.NONE).setText(Messages.Tageseinteilung_so);
    tMo = new Text(grid, SWT.BORDER | SWT.MULTI);
    tMo.setEnabled(false);
    tMo.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    originalBackgroundColor = tMo.getBackground();
    tDi = new Text(grid, SWT.BORDER | SWT.MULTI);
    tDi.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tDi.setEnabled(false);
    tMi = new Text(grid, SWT.BORDER | SWT.MULTI);
    tMi.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tMi.setEnabled(false);
    tDo = new Text(grid, SWT.BORDER | SWT.MULTI);
    tDo.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tDo.setEnabled(false);
    tFr = new Text(grid, SWT.BORDER | SWT.MULTI);
    tFr.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tFr.setEnabled(false);
    tSa = new Text(grid, SWT.BORDER | SWT.MULTI);
    tSa.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tSa.setEnabled(false);
    tSo = new Text(grid, SWT.BORDER | SWT.MULTI);
    tSo.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tSo.setEnabled(false);
    cbBereich.select(actBereich);

    Composite editDayComposite = new Composite(grid, SWT.None);
    editDayComposite.setLayoutData(SWTHelper.getFillGridData(7, true, 1, false));
    editDayComposite.setLayout(new GridLayout(3, false));

    btnEditValuesFor = new Button(editDayComposite, SWT.NONE);
    btnEditValuesFor.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            StructuredSelection ss = (StructuredSelection) comboViewerDayEditSelector.getSelection();
            editSelection = (DAYS) ss.getFirstElement();
            if (editSelection == null)
                return;

            Text[] days = new Text[] { tMo, tDi, tMi, tDo, tFr, tSa, tSo };
            for (Text text : days) {
                text.setEnabled(false);
                text.setBackground(originalBackgroundColor);
            }

            switch (editSelection) {
            case MONDAY:
                editSelectionText = tMo;
                break;
            case TUESDAY:
                editSelectionText = tDi;
                break;
            case FRIDAY:
                editSelectionText = tFr;
                break;
            case SATURDAY:
                editSelectionText = tSa;
                break;
            case SUNDAY:
                editSelectionText = tSo;
                break;
            case THURSDAY:
                editSelectionText = tDo;
                break;
            case WEDNESDAY:
                editSelectionText = tMi;
                break;
            default:
                break;
            }
            editSelectionText.setEnabled(true);
            editSelectionText
                    .setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_YELLOW));
            btnApplyEdit.setEnabled(true);
            dateTimeStartingFrom.setEnabled(true);
            editSelectionText.setFocus();
        }
    });
    btnEditValuesFor.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    btnEditValuesFor.setText(Messages.Tageseinteilung_lblEditValuesFor_text);

    comboViewerDayEditSelector = new ComboViewer(editDayComposite, SWT.NONE);
    Combo comboDayEditSelector = comboViewerDayEditSelector.getCombo();
    comboDayEditSelector.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    compositeEditStarting = new Composite(editDayComposite, SWT.NONE);
    compositeEditStarting.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    GridLayout gl_compositeEditStarting = new GridLayout(3, false);
    gl_compositeEditStarting.verticalSpacing = 0;
    gl_compositeEditStarting.marginHeight = 0;
    compositeEditStarting.setLayout(gl_compositeEditStarting);

    lblChangedValuesAre = new Label(compositeEditStarting, SWT.NONE);
    lblChangedValuesAre.setText(Messages.Tageseinteilung_lblChangedValuesAre_text);

    dateTimeStartingFrom = new DateTime(compositeEditStarting, SWT.BORDER);
    TimeTool tomorrow = new TimeTool();
    tomorrow.addDays(1);
    dateTimeStartingFrom.setDate(tomorrow.get(TimeTool.YEAR), tomorrow.get(TimeTool.MONTH),
            tomorrow.get(TimeTool.DAY_OF_MONTH));
    dateTimeStartingFrom.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            setErrorMessage(null);
            DateTime dt = (DateTime) e.getSource();
            int day = dateTimeStartingFrom.getDay(); // Calendar.DAY_OF_MONTH
            int month = dateTimeStartingFrom.getMonth(); // Calendar.MONTH
            int year = dateTimeStartingFrom.getYear(); // Calendar.YEAR
            String timeString = String.format("%02d", day) + "." + String.format("%02d", month + 1) + "."
                    + String.format("%04d", year);
            TimeTool tt = new TimeTool(timeString);
            if (tt.isBefore(new TimeTool())) {
                setErrorMessage(Messages.Tageseinteilung_no_past_Date);
                TimeTool tomorrow = new TimeTool();
                tomorrow.addDays(1);
                dateTimeStartingFrom.setDate(tomorrow.get(TimeTool.YEAR), tomorrow.get(TimeTool.MONTH),
                        tomorrow.get(TimeTool.DAY_OF_MONTH));
            }
        }
    });
    dateTimeStartingFrom.setEnabled(false);

    btnApplyEdit = new Button(compositeEditStarting, SWT.NONE);
    btnApplyEdit.setText(Messages.Tageseinteilung_btnNewButton_text);
    btnApplyEdit.setEnabled(false);
    btnApplyEdit.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // Apply the selected edits starting from the selected date
            int day = dateTimeStartingFrom.getDay(); // Calendar.DAY_OF_MONTH
            int month = dateTimeStartingFrom.getMonth(); // Calendar.MONTH
            int year = dateTimeStartingFrom.getYear(); // Calendar.YEAR
            String timeString = String.format("%02d", day) + "." + String.format("%02d", month + 1) + "."
                    + String.format("%04d", year);
            ProgressMonitorDialog pmd = new ProgressMonitorDialog(UiDesk.getTopShell());
            IRunnableWithProgress irp = new TermineLockedTimesUpdater(new TimeTool(timeString), editSelection,
                    editSelectionText.getText(), Termin.TerminBereiche[actBereich]);
            try {
                pmd.run(false, false, irp);
                editSelectionText.setBackground(originalBackgroundColor);
                editSelectionText.setEnabled(false);
            } catch (InvocationTargetException e1) {
                Status status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, "Execution Error", e1);
                StatusManager.getManager().handle(status, StatusManager.SHOW);
            } catch (InterruptedException e1) {
                Status status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, "Execution Error", e1);
                StatusManager.getManager().handle(status, StatusManager.SHOW);
            }

            dateTimeStartingFrom.setEnabled(false);
            btnApplyEdit.setEnabled(false);
        }
    });

    comboViewerDayEditSelector.setContentProvider(ArrayContentProvider.getInstance());
    comboViewerDayEditSelector.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            TimeTool.DAYS day = (TimeTool.DAYS) element;
            return day.fullName;
        }
    });
    TimeTool.DAYS[] days = TimeTool.DAYS.values();
    comboViewerDayEditSelector.setInput(days);
    comboViewerDayEditSelector.setSelection(new StructuredSelection(days[0]));

    compositeDayBorders = new Composite(ret, SWT.NONE);
    compositeDayBorders.setLayout(new GridLayout(2, false));

    Composite compositeStart = new Composite(compositeDayBorders, SWT.NONE);
    compositeStart.setLayout(new GridLayout(3, false));

    Label btnDayStartHourIsSet = new Label(compositeStart, SWT.CHECK);
    btnDayStartHourIsSet.setText(Messages.Tageseinteilung_btnCheckButton_text);

    sodt = new Text(compositeStart, SWT.BORDER);
    sodt.setTextLimit(4);

    Label lblHours = new Label(compositeStart, SWT.NONE);
    lblHours.setText(Messages.Tageseinteilung_lblHours_text);

    Composite compositeEnd = new Composite(compositeDayBorders, SWT.NONE);
    compositeEnd.setLayout(new GridLayout(3, false));

    Label btnEndStartHourIsSet = new Label(compositeEnd, SWT.CHECK);
    btnEndStartHourIsSet.setText(Messages.Tageseinteilung_btnCheckButton_text_1);

    eodt = new Text(compositeEnd, SWT.BORDER);
    eodt.setTextLimit(4);

    Label lblHours_1 = new Label(compositeEnd, SWT.NONE);
    lblHours_1.setText(Messages.Tageseinteilung_lblHours_1_text);

    reload();
    cbBereich.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int idx = cbBereich.getSelectionIndex();
            if (idx != -1) {
                save();
                actBereich = idx;
                reload();
            }
        }

    });
    return ret;
}

From source file:ch.elexis.base.messages.MsgDetailDialog.java

License:Open Source License

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

    Label lblMessageInfo = new Label(ret, SWT.NONE);
    lblMessageInfo.setLayoutData(SWTHelper.getFillGridData(4, true, 1, false));
    String msgLabel = (incomingMsg == null) ? new TimeTool().toString(TimeTool.FULL_GER)
            : new TimeTool(incomingMsg.get(Message.FLD_TIME)).toString(TimeTool.FULL_GER);
    lblMessageInfo.setText(Messages.MsgDetailDialog_messageDated + msgLabel);

    new Label(ret, SWT.NONE).setText(Messages.MsgDetailDialog_from);
    lblFrom = new Label(ret, SWT.NONE);

    new Label(ret, SWT.NONE).setText(Messages.MsgDetailDialog_to);
    cbTo = new ComboViewer(ret, SWT.SINGLE | SWT.READ_ONLY);
    cbTo.setContentProvider(ArrayContentProvider.getInstance());
    cbTo.setLabelProvider(new LabelProvider() {
        @Override/*from w w  w . j a  v a2  s.co  m*/
        public String getText(Object element) {
            Anwender anw = (Anwender) element;
            return anw.getLabel();
        }
    });
    cbTo.setInput(users);
    cbTo.setSelection(new StructuredSelection(users.get(0)));

    new Label(ret, SWT.SEPARATOR | SWT.HORIZONTAL).setLayoutData(SWTHelper.getFillGridData(4, true, 1, false));

    if (incomingMsg != null) {
        lblFrom.setText(incomingMsg.getSender().getLabel());
        Anwender sender = null;
        for (Anwender anwender : users) {
            if (incomingMsg.getDest().getId().equals(anwender.getId())) {
                sender = anwender;
                break;
            }
        }
        if (sender != null) {
            cbTo.setSelection(new StructuredSelection(sender));
        }

        cbTo.getCombo().setEnabled(false);

        new Label(ret, SWT.NONE).setText(Messages.MsgDetailDialog_message);
        Label lblIncomingMsg = new Label(ret, SWT.None);
        lblIncomingMsg.setLayoutData(SWTHelper.getFillGridData(3, true, 1, true));
        lblIncomingMsg.setText(incomingMsg.get(Message.FLD_TEXT));

        new Label(ret, SWT.NONE).setText(Messages.MsgDetailDialog_answer);
    } else {
        lblFrom.setText(CoreHub.actUser.getLabel());
        new Label(ret, SWT.NONE).setText(Messages.MsgDetailDialog_message);
    }

    txtMessage = SWTHelper.createText(ret, 1, SWT.BORDER);
    txtMessage.setLayoutData(SWTHelper.getFillGridData(3, true, 1, true));
    txtMessage.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (txtMessage.getText() != null && txtMessage.getText().length() > 0) {
                getShell().setDefaultButton(bAnswer);
            } else {
                getShell().setDefaultButton(bOK);
            }
        }
    });

    return ret;
}

From source file:ch.elexis.core.ui.contacts.controls.StammDatenComposite.java

License:Open Source License

public StammDatenComposite(Composite parent, int style) {
    super(parent, style);
    decorator = PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator();
    tdlp = new TableDecoratingLabelProvider(
            new ContactSelectorObservableMapLabelProvider(new ObservableMap[] {}), decorator);

    setLayout(new GridLayout(6, false));

    { // HEADER/* ww w.  ja  v  a2 s .  co m*/
        compositeHeader = new Composite(this, SWT.NONE);
        compositeHeader.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 6, 1));
        compositeHeader.setLayout(new GridLayout(3, false));

        lblContactType = new Label(compositeHeader, SWT.NONE);

        lblHeadline = new Label(compositeHeader, SWT.NONE);
        lblHeadline.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        lblCode = new Label(compositeHeader, SWT.NONE);
        GridData gd_lblCode = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
        gd_lblCode.widthHint = 40;
        lblCode.setLayoutData(gd_lblCode);
    }

    { // TYPE_PERSON - Title prefix
        txtTitleFront = new Text(this, SWT.BORDER);
        gd_txtTitleFront = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
        gd_txtTitleFront.widthHint = 60;
        txtTitleFront.setLayoutData(gd_txtTitleFront);
        txtTitleFront.setMessage("Titel");
        ContentProposalAdapter cpaTitleFront = new ContentProposalAdapter(txtTitleFront,
                new TextContentAdapter(),
                new TitleProposalProvider(TitleProposalProvider.TITLE_POSITION_PREFIX), null, null);
        cpaTitleFront.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    }

    txtFirstName = new Text(this, SWT.BORDER);
    txtFirstName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    txtFamilyName = new Text(this, SWT.BORDER);
    txtFamilyName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    { // TYPE_PERSON - Title back
        txtTitleBack = new Text(this, SWT.BORDER);
        gd_txtTitleBack = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
        gd_txtTitleBack.widthHint = 60;
        txtTitleBack.setLayoutData(gd_txtTitleBack);
        txtTitleBack.setMessage("Titel");
        ContentProposalAdapter cpaTitleBack = new ContentProposalAdapter(txtTitleBack, new TextContentAdapter(),
                new TitleProposalProvider(TitleProposalProvider.TITLE_POSITION_SUFFIX), null, null);
        cpaTitleBack.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    }

    { // TYPE_PERSON - Sex
        comboViewerSex = new ComboViewer(this, SWT.NONE);
        gd_comboSex = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
        comboViewerSex.getCombo().setLayoutData(gd_comboSex);
        comboViewerSex.setContentProvider(ArrayContentProvider.getInstance());
        comboViewerSex.setLabelProvider(new LabelProvider() {
            @Override
            public String getText(Object element) {
                switch ((ContactGender) element) {
                case FEMALE:
                    return "W";
                case MALE:
                    return "M";
                case UNDEFINED:
                    return "X";
                default:
                    return "?";
                }
            }
        });
        comboViewerSex.setInput(ContactGender.values());
    }
    { // TYPE_PERSON - Birthday
        dateTimeDob = new DateTime(this, SWT.BORDER | SWT.LONG);
        gd_dateTimeDob = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
        dateTimeDob.setLayoutData(gd_dateTimeDob);
    }

    Group grpAddress = new Group(this, SWT.NONE);
    grpAddress.setLayout(new GridLayout(3, false));
    grpAddress.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 7, 1));
    grpAddress.setText("Adresse");
    {
        // TODO: Default selection according to current Mandant's country
        comboViewerCountry = new ComboViewer(grpAddress, SWT.NONE);
        GridData gd_combo_1 = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
        gd_combo_1.widthHint = 55;
        comboViewerCountry.getCombo().setLayoutData(gd_combo_1);
        comboViewerCountry.setContentProvider(ArrayContentProvider.getInstance());
        comboViewerCountry.setInput(Country.values());
        comboViewerCountry.addSelectionChangedListener(new ISelectionChangedListener() {
            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                Country selCountry = (Country) ((StructuredSelection) event.getSelection()).getFirstElement();
                if (selCountry == Country.NDF) {
                    comboViewerCountry.getCombo()
                            .setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
                    ContactGeonames.setCountry(null);
                } else {
                    comboViewerCountry.getCombo()
                            .setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
                    ContactGeonames.setCountry(selCountry);
                }

            }
        });
    }
    {
        txtCity = new Text(grpAddress, SWT.BORDER);
        txtCity.setMessage("Ortschaft");
        txtCity.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        ContentProposalAdapter cpaCity = new ContentProposalAdapter(txtCity, new TextContentAdapter(), cityIP,
                null, null);
        cpaCity.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
        cpaCity.addContentProposalListener(new IContentProposalListener() {
            @Override
            public void proposalAccepted(IContentProposal proposal) {
                txtZIP.setText(cityIP.findZipForCityName(proposal.getContent()));
            }
        });
    }
    { // ZIP
        txtZIP = new Text(grpAddress, SWT.BORDER);
        txtZIP.setMessage("PLZ");
        txtZIP.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
        txtZIP.addModifyListener(new ModifyListener() {
            @Override
            public void modifyText(ModifyEvent e) {
                String currZip = ((Text) e.widget).getText();
                if (currZip == null || currZip.length() < 4)
                    return;
                streetIP.setZip(currZip);
            }
        });

        ContentProposalAdapter cpaZip = new ContentProposalAdapter(txtZIP, new TextContentAdapter(), zipIP,
                null, null);
        cpaZip.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
        cpaZip.addContentProposalListener(new IContentProposalListener() {
            @Override
            public void proposalAccepted(IContentProposal proposal) {
                txtCity.setText(zipIP.findCityNameForZip(proposal.getContent()));
            }
        });
    }

    Label lblImageCountry = new Label(grpAddress, SWT.NONE);
    GridData gd_lblImageCountry = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_lblImageCountry.widthHint = 55;
    lblImageCountry.setLayoutData(gd_lblImageCountry);

    {
        txtStreet = new Text(grpAddress, SWT.BORDER);
        txtStreet.setMessage("Strasse, Hausnummer");
        txtStreet.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

        ContentProposalAdapter cpaStreet = new ContentProposalAdapter(txtStreet, new TextContentAdapter(),
                streetIP, null, null);
        cpaStreet.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    }

    Group grpKontaktdaten = new Group(this, SWT.NONE);
    grpKontaktdaten.setText("Kontaktdaten");
    grpKontaktdaten.setLayout(new GridLayout(4, false));
    grpKontaktdaten.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 7, 1));

    Label lblImgPhone = new Label(grpKontaktdaten, SWT.NONE);
    lblImgPhone.setImage(Images.IMG_TELEPHONE.getImage());
    lblImgPhone.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    txtTelefon = new Text(grpKontaktdaten, SWT.BORDER);
    txtTelefon.setMessage("Telefon-Nummer");
    txtTelefon.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    txtTelefon.addFocusListener(preDialFocuListener);

    Label lblImgePhone2 = new Label(grpKontaktdaten, SWT.NONE);
    lblImgePhone2.setImage(Images.IMG_TELEPHONE.getImage());
    lblImgePhone2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    txtTelefon2 = new Text(grpKontaktdaten, SWT.BORDER);
    txtTelefon2.setMessage("Telefon-Nummer");
    txtTelefon2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    txtTelefon2.addFocusListener(preDialFocuListener);

    Label lblImgMobilePhone = new Label(grpKontaktdaten, SWT.NONE);
    lblImgMobilePhone.setImage(Images.IMG_MOBILEPHONE.getImage());
    lblImgMobilePhone.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    txtMobil = new Text(grpKontaktdaten, SWT.BORDER);
    txtMobil.setMessage("Handy-Nummer");
    txtMobil.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    txtMobil.addFocusListener(preDialFocuListener);

    Label lblImgFax = new Label(grpKontaktdaten, SWT.NONE);
    lblImgFax.setImage(Images.IMG_FAX.getImage());
    lblImgFax.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    txtFax = new Text(grpKontaktdaten, SWT.BORDER);
    txtFax.setMessage("Fax-Nummer");
    txtFax.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    txtFax.addFocusListener(preDialFocuListener);

    btnEmail = new Button(grpKontaktdaten, SWT.FLAT);
    btnEmail.setImage(Images.IMG_MAIL.getImage());
    btnEmail.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    btnEmail.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                URI uriMailTo = new URI("mailto", txtEmail.getText(), null);
                Desktop.getDesktop().mail(uriMailTo);
            } catch (URISyntaxException | IOException ex) {
                log.warn("Error opening URI", ex);
            }
        }
    });

    txtEmail = new Text(grpKontaktdaten, SWT.BORDER);
    txtEmail.setMessage("E-Mail Adresse");
    txtEmail.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    btnWebsite = new Button(grpKontaktdaten, SWT.FLAT);
    btnWebsite.setImage(Images.IMG_WEB.getImage());
    btnWebsite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    btnWebsite.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                URI uriURL = new URI(txtWebsite.getText());
                if (!uriURL.isAbsolute()) {
                    uriURL = new URI("http://" + txtWebsite.getText());
                }
                Desktop.getDesktop().browse(uriURL);
            } catch (URISyntaxException | IOException ex) {
                log.warn("Error opening URI", ex);
            }
        }
    });

    txtWebsite = new Text(grpKontaktdaten, SWT.BORDER);
    txtWebsite.setMessage("Webseite");
    txtWebsite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    { // Notes
        Group grpNotes = new Group(this, SWT.NONE);
        grpNotes.setLayout(new GridLayout(1, false));
        grpNotes.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 7, 1));
        grpNotes.setText("Notizen");
        txtNotes = new Text(grpNotes, SWT.V_SCROLL | SWT.WRAP);
        GridData gd_txtNotes = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
        gd_txtNotes.heightHint = (int) (5 * txtNotes.getFont().getFontData()[0].height);
        txtNotes.setLayoutData(gd_txtNotes);
    }

    initDataBindings();
}

From source file:ch.elexis.core.ui.contacts.dialogs.AdvancedFilterDialog.java

License:Open Source License

/**
 * Create contents of the dialog./*from w  w  w. j ava2 s.co m*/
 * 
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    setMessage("Konfiguration des erweiterten Filters");
    setTitle("Erweiterter Filter");
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    Label lblGespeichertenFilterLaden = new Label(container, SWT.NONE);
    lblGespeichertenFilterLaden.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblGespeichertenFilterLaden.setText("Gespeicherten Filter laden");

    ComboViewer comboViewer = new ComboViewer(container, SWT.NONE);
    Combo combo = comboViewer.getCombo();
    combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblNewLabel = new Label(container, SWT.NONE);
    lblNewLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));

    Button btnFilterSticker = new Button(container, SWT.CHECK);
    btnFilterSticker.setText("nach Sticker filtern");
    new Label(container, SWT.NONE);

    Button btnFilterField = new Button(container, SWT.CHECK);
    btnFilterField.setText("nach Feldwerten filtern");
    new Label(container, SWT.NONE);

    Button btnBtnfilterproperties = new Button(container, SWT.CHECK);
    btnBtnfilterproperties.setText("nach Eigenschaften filtern");
    new Label(container, SWT.NONE);

    Label lblNewLabel_1 = new Label(container, SWT.NONE);
    lblNewLabel_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));

    Label lblFilterSpeichernAls = new Label(container, SWT.NONE);
    lblFilterSpeichernAls.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblFilterSpeichernAls.setText("Filter speichern als");

    text = new Text(container, SWT.BORDER);
    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    return area;
}

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

License:Open Source License

@Override
protected Control createDialogArea(final Composite parent) {
    Composite ret = new Composite(parent, SWT.NONE);
    ret.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    ret.setLayout(new GridLayout(4, false));
    cbMarked = new Button(ret, SWT.CHECK);
    cbMarked.setText(ALLMARKED);//from w w  w  .  j  a v  a  2 s.com
    cbMarked.setLayoutData(SWTHelper.getFillGridData(4, true, 1, false));
    cbBefore = new Button(ret, SWT.CHECK);
    cbBefore.setText(TREATMENTBEGINBEFORE);
    ddc1 = new DayDateCombo(ret, "", TAGEN_BZW_DEM); //$NON-NLS-1$
    ddc1.spinDaysBack();
    cbTime = new Button(ret, SWT.CHECK);
    cbTime.setText(TREATMENTENDBEFORE);

    ddc2 = new DayDateCombo(ret, "", TAGEN_BZW_DEM); //$NON-NLS-1$
    ddc2.spinDaysBack();
    int prev = CoreHub.localCfg.get(CONFIG + "beginBefore", 30) * -1; //$NON-NLS-1$
    TimeTool ttNow = new TimeTool();
    ttNow.addDays(prev);
    ddc1.setDays(prev);

    prev = CoreHub.localCfg.get(CONFIG + "endBefore", 20) * -1; //$NON-NLS-1$
    ddc2.setDays(prev);
    ddc1.setLayoutData(SWTHelper.getFillGridData(3, true, 1, false));

    ddc2.setLayoutData(SWTHelper.getFillGridData(3, true, 1, false));
    cbAmount = new Button(ret, SWT.CHECK);
    cbAmount.setText(TREATMENT_AMOUNTHIGHER);
    mi1 = new MoneyInput(ret);
    mi1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
    mi1.setLayoutData(SWTHelper.getFillGridData(3, true, 1, false));

    cbQuartal = new Button(ret, SWT.CHECK);
    cbQuartal.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
    cbQuartal.setText(TREATMENT_TRIMESTER);

    cbTimespan = new Button(ret, SWT.CHECK);
    cbTimespan.setText(TREATMENT_TIMESPAN);
    timespanFrom = new DateTime(ret, SWT.NONE);
    Label lblTill = new Label(ret, SWT.NONE);
    lblTill.setText(TREATMENT_TIMESPAN_TILL);
    timespanTo = new DateTime(ret, SWT.NONE);
    cbTimespan.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            timespanFrom.setEnabled(cbTimespan.getSelection());
            timespanTo.setEnabled(cbTimespan.getSelection());
        }
    });

    cbAccountingSys = new Button(ret, SWT.CHECK);
    cbAccountingSys.setText(TREATMENT_ACCOUNTING_SYS);
    cbAccountingSys.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            cAccountingSys.getCombo().setEnabled(cbAccountingSys.getSelection());
        }
    });
    cAccountingSys = new ComboViewer(ret, SWT.NONE);
    Combo combo = cAccountingSys.getCombo();
    combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
    cAccountingSys.setContentProvider(ArrayContentProvider.getInstance());
    cAccountingSys.setLabelProvider(new LabelProvider());
    String[] accSystems = Fall.getAbrechnungsSysteme();
    cAccountingSys.setInput(accSystems);
    cAccountingSys.setSelection(new StructuredSelection(accSystems[0]));

    new Label(ret, SWT.NONE);
    new Label(ret, SWT.NONE);
    new Label(ret, SWT.NONE);
    new Label(ret, SWT.NONE);
    new Label(ret, SWT.NONE);
    new Label(ret, SWT.NONE);
    new Label(ret, SWT.NONE);
    new Label(ret, SWT.NONE);
    new Label(ret, SWT.SEPARATOR | SWT.HORIZONTAL).setLayoutData(SWTHelper.getFillGridData(4, true, 1, false));
    cbSkip = new Button(ret, SWT.CHECK);
    cbSkip.setText(SKIPSELECTION);
    cbSkip.setSelection(CoreHub.globalCfg.get(CFG_SKIP, false));
    cbBefore.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            ddc1.setEnabled(cbBefore.getSelection());
        }

    });
    cbTime.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            ddc2.setEnabled(cbTime.getSelection());
        }

    });

    cAccountingSys.getCombo().setEnabled(false);
    timespanFrom.setEnabled(false);
    timespanTo.setEnabled(false);
    ddc1.setEnabled(false);
    ddc2.setEnabled(false);
    new Label(ret, SWT.NONE);
    new Label(ret, SWT.NONE);
    new Label(ret, SWT.NONE);
    return ret;
}

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

License:Open Source License

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

    Composite compAddressType = new Composite(com, SWT.NONE);
    compAddressType.setLayoutData(SWTHelper.getFillGridData(2, true, 1, true));
    compAddressType.setLayout(new GridLayout(2, false));
    Label lblAddressType = new Label(compAddressType, SWT.NONE);
    lblAddressType.setText("Type");
    comboAddressType = new ComboViewer(compAddressType, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
    comboAddressType.setContentProvider(ArrayContentProvider.getInstance());
    comboAddressType.setLabelProvider(new LabelProvider() {
        @Override// ww  w  . ja  va 2  s. com
        public String getText(Object element) {
            return LocalizeUtil.getLocaleText((AddressType) element);
        }
    });
    List<AddressType> comboValues = new ArrayList<>(Arrays.asList(AddressType.values()));
    comboValues.remove(AddressType.PRINCIPAL_RESIDENCE); //principal residence is defined within patient - contact relation
    comboAddressType.setInput(comboValues);

    Label l1 = new Label(com, SWT.NONE);
    l1.setText(Messages.AnschriftEingabeDialog_street + "1"); //$NON-NLS-1$
    str1 = new Text(com, SWT.BORDER);

    str1.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));

    l1 = new Label(com, SWT.NONE);
    l1.setText(Messages.AnschriftEingabeDialog_street + "2"); //$NON-NLS-1$
    str2 = new Text(com, SWT.BORDER);

    str2.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));

    Label l2 = new Label(com, SWT.NONE);
    l2.setText(Messages.AnschriftEingabeDialog_zip); //$NON-NLS-1$
    plz = new Text(com, SWT.BORDER);

    plz.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
    Label l3 = new Label(com, SWT.NONE);
    l3.setText(Messages.AnschriftEingabeDialog_city); //$NON-NLS-1$
    ort = new Text(com, SWT.BORDER);

    ort.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
    Label l4 = new Label(com, SWT.NONE);
    l4.setText(Messages.AnschriftEingabeDialog_country); //$NON-NLS-1$
    land = new Text(com, SWT.BORDER);

    land.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));

    Button post = new Button(com, SWT.PUSH);
    post.setText(Messages.AnschriftEingabeDialog_postalAddress); //$NON-NLS-1$
    post.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setFieldValues();
            Kontakt kontakt = Kontakt.load(zusatzAdresseDTO.getKontaktId());
            zusatzAdresseDTO.setPostalAddress(kontakt.getSalutation() + zusatzAdresse.getEtikette(false, true,
                    zusatzAdresseDTO.getKontaktId(), zusatzAdresseDTO.getStreet1(),
                    zusatzAdresseDTO.getCountry(), zusatzAdresseDTO.getZip(), zusatzAdresseDTO.getPlace()));
            loadFieldValues();
        }
    });

    postanschrift = new Text(com, SWT.MULTI | SWT.BORDER);
    GridData gd = SWTHelper.getFillGridData(1, true, 1, true);
    // at least 3 lines height
    Point size = postanschrift.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd.heightHint = 4 * size.y;
    postanschrift.setLayoutData(gd);

    // postanschrift info message
    new Label(com, SWT.NONE); // filler
    Label l5 = new Label(com, SWT.NONE);
    l5.setText(Messages.AnschriftEingabeDialog_postalAddressInfo); //$NON-NLS-1$
    l5.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));

    loadFieldValues();
    return com;
}

From source file:ch.elexis.core.ui.documents.views.DocumentsMetaDataDialog.java

License:Open Source License

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

    new Label(ret, SWT.None).setText(Messages.DocumentView_categoryColumn);
    Composite cCats = new Composite(ret, SWT.NONE);
    cCats.setFocus();//from  ww w .j  a  v a 2  s . c  om
    cCats.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
    cCats.setLayout(new RowLayout(SWT.HORIZONTAL));
    cbCategories = new ComboViewer(cCats, SWT.SINGLE | SWT.READ_ONLY);
    cbCategories.setContentProvider(ArrayContentProvider.getInstance());
    cbCategories.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof ICategory) {
                ICategory iCategory = (ICategory) element;
                return iCategory.getName();
            }
            return super.getText(element);
        }
    });
    List<ICategory> categories = DocumentStoreServiceHolder.getService().getCategories(document);
    cbCategories.setInput(categories);

    Button bNewCat = new Button(cCats, SWT.PUSH);
    bNewCat.setVisible(categoryCrudAllowed);
    bNewCat.setImage(Images.IMG_NEW.getImage());
    bNewCat.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            InputDialog id = new InputDialog(getShell(), Messages.DocumentMetaDataDialog_newCategory,
                    Messages.DocumentMetaDataDialog_newCategory, null, null);
            if (id.open() == Dialog.OK) {
                document.setCategory(
                        DocumentStoreServiceHolder.getService().createCategory(document, id.getValue()));
                if (!((List<?>) cbCategories.getInput()).contains(document.getCategory())) {
                    cbCategories.add(document.getCategory());
                }
                cbCategories.setSelection(new StructuredSelection(document.getCategory()), true);
            }
        }
    });
    Button bEditCat = new Button(cCats, SWT.PUSH);
    bEditCat.setImage(Images.IMG_EDIT.getImage());
    bEditCat.setVisible(categoryCrudAllowed);
    bEditCat.setToolTipText(Messages.DocumentMetaDataDialog_renameCategory);
    bEditCat.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection old = cbCategories.getSelection();
            Object selection = ((StructuredSelection) old).getFirstElement();
            if (selection instanceof ICategory) {
                InputDialog id = new InputDialog(getShell(),
                        MessageFormat.format(Messages.DocumentMetaDataDialog_renameCategoryConfirm,
                                ((ICategory) selection).getName()),
                        Messages.DocumentMetaDataDialog_renameCategoryText, ((ICategory) selection).getName(),
                        null);
                if (id.open() == Dialog.OK) {
                    DocumentStoreServiceHolder.getService().renameCategory(document, id.getValue());
                    ((ICategory) selection).setName(id.getValue());
                    cbCategories.refresh();
                }
            }

        }
    });

    Button bDeleteCat = new Button(cCats, SWT.PUSH);
    bDeleteCat.setVisible(categoryCrudAllowed);
    bDeleteCat.setImage(Images.IMG_DELETE.getImage());
    bDeleteCat.setToolTipText(Messages.DocumentMetaDataDialog_deleteCategory);
    bDeleteCat.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent ev) {
            ISelection old = cbCategories.getSelection();
            Object selection = ((StructuredSelection) old).getFirstElement();
            InputDialog id = new InputDialog(getShell(),
                    MessageFormat.format(Messages.DocumentMetaDataDialog_deleteCategoryConfirm,
                            ((ICategory) selection).getName()),
                    Messages.DocumentMetaDataDialog_deleteCategoryText, "", null);
            if (id.open() == Dialog.OK) {
                try {
                    document.setCategory((ICategory) selection);
                    document.setCategory(
                            DocumentStoreServiceHolder.getService().removeCategory(document, id.getValue()));
                    if (findComboElementByName(document.getCategory().getName()) == null) {
                        cbCategories.add(document.getCategory());
                    }
                    cbCategories.remove(selection);
                    cbCategories.setSelection(new StructuredSelection(document.getCategory()), true);
                } catch (ElexisException e) {
                    logger.warn("existing document references", e);
                    SWTHelper.showError(Messages.DocumentMetaDataDialog_deleteCategoryError,
                            Messages.DocumentMetaDataDialog_deleteCategoryErrorText);
                }
            }
        }
    });
    new Label(ret, SWT.NONE).setText(Messages.DocumentsView_Title);
    tTitle = SWTHelper.createText(ret, 1, SWT.NONE);
    new Label(ret, SWT.NONE).setText(Messages.DocumentView_keywordsColumn);
    tKeywords = SWTHelper.createText(ret, 4, SWT.NONE);
    tKeywords.setEnabled(keywordsCrudAllowed);
    tTitle.setText(document.getTitle());

    tKeywords.setText(document.getKeywords());
    Object cbSelection = document.getCategory() != null ? document.getCategory() : cbCategories.getElementAt(0);
    if (cbSelection != null) {
        if (!categories.contains(cbSelection)) {
            cbSelection = DocumentStoreServiceHolder.getService().getDefaultCategory(document);
        }
        cbCategories.setSelection(new StructuredSelection(cbSelection), true);

    }
    return ret;
}

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;//from w w w . j a  v  a 2  s.  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() {
        @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;
}