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

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

Introduction

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

Prototype

public Combo getCombo() 

Source Link

Document

Returns this list viewer's list control.

Usage

From source file:org.kalypso.ui.wizard.sensor.ImportObservationSelectionWizardPage.java

License:Open Source License

public void createControlSource(final Composite parent) {
    final Group group = new Group(parent, SWT.NONE);
    group.setLayout(new GridLayout(3, false));
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    group.setText(Messages.getString("org.kalypso.ui.wizard.sensor.ImportObservationSelectionWizardPage2")); //$NON-NLS-1$

    // line 1/*from   ww  w. j av a 2  s.co m*/
    final Label label = new Label(group, SWT.NONE);
    label.setText(Messages.getString("org.kalypso.ui.wizard.sensor.ImportObservationSelectionWizardPage3")); //$NON-NLS-1$

    final Text textFileSource = new Text(group, SWT.BORDER);
    textFileSource.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    textFileSource.setText(StringUtils.EMPTY);
    textFileSource.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(final ModifyEvent e) {
            handleSourcePathModified(textFileSource.getText());
        }
    });

    final Button button = new Button(group, SWT.PUSH);
    button.setText(Messages.getString("org.kalypso.ui.wizard.sensor.ImportObservationSelectionWizardPage4")); //$NON-NLS-1$
    button.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));

    button.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            chooseSourceFile(textFileSource);
        }
    });

    // line 2
    final Label formatLabel = new Label(group, SWT.NONE);
    formatLabel
            .setText(Messages.getString("org.kalypso.ui.wizard.sensor.ImportObservationSelectionWizardPage5")); //$NON-NLS-1$

    m_formatCombo = new ComboViewer(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    m_formatCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    m_formatCombo.setContentProvider(new ArrayContentProvider());
    m_formatCombo.setLabelProvider(new LabelProvider());
    m_formatCombo.setInput(m_adapter);

    m_formatCombo.addSelectionChangedListener(this);

    if (m_adapter.length > 0)
        m_formatCombo.setSelection(new StructuredSelection(m_adapter[0]));

    new Label(group, SWT.NONE);

    // TimeZone
    /* time zone selection */
    final Label timezoneLabel = new Label(group, SWT.NONE);
    timezoneLabel.setText(Messages.getString("ImportObservationSelectionWizardPage.0")); //$NON-NLS-1$

    final String[] tz = TimeZone.getAvailableIDs();
    Arrays.sort(tz);

    final ComboViewer comboTimeZones = new ComboViewer(group, SWT.BORDER | SWT.SINGLE);
    comboTimeZones.getControl().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));

    comboTimeZones.setContentProvider(new ArrayContentProvider());
    comboTimeZones.setLabelProvider(new LabelProvider());
    comboTimeZones.setInput(tz);

    comboTimeZones.addFilter(new TimezoneEtcFilter());

    comboTimeZones.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) comboTimeZones.getSelection();
            updateTimeZone((String) selection.getFirstElement());
        }
    });

    comboTimeZones.getCombo().addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(final ModifyEvent e) {
            updateTimeZone(comboTimeZones.getCombo().getText());
        }
    });

    if (m_timezone != null) {
        final String id = m_timezone.getID();
        if (ArrayUtils.contains(tz, id))
            comboTimeZones.setSelection(new StructuredSelection(id));
        else
            comboTimeZones.getCombo().setText(id);
    }
}

From source file:org.kalypso.ui.wizards.imports.observation.ImportObservationSelectionWizardPage.java

License:Open Source License

