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

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

Introduction

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

Prototype

public StructuredSelection(List elements) 

Source Link

Document

Creates a structured selection from the given List.

Usage

From source file:carisma.ocl.library.presentation.LibraryEditor.java

License:Open Source License

/**
 * This accesses a cached version of the content outliner.
 * <!-- begin-user-doc -->/* www.  j a v a  2 s . co  m*/
 * <!-- end-user-doc -->
 * @generated
 */
public IContentOutlinePage getContentOutlinePage() {
    if (this.contentOutlinePage == null) {
        // The content outline is just a tree.
        //
        class MyContentOutlinePage extends ContentOutlinePage {
            @Override
            public void createControl(Composite parent) {
                super.createControl(parent);
                LibraryEditor.this.contentOutlineViewer = getTreeViewer();
                LibraryEditor.this.contentOutlineViewer.addSelectionChangedListener(this);

                // Set up the tree viewer.
                //
                LibraryEditor.this.contentOutlineViewer.setContentProvider(
                        new AdapterFactoryContentProvider(LibraryEditor.this.adapterFactory));
                LibraryEditor.this.contentOutlineViewer
                        .setLabelProvider(new AdapterFactoryLabelProvider(LibraryEditor.this.adapterFactory));
                LibraryEditor.this.contentOutlineViewer
                        .setInput(LibraryEditor.this.editingDomain.getResourceSet());

                // Make sure our popups work.
                //
                createContextMenuFor(LibraryEditor.this.contentOutlineViewer);

                if (!LibraryEditor.this.editingDomain.getResourceSet().getResources().isEmpty()) {
                    // Select the root object in the view.
                    //
                    LibraryEditor.this.contentOutlineViewer.setSelection(
                            new StructuredSelection(
                                    LibraryEditor.this.editingDomain.getResourceSet().getResources().get(0)),
                            true);
                }
            }

            @Override
            public void makeContributions(IMenuManager menuManager, IToolBarManager toolBarManager,
                    IStatusLineManager statusLineManager) {
                super.makeContributions(menuManager, toolBarManager, statusLineManager);
                LibraryEditor.this.contentOutlineStatusLineManager = statusLineManager;
            }

            @Override
            public void setActionBars(IActionBars actionBars) {
                super.setActionBars(actionBars);
                getActionBarContributor().shareGlobalActions(this, actionBars);
            }
        }

        this.contentOutlinePage = new MyContentOutlinePage();

        // Listen to selection so that we can handle it is a special way.
        //
        this.contentOutlinePage.addSelectionChangedListener(new ISelectionChangedListener() {
            // This ensures that we handle selections correctly.
            //
            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                handleContentOutlineSelection(event.getSelection());
            }
        });
    }

    return this.contentOutlinePage;
}

From source file:carisma.ocl.library.presentation.LibraryModelWizard.java

License:Open Source License

/**
 * Do the work after everything is specified.
 * <!-- begin-user-doc -->/*  ww w. ja v  a  2  s.co m*/
 * <!-- end-user-doc -->
 * @generated not
 */
@Override
public boolean performFinish() {
    try {
        // Remember the file.
        //
        final IFile modelFile = getModelFile();

        // Do the work within an operation.
        //
        WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
            @Override
            protected void execute(IProgressMonitor progressMonitor) {
                try {
                    // Create a resource set
                    //
                    ResourceSet resourceSet = new ResourceSetImpl();

                    // Get the URI of the model file.
                    //
                    URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);

                    // Create a resource for this file.
                    //
                    Resource resource = resourceSet.createResource(fileURI);

                    // Add the initial model object to the contents.
                    //
                    EObject rootObject = createInitialModel();
                    if (rootObject != null) {
                        resource.getContents().add(rootObject);
                    }

                    // Save the contents of the resource to the file system.
                    //
                    Map<Object, Object> options = new HashMap<>();

                    /** Define Encoding manually */
                    //options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
                    options.put(XMLResource.OPTION_ENCODING, "UTF-8");

                    resource.save(options);
                } catch (Exception exception) {
                    OclEditorPlugin.INSTANCE.log(exception);
                } finally {
                    progressMonitor.done();
                }
            }
        };

        getContainer().run(false, false, operation);

        // Select the new file resource in the current view.
        //
        IWorkbenchWindow workbenchWindow = this.iWorkbench.getActiveWorkbenchWindow();
        IWorkbenchPage page = workbenchWindow.getActivePage();
        final IWorkbenchPart activePart = page.getActivePart();
        if (activePart instanceof ISetSelectionTarget) {
            final ISelection targetSelection = new StructuredSelection(modelFile);
            getShell().getDisplay().asyncExec(new Runnable() {
                @Override
                public void run() {
                    ((ISetSelectionTarget) activePart).selectReveal(targetSelection);
                }
            });
        }

        // Open an editor on the new file.
        //
        try {
            page.openEditor(new FileEditorInput(modelFile), this.iWorkbench.getEditorRegistry()
                    .getDefaultEditor(modelFile.getFullPath().toString()).getId());
        } catch (PartInitException exception) {
            MessageDialog.openError(workbenchWindow.getShell(),
                    OclEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
            return false;
        }

        return true;
    } catch (Exception exception) {
        OclEditorPlugin.INSTANCE.log(exception);
        return false;
    }
}