public void createControlSource(final Composite parent) {
    final Group group = new Group(parent, SWT.NONE);
    group.setText(Messages// w  w  w .java 2  s  . com
            .getString("org.kalypso.ui.wizards.imports.observation.ImportObservationSelectionWizardPage.5")); //$NON-NLS-1$

    final GridData groupData = new GridData(SWT.FILL, SWT.FILL, true, false);
    group.setLayoutData(groupData);

    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    group.setLayout(gridLayout);

    /* file selection */
    final Label labelFilePath = new Label(group, SWT.READ_ONLY);
    labelFilePath.setText(Messages
            .getString("org.kalypso.ui.wizards.imports.observation.ImportObservationSelectionWizardPage.6")); //$NON-NLS-1$

    m_textFileSource = new Text(group, SWT.READ_ONLY | SWT.BORDER);
    m_textFileSource.setText(DEFAUL_FILE_LABEL);
    m_textFileSource.addFocusListener(this);

    final GridData textData = new GridData(SWT.FILL, SWT.FILL, true, false);
    m_textFileSource.setLayoutData(textData);

    /* Choose file button */
    final Button chooseFileButton = new Button(group, SWT.PUSH);
    chooseFileButton.setText(Messages
            .getString("org.kalypso.ui.wizards.imports.observation.ImportObservationSelectionWizardPage.7")); //$NON-NLS-1$
    final GridData chooseFileButtonGridData = new GridData();
    chooseFileButtonGridData.horizontalAlignment = GridData.END;
    chooseFileButton.setLayoutData(chooseFileButtonGridData);

    chooseFileButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            m_sourceFile = chooseFile(m_sourceFile);
            if (m_sourceFile != null) {
                m_textFileSource.setText(m_sourceFile.getPath());
                validate();
            }
        }
    });

    final Label formatLabel = new Label(group, SWT.NONE);
    formatLabel.setText(Messages
            .getString("org.kalypso.ui.wizards.imports.observation.ImportObservationSelectionWizardPage.10")); //$NON-NLS-1$

    m_formatCombo = new ComboViewer(group, SWT.READ_ONLY | SWT.DROP_DOWN);

    final GridData formatData = new GridData(SWT.FILL, SWT.FILL, true, false);
    m_formatCombo.getControl().setLayoutData(formatData);

    m_formatCombo.add(m_adapter);

    m_formatCombo.setContentProvider(new ArrayContentProvider());

    m_formatCombo.setLabelProvider(new ILabelProvider() {
        @Override
        public Image getImage(final Object element) {
            return null;
        }

        @Override
        public String getText(final Object element) {
            return element.toString();
        }

        @Override
        public void addListener(final ILabelProviderListener listener) {
            // nothing as labelprovider will not change
        }

        @Override
        public void dispose() {
            // nothing as labelprovider will not change
        }

        @Override
        public boolean isLabelProperty(final Object element, final String property) {
            return true;
        }

        @Override
        public void removeListener(final ILabelProviderListener listener) {
            // nothing
        }
    });

    m_formatCombo.setInput(m_adapter);
    m_formatCombo.addSelectionChangedListener(this);

    if (m_adapter.length > 0)
        m_formatCombo.setSelection(new StructuredSelection(m_adapter[0]));

    // just a placeholder
    new Label(group, SWT.NONE);

    /* time zone selection */
    final Label timezoneLabel = new Label(group, SWT.NONE);
    timezoneLabel.setText(Messages
            .getString("org.kalypso.ui.wizards.imports.observation.ImportObservationSelectionWizardPage.0")); //$NON-NLS-1$

    final String[] tz = TimeZone.getAvailableIDs();
    Arrays.sort(tz);

    final ComboViewer comboTimeZones = new ComboViewer(group, SWT.BORDER | SWT.SINGLE);
    comboTimeZones.getControl().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));

    m_timezone = KalypsoCorePlugin.getDefault().getTimeZone();

    comboTimeZones.setContentProvider(new ArrayContentProvider());
    comboTimeZones.setLabelProvider(new LabelProvider());
    comboTimeZones.setInput(tz);

    comboTimeZones.addFilter(new TimezoneEtcFilter());

    comboTimeZones.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) comboTimeZones.getSelection();
            updateTimeZone((String) selection.getFirstElement());
        }
    });

    comboTimeZones.getCombo().addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(final ModifyEvent e) {
            updateTimeZone(comboTimeZones.getCombo().getText());
        }
    });

    if (m_timezone != null) {
        final String id = m_timezone.getID();
        if (ArrayUtils.contains(tz, id))
            comboTimeZones.setSelection(new StructuredSelection(id));
        else
            comboTimeZones.getCombo().setText(id);
    }

    // just a placeholder
    new Label(group, SWT.NONE);
}

From source file:org.kalypso.zml.ui.imports.ImportObservationSourcePage.java

License:Open Source License

private void createParameterTypeControl(final Composite parent) {
    final Label formatLabel = new Label(parent, SWT.NONE);
    formatLabel.setText(Messages.getString("ImportObservationSourcePage.2")); //$NON-NLS-1$

    final ComboViewer parameterCombo = new ComboViewer(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    parameterCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final ParameterTypeLabelProvider labelProvider = new ParameterTypeLabelProvider();
    parameterCombo.setLabelProvider(labelProvider);
    parameterCombo.setContentProvider(new ArrayContentProvider());

    parameterCombo.setSorter(new ViewerSorter() {
        @Override/* w ww  .  jav a  2  s  . c o m*/
        public int compare(final org.eclipse.jface.viewers.Viewer viewer, final Object e1, final Object e2) {
            final String l1 = labelProvider.getText(e1);
            final String l2 = labelProvider.getText(e2);

            if (StringUtils.isNotEmpty(l1) && StringUtils.isNotEmpty(l2))
                return l1.compareTo(l2);

            return super.compare(viewer, e1, e2);
        }
    });

    final String[] parameterTypes = m_data.getAllowedParameterTypes();
    parameterCombo.setInput(parameterTypes);

    new Label(parent, SWT.NONE);

    /* Binding */
    final IViewerObservableValue target = ViewersObservables.observeSinglePostSelection(parameterCombo);
    final IObservableValue model = BeansObservables.observeValue(m_data,
            ImportObservationData.PROPERTY_PARAMETER_TYPE);

    m_binding.bindValue(target, model);

    if (m_updateMode)
        parameterCombo.getCombo().setEnabled(false);
}

From source file:org.kalypso.zml.ui.table.dialogs.input.ChooseSteppingDialog.java

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
 *///from   www  .j  a v a 2  s  .c o  m
@Override
protected Control createDialogArea(final Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new GridLayout());

    if (ArrayUtils.isEmpty(m_steppings)) {
        m_toolkit.createLabel(composite, Messages.ChooseSteppingDialog_2);
        return composite;
    }

    m_toolkit.createLabel(composite, Messages.ChooseSteppingDialog_3);
    final ComboViewer viewer = new ComboViewer(composite, SWT.BORDER | SWT.READ_ONLY | SWT.SINGLE);
    viewer.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));

    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(final Object element) {
            final Integer step = (Integer) element;

            final Calendar calendar = Calendar.getInstance(KalypsoCorePlugin.getDefault().getTimeZone());
            calendar.setTime(m_current);
            calendar.add(Calendar.HOUR_OF_DAY, step);

            final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm"); //$NON-NLS-1$

            return String.format(Messages.ChooseSteppingDialog_4, step, sdf.format(calendar.getTime()));
        }
    });
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setInput(m_steppings);

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            m_selection = (Integer) selection.getFirstElement();
        }
    });

    viewer.setSelection(new StructuredSelection(m_steppings[0]));

    m_toolkit.adapt(composite);

    return composite;
}

From source file:org.ow2.petals.client.swt.dialogs.NewWsdlOperationDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {

    getShell().setText("New WSDL Operation");
    setTitle("New WSDL Operation");
    setMessage("Create a custom WSDL operation.");

    Composite container = new Composite(parent, SWT.NONE);
    container.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Local Part
    Label l = new Label(container, SWT.NONE);
    l.setText("Operation Name:");
    l.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));

    Text text = new Text(container, SWT.SINGLE | SWT.BORDER);
    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (this.localPart != null)
        text.setText(this.localPart);

    text.addModifyListener(new ModifyListener() {
        @Override/*www . ja  v  a  2 s .  c  om*/
        public void modifyText(ModifyEvent e) {
            NewWsdlOperationDialog.this.localPart = ((Text) e.widget).getText();
            validate();
        }
    });

    // Name space URI
    l = new Label(container, SWT.NONE);
    l.setText("Operation Namespace:");
    l.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));

    text = new Text(container, SWT.SINGLE | SWT.BORDER);
    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (this.namespaceUri != null)
        text.setText(this.namespaceUri);

    text.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            NewWsdlOperationDialog.this.namespaceUri = ((Text) e.widget).getText();
            validate();
        }
    });

    // MEP
    l = new Label(container, SWT.NONE);
    l.setText("MEP:");
    l.setToolTipText("Message Exchange Pattern");
    l.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));

    final ComboViewer mepViewer = new ComboViewer(container, SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN);
    mepViewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    mepViewer.setContentProvider(new ArrayContentProvider());
    mepViewer.setLabelProvider(new LabelProvider());
    mepViewer.setInput(Mep.values());

    mepViewer.setSelection(new StructuredSelection(this.mep));
    mepViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent e) {
            NewWsdlOperationDialog.this.mep = (Mep) ((IStructuredSelection) mepViewer.getSelection())
                    .getFirstElement();
            validate();
        }
    });

    return container;
}