From source file:cc.frz.ecl.openproject.OpenProjectAction.java

License:Open Source License

public void run(IAction action) {
    OpenProjectDialog openProjectDialog = new OpenProjectDialog(Display.getCurrent().getActiveShell());
    if (openProjectDialog.open() != IDialogConstants.OK_ID)
        return;//  w  ww .j a  v  a  2s  .c o  m

    Object[] res = openProjectDialog.getResult();
    if (res.length == 0) {
        return;
    }

    // find the explorers (!)
    // HACK THE PLANET (!)

    List<ISetSelectionTarget> nav = new ArrayList<ISetSelectionTarget>();
    int openViews = 0;
    IWorkbench workbench = Activator.getDefault().getWorkbench();

    for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
        for (IWorkbenchPage page : window.getPages()) {
            for (IViewReference reference : page.getViewReferences()) {
                IWorkbenchPart part = reference.getPart(false);

                if (part != null) {
                    for (Class<?> view : knownViews) {
                        if (view.isAssignableFrom(part.getClass())) {
                            nav.add((ISetSelectionTarget) part);
                            if (page.isPartVisible(part)) {
                                openViews++;
                            }
                        }
                    }
                }
            }
        }
    }

    if (openViews == 0) { // try to open the package explorer
        try {
            nav.add((ISetSelectionTarget) workbench.getActiveWorkbenchWindow().getActivePage()
                    .showView("org.eclipse.jdt.ui.PackageExplorer"));
        } catch (PartInitException e) {
            // didn't work, try the project explorer
            try {
                nav.add((ISetSelectionTarget) workbench.getActiveWorkbenchWindow().getActivePage()
                        .showView("org.eclipse.ui.navigator.ProjectExplorer"));
            } catch (PartInitException e1) {
                // give up
            }
        }
    }
    for (ISetSelectionTarget setSelectionTarget : nav) {
        setSelectionTarget.selectReveal(new StructuredSelection(res[0]));
    }
}

From source file:ccw.editors.outline.ClojureOutlinePage.java

License:Open Source License

/**
 * Find closest matching element to line
 * //w  w w  .ja  va  2  s  .com
 * @param toFind
 *            line to find
 * @return
 */
protected StructuredSelection findClosest(int toFind) {
    Object selected = null;
    for (Object o : forms) {
        if (o instanceof Obj) {
            Obj obj = (Obj) o;
            int lineNr = getLineNr(obj);
            if (lineNr >= 0 && lineNr <= toFind) {
                selected = obj;
            }

        }
    }
    if (selected != null) {
        return new StructuredSelection(selected);
    }
    return StructuredSelection.EMPTY;
}

From source file:ccw.preferences.SyntaxColoringPreferencePage.java

License:Open Source License