From source file:org.ow2.petals.client.swt.tabs.PreferencesTab.java

License:Open Source License

/**
 * Constructor./*from   www  . j  av  a 2 s  .  c  o  m*/
 * @param parent
 * @param clientApp
 */
public PreferencesTab(Composite parent, final ClientApplication clientApp) {

    // Root elements
    super(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().spacing(0, 0).applyTo(this);
    setLayoutData(new GridData(GridData.FILL_BOTH));

    final ColorCacheManager colorManager = clientApp.getColorManager();
    new Label(this, SWT.NONE).setText("The preferences for this client application.");

    // History
    Composite historyGroup = createSection("History", 4, false);
    Label l = new Label(historyGroup, SWT.NONE);
    l.setText("History Directory:");
    l.setToolTipText("The directory in which old requests are stored");

    final Text directoryText = new Text(historyGroup, SWT.BORDER | SWT.READ_ONLY);
    directoryText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    directoryText.setText(PreferencesManager.INSTANCE.getHistoryDirectory().getAbsolutePath());

    Button browseButton = new Button(historyGroup, SWT.PUSH);
    browseButton.setText("Browse...");
    browseButton.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {

            DirectoryDialog dlg = new DirectoryDialog(getShell());
            String dir = dlg.open();
            if (dir != null) {
                PreferencesManager.INSTANCE.saveHistoryDirectory(new File(dir));
                directoryText.setText(dir);
                clientApp.refreshHistory();
            }
        }
    });

    Button resetHistoryDirButton = new Button(historyGroup, SWT.PUSH);
    resetHistoryDirButton.setText("Reset Default Directory");
    resetHistoryDirButton.setToolTipText("Set the history directory in the temporary files");
    resetHistoryDirButton.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {

            PreferencesManager.INSTANCE.saveHistoryDirectory(null);
            File f = PreferencesManager.INSTANCE.getHistoryDirectory();
            directoryText.setText(f.getAbsolutePath());
            clientApp.refreshHistory();
        }
    });

    // Clear the history?
    new Label(historyGroup, SWT.NONE);
    Link link = new Link(historyGroup, SWT.NONE);
    link.setText("<A>Clear All the History</A>");
    link.setToolTipText("Deletes the entire history");
    GridDataFactory.swtDefaults().span(3, 1).applyTo(link);
    link.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {
            SwtUtils.clearHistoryWithProgressBar(getShell(), -1, clientApp);
        }
    });

    new Label(historyGroup, SWT.NONE);
    link = new Link(historyGroup, SWT.NONE);
    link.setText("<A>Clear the History older than...</A>");
    link.setToolTipText("Deletes the oldest part of the history");
    link.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {
            ClearHistoryDialog dlg = new ClearHistoryDialog(getShell());
            if (dlg.open() == Window.OK) {
                SwtUtils.clearHistoryWithProgressBar(getShell(), dlg.getDays(), clientApp);
                clientApp.refreshHistory();
            }
        }
    });

    // General Preferences
    Composite defaultGroup = createSection("General Preferences", 2, false);

    Button wrapButton = new Button(defaultGroup, SWT.CHECK);
    wrapButton.setText("Wrap text in XML viewers");
    wrapButton.setToolTipText("Will allow XML viewers to wrap their content instead of only scrolling");
    wrapButton.setSelection(PreferencesManager.INSTANCE.wrapInsteadOfScrolling());

    GridDataFactory.swtDefaults().span(2, 1).applyTo(wrapButton);
    wrapButton.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {

            boolean wrap = ((Button) e.widget).getSelection();
            PreferencesManager.INSTANCE.saveWrapInsteadOfScrolling(wrap);

            MessageDialog.openInformation(getShell(), "Restart",
                    "The user interface needs to be restarted to take this preference into account.\n"
                            + "Save your work and then go into \"File > Restart the User Interface\".");
        }
    });

    l = new Label(defaultGroup, SWT.NONE);
    l.setText("Default Timeout:");
    l.setToolTipText("The default timeout to use when crating a new request");

    Spinner timeoutSpinner = new Spinner(defaultGroup, SWT.BORDER);
    long value = PreferencesManager.INSTANCE.getDefaultTimeout();
    timeoutSpinner.setValues((int) value, 0, Integer.MAX_VALUE, 0, 1000, 100);

    // Syntax highlighting
    Composite shGroup = createSection("Syntax Highlighting", 2, true);
    l = new Label(shGroup, SWT.NONE);
    l.setText("XML Viewers Preview");
    GridDataFactory.swtDefaults().span(2, 1).applyTo(l);

    final Map<XmlRegionType, String> regionToLabel = new LinkedHashMap<XmlRegionType, String>();
    regionToLabel.put(XmlRegionType.MARKUP, "XML Mark-ups");
    regionToLabel.put(XmlRegionType.ATTRIBUTE, "XML Attributes");
    regionToLabel.put(XmlRegionType.ATTRIBUTE_VALUE, "Attribute Values");
    regionToLabel.put(XmlRegionType.COMMENT, "XML Comments");
    regionToLabel.put(XmlRegionType.CDATA, "CDATA Sections");
    regionToLabel.put(XmlRegionType.INSTRUCTION, "XML Instructions");

    // Show a preview area
    final StyledText previewStyledText = SwtUtils.createXmlViewer(shGroup, colorManager, false);
    try {
        String previewText = Utils.loadResource("/sample.xml");
        previewStyledText.setText(previewText);

    } catch (IOException e1) {
        clientApp.log("An error occurred while loading a request file.", e1, Level.INFO);
    }

    // List the customizable elements...
    Composite subContainer = new Composite(shGroup, SWT.NONE);
    GridLayoutFactory.swtDefaults().margins(10, 0).numColumns(2).applyTo(subContainer);
    GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.BEGINNING).grab(false, true).applyTo(subContainer);

    new Label(subContainer, SWT.NONE).setText("Select the style to edit:");
    final ComboViewer styleViewer = new ComboViewer(subContainer, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
    styleViewer.setContentProvider(new ArrayContentProvider());
    styleViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return regionToLabel.get(element);
        };
    });

    GridDataFactory.swtDefaults().hint(200, SWT.DEFAULT).applyTo(styleViewer.getCombo());
    styleViewer.setInput(regionToLabel.keySet());

    // ... and their properties
    final List<Button> styleButtons = new ArrayList<Button>();

    new Label(subContainer, SWT.NONE);
    Button b = new Button(subContainer, SWT.CHECK);
    b.setText("Bold");
    b.setData(PreferencesManager.BOLD);
    styleButtons.add(b);

    new Label(subContainer, SWT.NONE);
    b = new Button(subContainer, SWT.CHECK);
    b.setText("Italic");
    b.setData(PreferencesManager.ITALIC);
    styleButtons.add(b);

    new Label(subContainer, SWT.NONE);
    b = new Button(subContainer, SWT.CHECK);
    b.setText("Underline");
    b.setData(PreferencesManager.UNDERLINE);
    styleButtons.add(b);

    new Label(subContainer, SWT.NONE);
    Composite colorComposite = new Composite(subContainer, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).applyTo(colorComposite);

    new Label(colorComposite, SWT.NONE).setText("Foreground Color:");
    final ColorSelector colorSelector = new ColorSelector(colorComposite);

    new Label(subContainer, SWT.NONE);
    b = new Button(subContainer, SWT.PUSH);
    b.setText("Reset All the Settings for this Style");
    b.setToolTipText("Resets all the settings for the selected style");
    b.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    b.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {

            XmlRegionType xr = (XmlRegionType) ((IStructuredSelection) styleViewer.getSelection())
                    .getFirstElement();
            PreferencesManager.INSTANCE.saveXmlRegionColor(xr, null);
            colorManager.updateColor(xr);

            PreferencesManager.INSTANCE.saveXmlRegionStyle(xr, PreferencesManager.BOLD, null);
            PreferencesManager.INSTANCE.saveXmlRegionStyle(xr, PreferencesManager.ITALIC, null);
            PreferencesManager.INSTANCE.saveXmlRegionStyle(xr, PreferencesManager.UNDERLINE, null);

            previewStyledText.notifyListeners(SWT.Modify, new Event());
            styleViewer.getCombo().notifyListeners(SWT.Selection, new Event());
        }
    });

    // React to selection changes
    Listener clickListener = new Listener() {
        @Override
        public void handleEvent(Event e) {

            XmlRegionType xr = (XmlRegionType) ((IStructuredSelection) styleViewer.getSelection())
                    .getFirstElement();
            Button b = (Button) e.widget;
            String name = (String) b.getData();
            PreferencesManager.INSTANCE.saveXmlRegionStyle(xr, name, b.getSelection());
            previewStyledText.notifyListeners(SWT.Modify, new Event());
        }
    };

    for (Button bb : styleButtons)
        bb.addListener(SWT.Selection, clickListener);

    styleViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent e) {

            XmlRegionType xr = (XmlRegionType) ((IStructuredSelection) styleViewer.getSelection())
                    .getFirstElement();
            Color c = colorManager.getColor(xr);
            colorSelector.setColorValue(c.getRGB());

            for (Button b : styleButtons) {
                String name = (String) b.getData();
                b.setSelection(PreferencesManager.INSTANCE.getXmlRegionStyle(xr, name));
            }
        }
    });

    colorSelector.addListener(new IPropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent e) {

            if (!ColorSelector.PROP_COLORCHANGE.equals(e.getProperty()))
                return;

            XmlRegionType xr = (XmlRegionType) ((IStructuredSelection) styleViewer.getSelection())
                    .getFirstElement();
            RGB rgb = (RGB) e.getNewValue();
            PreferencesManager.INSTANCE.saveXmlRegionColor(xr, rgb);
            colorManager.updateColor(xr);

            previewStyledText.notifyListeners(SWT.Modify, new Event());
        }
    });

    // Initial selection
    styleViewer.getCombo().select(0);
    styleViewer.getCombo().notifyListeners(SWT.Selection, new Event());
}

From source file:org.polarsys.reqcycle.export.pages.RequirementSourceSelectionPage.java

License:Open Source License

/**
 * Create contents of the wizard./*from   ww  w.  j  a  v a  2  s  .c  o  m*/
 * 
 * @param parent
 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);

    setControl(container);
    container.setLayout(new GridLayout(1, false));

    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    composite.setLayout(new GridLayout(1, false));

    Group grpDataSource = new Group(composite, SWT.NONE);
    grpDataSource.setLayout(new GridLayout(1, false));
    grpDataSource.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    grpDataSource.setText("Data Sources");

    reqSourceTableViewer = CheckboxTableViewer.newCheckList(grpDataSource, SWT.BORDER | SWT.FULL_SELECTION);
    reqSourceTableViewer.setLabelProvider(new RequirementSourceLabelProvider());
    reqSourceTableViewer.setContentProvider(ProviderUtils.getArrayContentProvider());
    reqSourceTableViewer.setInput(requirementSourceManager.getRequirementSources());
    table = reqSourceTableViewer.getTable();
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    reqSourceTableViewer.addCheckStateListener(new ICheckStateListener() {
        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getChecked()) {
                controller.addReqProvider(
                        new RequirementSourceReqProvider((RequirementSource) event.getElement()));
            } else {
                controller.removeReqProvider(
                        new RequirementSourceReqProvider((RequirementSource) event.getElement()));
            }
            getWizard().getContainer().updateButtons();
            getWizard().getContainer().updateMessage();
        }
    });

    Group grpScope = new Group(composite, SWT.NONE);
    grpScope.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    grpScope.setText("Scopes");
    grpScope.setLayout(new GridLayout(2, false));
    Label lblDataModel = new Label(grpScope, SWT.NONE);
    lblDataModel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblDataModel.setText("Data Model :");

    ComboViewer modelComboViewer = new ComboViewer(grpScope, SWT.READ_ONLY);
    Combo combo = modelComboViewer.getCombo();
    combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    modelComboViewer.setContentProvider(ProviderUtils.getArrayContentProvider());

    modelComboViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IDataModel) {
                return ((IDataModel) element).getName();
            }
            return "";
        }
    });
    modelComboViewer.setInput(dataManager.getCurrentDataModels());

    modelComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {

            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                Object firstElement = ((IStructuredSelection) selection).getFirstElement();
                if (firstElement instanceof IDataModel) {
                    IDataModel selectedDataModel = (IDataModel) firstElement;
                    if (selectedDataModel != dataModel) {
                        dataModel = selectedDataModel;
                        setScopes(dataManager.getScopes(dataModel));
                    }
                }
            }
        }
    });

    reqScopeTableViewer = CheckboxTableViewer.newCheckList(grpScope, SWT.BORDER | SWT.FULL_SELECTION);
    reqScopeTableViewer.setContentProvider(ProviderUtils.getArrayContentProvider());
    reqScopeTableViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof Scope) {
                return ((Scope) element).getName();
            }
            return "a";
        }
    });
    reqScopeTableViewer.setInput(scopes);

    reqScopeTableViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getChecked()) {
                controller.addReqProvider(new ScopeReqProvider((Scope) event.getElement()));
            } else {
                controller.removeReqProvider(new ScopeReqProvider((Scope) event.getElement()));
            }
            getWizard().getContainer().updateButtons();
            getWizard().getContainer().updateMessage();
        }
    });
    table_1 = reqScopeTableViewer.getTable();
    table_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    for (RequirementSource s : selectedSources) {
        reqSourceTableViewer.setChecked(s, true);
    }

    doCreateGroup(composite);

}