private Control createSyntaxPage(final Composite parent) {
    fOverlayStore.load();/*from ww w  .  j av  a  2s .c o m*/
    fOverlayStore.start();

    Composite colorComposite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    colorComposite.setLayout(layout);

    Link link = new Link(colorComposite, SWT.NONE);
    link.setText(Messages.SyntaxColoringPreferencePage_link);
    link.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null);
        }
    });
    // TODO replace by link-specific tooltips when
    // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=88866 gets fixed
    //      link.setToolTipText(Messages.JavaEditorColoringConfigurationBlock_link_tooltip);

    GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    gridData.widthHint = 150; // only expand further if anyone else requires it
    gridData.horizontalSpan = 2;
    link.setLayoutData(gridData);

    Label label;
    label = new Label(colorComposite, SWT.LEFT);
    label.setText(Messages.SyntaxColoringPreferencePage_coloring_element);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Composite editorComposite = new Composite(colorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    editorComposite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    editorComposite.setLayoutData(gd);

    fListViewer = new ListViewer(editorComposite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    fListViewer.setLabelProvider(new ColorListLabelProvider());
    fListViewer.setContentProvider(new ColorListContentProvider());
    fListViewer.setInput(fListModel);

    gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true);
    gd.heightHint = convertHeightInCharsToPixels(30);
    int maxWidth = 0;
    for (Iterator<HighlightingColorListItem> it = fListModel.iterator(); it.hasNext();) {
        HighlightingColorListItem item = it.next();
        maxWidth = Math.max(maxWidth, convertWidthInCharsToPixels(item.getDisplayName().length()));
    }
    ScrollBar vBar = ((Scrollable) fListViewer.getControl()).getVerticalBar();
    if (vBar != null)
        maxWidth += vBar.getSize().x * 3; // scrollbars and tree indentation guess
    gd.widthHint = maxWidth;

    fListViewer.getControl().setLayoutData(gd);

    Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    stylesComposite.setLayout(layout);
    stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));

    fEnableCheckbox = new Button(stylesComposite, SWT.CHECK);
    fEnableCheckbox.setText(Messages.SyntaxColoringPreferencePage_enable);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    fEnableCheckbox.setLayoutData(gd);

    fColorEditorLabel = new Label(stylesComposite, SWT.LEFT);
    fColorEditorLabel.setText(Messages.SyntaxColoringPreferencePage_color);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    fColorEditorLabel.setLayoutData(gd);

    fSyntaxForegroundColorEditor = new ColorSelector(stylesComposite);
    Button foregroundColorButton = fSyntaxForegroundColorEditor.getButton();
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    foregroundColorButton.setLayoutData(gd);

    fBoldCheckBox = new Button(stylesComposite, SWT.CHECK);
    fBoldCheckBox.setText(Messages.SyntaxColoringPreferencePage_bold);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    gd.horizontalSpan = 2;
    fBoldCheckBox.setLayoutData(gd);

    fItalicCheckBox = new Button(stylesComposite, SWT.CHECK);
    fItalicCheckBox.setText(Messages.SyntaxColoringPreferencePage_italic);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    gd.horizontalSpan = 2;
    fItalicCheckBox.setLayoutData(gd);

    /* TODO enable once text attributes are used
    fStrikethroughCheckBox= new Button(stylesComposite, SWT.CHECK);
    fStrikethroughCheckBox.setText(Messages.SyntaxColoringPreferencePage_strikethrough);
    gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent= 20;
    gd.horizontalSpan= 2;
    fStrikethroughCheckBox.setLayoutData(gd);
            
    fUnderlineCheckBox= new Button(stylesComposite, SWT.CHECK);
    fUnderlineCheckBox.setText(Messages.SyntaxColoringPreferencePage_underline);
    gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent= 20;
    gd.horizontalSpan= 2;
    fUnderlineCheckBox.setLayoutData(gd);
    */

    label = new Label(colorComposite, SWT.LEFT);
    label.setText(Messages.SyntaxColoringPreferencePage_preview);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Control previewer = createPreviewer(colorComposite);
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = convertWidthInCharsToPixels(20);
    gd.heightHint = convertHeightInCharsToPixels(5);
    previewer.setLayoutData(gd);

    fListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            handleSyntaxColorListSelection();
        }
    });

    foregroundColorButton.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
        }

        public void widgetSelected(SelectionEvent e) {
            HighlightingColorListItem item = getHighlightingColorListItem();
            // TODO: remove this ? PreferenceConverter.setValue(getPreferenceStore(), item.getColorKey(), fSyntaxForegroundColorEditor.getColorValue());
            PreferenceConverter.setValue(fOverlayStore, item.getColorKey(),
                    fSyntaxForegroundColorEditor.getColorValue());
        }
    });

    fBoldCheckBox.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
        }

        public void widgetSelected(SelectionEvent e) {
            HighlightingColorListItem item = getHighlightingColorListItem();
            fOverlayStore.setValue(item.getBoldKey(), fBoldCheckBox.getSelection());
        }
    });

    fItalicCheckBox.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
        }

        public void widgetSelected(SelectionEvent e) {
            HighlightingColorListItem item = getHighlightingColorListItem();
            fOverlayStore.setValue(item.getItalicKey(), fItalicCheckBox.getSelection());
        }
    });
    /*        
    fStrikethroughCheckBox.addSelectionListener(new SelectionListener() {
    public void widgetDefaultSelected(SelectionEvent e) {
        // do nothing
    }
    public void widgetSelected(SelectionEvent e) {
        HighlightingColorListItem item= getHighlightingColorListItem();
        fOverlayStore.setValue(item.getStrikethroughKey(), fStrikethroughCheckBox.getSelection());
    }
    });
    fUnderlineCheckBox.addSelectionListener(new SelectionListener() {
    public void widgetDefaultSelected(SelectionEvent e) {
        // do nothing
    }
    public void widgetSelected(SelectionEvent e) {
        HighlightingColorListItem item= getHighlightingColorListItem();
        fOverlayStore.setValue(item.getUnderlineKey(), fUnderlineCheckBox.getSelection());
    }
    });
    */

    fEnableCheckbox.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
        }

        public void widgetSelected(SelectionEvent e) {
            HighlightingColorListItem item = getHighlightingColorListItem();
            boolean enable = fEnableCheckbox.getSelection();
            fOverlayStore.setValue(item.getEnableKey(), enable);
            fEnableCheckbox.setSelection(enable);
            fSyntaxForegroundColorEditor.getButton().setEnabled(enable);
            fColorEditorLabel.setEnabled(enable);
            fBoldCheckBox.setEnabled(enable);
            fItalicCheckBox.setEnabled(enable);
            /* TODO re-enable once text attributes are used
            fStrikethroughCheckBox.setEnabled(enable);
            fUnderlineCheckBox.setEnabled(enable);
            */
        }
    });

    colorComposite.layout(false);

    fListViewer.setSelection(new StructuredSelection(fListModel.get(0)));

    return colorComposite;
}