From source file:org.polarsys.reqcycle.repository.connector.rmf.ui.ScopeSelectionComposite.java

License:Open Source License

/**
 * Create the composite.//from   w  ww.  j  a  va2s.c  om
 * 
 * @param parent
 * @param style
 */
public ScopeSelectionComposite(Composite parent, int style) {
    super(parent, style);

    Composite control = new Composite(parent, SWT.None);
    control.setLayout(new GridLayout(2, false));
    control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

    Label lblDataModel = new Label(control, SWT.NONE);
    lblDataModel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
    lblDataModel.setText("Data Model :");

    ComboViewer cvDataModel = new ComboViewer(control, SWT.NONE);
    Combo cDataModel = cvDataModel.getCombo();
    cDataModel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblScope = new Label(control, SWT.NONE);
    lblScope.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
    lblScope.setText("Scope :");

    Combo cScope = new Combo(control, SWT.NONE);
    cScope.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
}

From source file:org.polarsys.reqcycle.repository.data.util.EntryUtil.java

License:Open Source License

public static ComboViewer createComboViewer(Composite composite, String attributeName, Object input) {
    composite.setLayout(new GridLayout(3, false));
    Label label = new Label(composite, SWT.None);
    label.setText(attributeName);/*from   ww w  . j  ava2 s  .  c o  m*/
    final ComboViewer comboViewer = new ComboViewer(composite);
    Combo combo = comboViewer.getCombo();
    combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    final LabelProvider labelProvider = new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (Platform.getAdapterManager().hasAdapter(element, String.class.getName())) {
                Object adapter = Platform.getAdapterManager().getAdapter(element, String.class);
                if (adapter instanceof String) {
                    return ((String) adapter);
                }
            }
            return super.getText(element);
        }
    };
    comboViewer.setLabelProvider(labelProvider);
    comboViewer.setContentProvider(new ArrayContentProvider());
    comboViewer.setInput(input);

    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                Object firstElement = ((IStructuredSelection) selection).getFirstElement();
                if (firstElement instanceof IDataModel || firstElement instanceof IRequirementType
                        || firstElement instanceof Scope) {
                    comboViewer.setData(AN_ENTRY, labelProvider.getText(firstElement));
                } else {
                    comboViewer.setData(AN_ENTRY, null);
                }
            }
        }
    });

    Button clearCombo = new Button(composite, SWT.PUSH);
    clearCombo.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false, false));
    clearCombo.setImage(Activator.getImageDescriptor(CLEAR_IMG_PATH).createImage());
    clearCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (comboViewer != null) {
                comboViewer.setSelection(StructuredSelection.EMPTY);
            }
        }
    });
    return comboViewer;
}

From source file:org.raspinloop.fmi.plugin.launcher.RilMainTab.java

License:Open Source License

protected ComboViewer createComboViewer(Group parent, int style, int hspan) {
    ComboViewer c = new ComboViewer(parent, style);
    c.getCombo().setFont(parent.getFont());
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = hspan;//  w  ww .j a  v a 2 s  .co m
    c.getCombo().setLayoutData(gd);

    // Some platforms open up combos in bad sizes without this, see bug
    // 245569
    c.getCombo().setVisibleItemCount(30);
    c.getCombo().select(0);
    return c;
}