From source file:cg.editor.propertysheet.PropertySheetViewer.java

License:Open Source License

/**
 * The <code>PropertySheetViewer</code> implementation of this
 * <code>ISelectionProvider</code> method returns the result as a
 * <code>StructuredSelection</code>.
 * <p>//w  w w  .j a va 2  s  . co  m
 * Note that this method only includes <code>IPropertySheetEntry</code> in
 * the selection (no categories).
 * </p>
 */
public ISelection getSelection() {
    if (tree.getSelectionCount() == 0) {
        return StructuredSelection.EMPTY;
    }
    TreeItem[] sel = tree.getSelection();
    List<IPropertySheetEntry> entries = new ArrayList<IPropertySheetEntry>(sel.length);
    for (int i = 0; i < sel.length; i++) {
        TreeItem ti = sel[i];
        Object data = ti.getData();
        if (data instanceof IPropertySheetEntry) {
            entries.add((IPropertySheetEntry) data);
        }
    }
    return new StructuredSelection(entries);
}

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  2s  . c om*/

    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 a 2 s.  c om
        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.findings.ui.views.nattable.NatTableWrapper.java

License:Open Source License

public void configure() {
    natTable.addLayerListener(new ILayerListener() {
        @SuppressWarnings("unchecked")
        @Override/*from   w  w  w .  j  av a 2 s.co  m*/
        public void handleLayerEvent(ILayerEvent event) {
            if (event instanceof CellSelectionEvent) {
                currentSelection.clear();
                CellSelectionEvent cellEvent = (CellSelectionEvent) event;
                Collection<ILayerCell> cells = cellEvent.getSelectionLayer().getSelectedCells();
                for (ILayerCell iLayerCell : cells) {
                    Object selectedObj = dataProvider.getDataValue(iLayerCell.getColumnIndex(),
                            iLayerCell.getRowIndex());
                    if (selectedObj instanceof List) {
                        currentSelection.addAll((List) selectedObj);
                    }
                }
                // call listeners
                Object[] listeners = selectionListener.getListeners();
                for (Object object : listeners) {
                    ((ISelectionChangedListener) object).selectionChanged(new SelectionChangedEvent(
                            NatTableWrapper.this, new StructuredSelection(currentSelection)));
                }
            }
        }
    });

    natTable.addConfiguration(new AbstractUiBindingConfiguration() {
        @Override
        public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
            uiBindingRegistry.registerDoubleClickBinding(
                    new MouseEventMatcher(SWT.NONE, GridRegion.BODY, MouseEventMatcher.LEFT_BUTTON),
                    new DblClickMouseAction());
        }

        class DblClickMouseAction implements IMouseAction {
            @Override
            public void run(NatTable natTable, MouseEvent event) {
                if (currentSelection != null) {
                    Object[] listeners = doubleClickListeners.getListeners();
                    for (Object object : listeners) {
                        ((IDoubleClickListener) object).doubleClick(NatTableWrapper.this, getSelection());
                    }
                }
            }
        }
    });
    natTable.configure();
}

From source file:ch.elexis.core.findings.ui.views.nattable.NatTableWrapper.java

License:Open Source License

@Override
public ISelection getSelection() {
    if (!currentSelection.isEmpty()) {
        return new StructuredSelection(currentSelection);
    }//  ww w  .j av a  2  s .c  o m
    return StructuredSelection.EMPTY;
}