Example usage for org.eclipse.jface.dialogs IDialogConstants VERTICAL_SPACING

List of usage examples for org.eclipse.jface.dialogs IDialogConstants VERTICAL_SPACING

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs IDialogConstants VERTICAL_SPACING.

Prototype

int VERTICAL_SPACING

To view the source code for org.eclipse.jface.dialogs IDialogConstants VERTICAL_SPACING.

Click Source Link

Document

Vertical spacing in dialog units (value 4).

Usage

From source file:org.eclipse.ui.internal.ide.dialogs.ResourceFilterGroup.java

License:Open Source License

private void setupMultiOperatorAndField(boolean updateOperator) {
    boolean isUsingRegularExpression = false;
    String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
    if (updateOperator) {
        String[] operators = getLocalOperatorsForKey(selectedKey);
        multiOperator.setItems(operators);
        FileInfoAttributesMatcher.Argument argument = FileInfoAttributesMatcher
                .decodeArguments((String) filter.getArguments());
        String local = MultiMatcherLocalization.getLocalMultiMatcherKey(argument.operator);
        int index = multiOperator.indexOf(local);
        if (index != -1)
            multiOperator.select(index);
        else/*from ww w.j a va 2 s.  c  o  m*/
            multiOperator.select(0);
    }
    String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());

    Class selectedKeyOperatorType = FileInfoAttributesMatcher.getTypeForKey(selectedKey, selectedOperator);

    if (intiantiatedKeyOperatorType != null) {
        if (arguments != null) {
            arguments.dispose();
            arguments = null;
        }
        if (attributeStringArgumentComposite != null) {
            attributeStringArgumentComposite.dispose();
            attributeStringArgumentComposite = null;
        }
        if (stringArgumentComposite != null) {
            stringArgumentComposite.dispose();
            stringArgumentComposite = null;
        }
        if (argumentsBoolean != null) {
            argumentsBoolean.dispose();
            argumentsBoolean = null;
        }
        if (argumentsDate != null) {
            argumentsDate.dispose();
            argumentsDate = null;
        }
        if (argumentsRegularExpresion != null) {
            argumentsRegularExpresion.dispose();
            argumentsRegularExpresion = null;
        }
        if (argumentsCaseSensitive != null) {
            argumentsCaseSensitive.dispose();
            argumentsCaseSensitive = null;
        }
        if (dummyLabel1 != null) {
            dummyLabel1.dispose();
            dummyLabel1 = null;
        }
        if (dummyLabel2 != null) {
            dummyLabel2.dispose();
            dummyLabel2 = null;
        }
        fContentAssistField = null;
        FileInfoAttributesMatcher.Argument argument = FileInfoAttributesMatcher
                .decodeArguments((String) filter.getArguments());
        valueCache.put(intiantiatedKeyOperatorType.getName(), argument.pattern);
        argument.pattern = (String) valueCache.get(selectedKeyOperatorType.getName());
        if (argument.pattern == null)
            argument.pattern = new String();
        filter.setArguments(FileInfoAttributesMatcher.encodeArguments(argument));
    }

    if (selectedKeyOperatorType.equals(String.class)) {

        arguments = new Text(multiArgumentComposite, SWT.SINGLE | SWT.BORDER);
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
        data.widthHint = 150;
        arguments.setLayoutData(data);
        arguments.setFont(multiArgumentComposite.getFont());
        arguments.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                validateInputText();
            }
        });

        dummyLabel1 = new Label(multiArgumentComposite, SWT.NONE);
        data = new GridData(SWT.LEFT, SWT.CENTER, true, true);
        dummyLabel1.setText(new String());
        data.horizontalSpan = 1;
        dummyLabel1.setLayoutData(data);

        dummyLabel2 = new Label(multiArgumentComposite, SWT.NONE);
        data = new GridData(SWT.LEFT, SWT.CENTER, true, true);
        dummyLabel2.setText(new String());
        data.horizontalSpan = 1;
        dummyLabel2.setLayoutData(data);

        stringArgumentComposite = new Composite(multiArgumentComposite, SWT.NONE);

        GridLayout layout = new GridLayout();
        layout.numColumns = 2;
        layout.marginWidth = 0;
        layout.marginTop = dialog.getVerticalDLUsToPixel(IDialogConstants.VERTICAL_SPACING) / 2;
        layout.marginHeight = 0;
        layout.marginBottom = 0;
        stringArgumentComposite.setLayout(layout);
        data = new GridData(SWT.FILL, SWT.CENTER, true, true);
        data.horizontalSpan = 1;
        stringArgumentComposite.setLayoutData(data);
        stringArgumentComposite.setFont(multiArgumentComposite.getFont());

        argumentsCaseSensitive = new Button(stringArgumentComposite, SWT.CHECK);
        argumentsCaseSensitive.setText(NLS.bind(IDEWorkbenchMessages.ResourceFilterPage_caseSensitive, null));
        data = new GridData(SWT.LEFT, SWT.CENTER, false, false);
        argumentsCaseSensitive.setLayoutData(data);
        argumentsCaseSensitive.setFont(multiArgumentComposite.getFont());

        argumentsRegularExpresion = new Button(stringArgumentComposite, SWT.CHECK);
        argumentsRegularExpresion
                .setText(NLS.bind(IDEWorkbenchMessages.ResourceFilterPage_regularExpression, null));
        data = new GridData(SWT.LEFT, SWT.CENTER, false, false);
        data.minimumWidth = 100;
        argumentsRegularExpresion.setLayoutData(data);
        argumentsRegularExpresion.setFont(multiArgumentComposite.getFont());

        if (filter.hasStringArguments()) {
            FileInfoAttributesMatcher.Argument argument = FileInfoAttributesMatcher
                    .decodeArguments((String) filter.getArguments());
            arguments.setText(argument.pattern);
            isUsingRegularExpression = argument.regularExpression;
            argumentsCaseSensitive.setSelection(argument.caseSensitive);
            argumentsRegularExpresion.setSelection(argument.regularExpression);
        }

        arguments.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                storeMultiSelection();
            }
        });
        argumentsRegularExpresion.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                setupDescriptionText(null);
                storeMultiSelection();
                if (fContentAssistField != null)
                    fContentAssistField.setEnabled(argumentsRegularExpresion.getSelection());
            }
        });
        argumentsCaseSensitive.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                storeMultiSelection();
            }
        });

        TextContentAdapter contentAdapter = new TextContentAdapter();
        FindReplaceDocumentAdapterContentProposalProvider findProposer = new FindReplaceDocumentAdapterContentProposalProvider(
                true);
        fContentAssistField = new ContentAssistCommandAdapter(arguments, contentAdapter, findProposer, null,
                new char[] { '\\', '[', '(' }, true);
    }
    if (selectedKeyOperatorType.equals(Integer.class)) {
        GridData data;
        arguments = new Text(multiArgumentComposite, SWT.SINGLE | SWT.BORDER);
        data = new GridData(SWT.FILL, SWT.FILL, true, false);
        data.widthHint = 150;
        arguments.setLayoutData(data);
        arguments.setFont(multiArgumentComposite.getFont());
        arguments.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                validateInputText();
            }
        });

        if (filter.hasStringArguments()) {
            FileInfoAttributesMatcher.Argument argument = FileInfoAttributesMatcher
                    .decodeArguments((String) filter.getArguments());
            if (selectedKey.equals(FileInfoAttributesMatcher.KEY_LAST_MODIFIED)
                    || selectedKey.equals(FileInfoAttributesMatcher.KEY_CREATED))
                arguments.setText(convertToEditableTimeInterval(argument.pattern));
            else
                arguments.setText(convertToEditableLength(argument.pattern));
        }

        arguments.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                storeMultiSelection();
            }
        });
    }
    if (selectedKeyOperatorType.equals(Date.class)) {
        GridData data;
        argumentsDate = new DateTime(multiArgumentComposite, SWT.DATE | SWT.MEDIUM | SWT.BORDER);
        data = new GridData(SWT.FILL, SWT.FILL, true, false);
        argumentsDate.setLayoutData(data);
        argumentsDate.setFont(multiArgumentComposite.getFont());
        argumentsDate.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                storeMultiSelection();
            }
        });
        if (filter.hasStringArguments()) {
            FileInfoAttributesMatcher.Argument argument = FileInfoAttributesMatcher
                    .decodeArguments((String) filter.getArguments());
            Date date;
            Calendar calendar = Calendar.getInstance();
            try {
                date = new Date(Long.parseLong(argument.pattern));
                calendar.setTime(date);
            } catch (NumberFormatException e1) {
                date = new Date();
                calendar.setTime(date);
                argument.pattern = Long.toString(calendar.getTimeInMillis());
            }
            argumentsDate.setDay(calendar.get(Calendar.DAY_OF_MONTH));
            argumentsDate.setMonth(calendar.get(Calendar.MONTH));
            argumentsDate.setYear(calendar.get(Calendar.YEAR));
        }
    }
    if (selectedKeyOperatorType.equals(Boolean.class)) {
        GridData data;
        argumentsBoolean = new Combo(multiArgumentComposite, SWT.READ_ONLY);
        data = new GridData(SWT.FILL, SWT.TOP, true, false);
        argumentsBoolean.setLayoutData(data);
        argumentsBoolean.setFont(multiArgumentComposite.getFont());
        argumentsBoolean.setItems(
                new String[] { MultiMatcherLocalization.getLocalMultiMatcherKey(Boolean.TRUE.toString()),
                        MultiMatcherLocalization.getLocalMultiMatcherKey(Boolean.FALSE.toString()) });
        argumentsBoolean.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                storeMultiSelection();
            }
        });
        if (filter.hasStringArguments()) {
            FileInfoAttributesMatcher.Argument argument = FileInfoAttributesMatcher
                    .decodeArguments((String) filter.getArguments());
            if (argument.pattern.length() == 0)
                argumentsBoolean.select(0);
            else
                argumentsBoolean.select(Boolean.valueOf(argument.pattern).booleanValue() ? 0 : 1);
        }
    }
    intiantiatedKeyOperatorType = selectedKeyOperatorType;

    if (fContentAssistField != null)
        fContentAssistField.setEnabled(isUsingRegularExpression);

    shell.layout(true, true);
    if (initializationComplete) {
        Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        Point shellSize = shell.getSize();
        size.x = Math.max(size.x, shellSize.x);
        size.y = Math.max(size.y, shellSize.y);
        if ((size.x > shellSize.x) || (size.y > shellSize.y))
            shell.setSize(size);
    }
    shell.redraw();
    setupDescriptionText(null);
}

From source file:org.eclipse.ui.internal.progress.ProgressInfoItem.java

License:Open Source License

/**
 * Create the progress bar and apply any style bits from style.
 * //from www . j  ava  2s.  co m
 * @param style
 */
void createProgressBar(int style) {

    FormData buttonData = new FormData();
    buttonData.top = new FormAttachment(progressLabel, 0);
    buttonData.right = new FormAttachment(100, IDialogConstants.HORIZONTAL_SPACING * -1);

    actionBar.setLayoutData(buttonData);

    progressBar = new ProgressBar(this, SWT.HORIZONTAL | style);
    FormData barData = new FormData();
    barData.top = new FormAttachment(actionBar, IDialogConstants.VERTICAL_SPACING, SWT.TOP);
    barData.left = new FormAttachment(progressLabel, 0, SWT.LEFT);
    barData.right = new FormAttachment(actionBar, IDialogConstants.HORIZONTAL_SPACING * -1);
    barData.height = MAX_PROGRESS_HEIGHT;
    barData.width = 0;// default is too large
    progressBar.setLayoutData(barData);

    if (taskEntries.size() > 0) {
        // Reattach the link label if there is one
        FormData linkData = new FormData();
        linkData.top = new FormAttachment(progressBar, IDialogConstants.VERTICAL_SPACING);
        linkData.left = new FormAttachment(progressBar, 0, SWT.LEFT);
        linkData.right = new FormAttachment(progressBar, 0, SWT.RIGHT);
        // Give an initial value so as to constrain the link shortening
        linkData.width = 20;

        ((Link) taskEntries.get(0)).setLayoutData(linkData);
    }
}

From source file:org.eclipse.ui.internal.progress.ProgressInfoItem.java

License:Open Source License

/**
 * Set the text of the link to the taskString.
 * //from  w ww . j  a va2  s  .com
 * @param taskString
 */
void setLinkText(Job linkJob, String taskString, int index) {

    if (index >= taskEntries.size()) {// Is it new?
        link = new Link(this, SWT.NONE);

        FormData linkData = new FormData();
        if (index == 0 || taskEntries.size() == 0) {
            Control top = progressBar;
            if (top == null) {
                top = progressLabel;
            }
            linkData.top = new FormAttachment(top, IDialogConstants.VERTICAL_SPACING);
            linkData.left = new FormAttachment(top, 0, SWT.LEFT);
            linkData.right = new FormAttachment(top, 0, SWT.RIGHT);
            // Give an initial value so as to constrain the link shortening
            linkData.width = 20;
        } else {
            Link previous = (Link) taskEntries.get(index - 1);
            linkData.top = new FormAttachment(previous, IDialogConstants.VERTICAL_SPACING);
            linkData.left = new FormAttachment(previous, 0, SWT.LEFT);
            linkData.right = new FormAttachment(previous, 0, SWT.RIGHT);
            // Give an initial value so as to constrain the link shortening
            linkData.width = 20;
        }

        link.setLayoutData(linkData);

        link.addSelectionListener(new SelectionAdapter() {
            /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
             */
            public void widgetSelected(SelectionEvent e) {
                executeTrigger();
            }
        });

        link.addListener(SWT.Resize, new Listener() {
            /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
             */
            public void handleEvent(Event event) {

                Object text = link.getData(TEXT_KEY);
                if (text == null)
                    return;

                updateText((String) text, link);

            }
        });
        taskEntries.add(link);
    } else {
        link = (Link) taskEntries.get(index);
    }

    // check for action property
    Object actionProperty = linkJob.getProperty(IProgressConstants.ACTION_PROPERTY);
    Object commandProperty = linkJob.getProperty(IProgressConstants2.COMMAND_PROPERTY);

    if (actionProperty != null && commandProperty != null) {
        // if both are specified, then use neither
        updateTrigger(null, link);
    } else {
        Object property = actionProperty != null ? actionProperty : commandProperty;
        updateTrigger(property, link);
    }

    if (link.getData(TRIGGER_KEY) == null && (taskString == null || taskString.equals(getMainTitle()))) {
        // workaround for https://bugs.eclipse.org/383570
        taskString = ""; //$NON-NLS-1$
    }
    link.setToolTipText(taskString);
    link.setData(TEXT_KEY, taskString);

    updateText(taskString, link);

}

From source file:org.eclipse.ui.texteditor.ChangeEncodingAction.java

License:Open Source License

public void run() {
    final IResource resource = getResource();
    final Shell parentShell = getTextEditor().getSite().getShell();
    final IEncodingSupport encodingSupport = getEncodingSupport();
    if (resource == null && encodingSupport == null) {
        MessageDialog.openInformation(parentShell, fDialogTitle,
                TextEditorMessages.ChangeEncodingAction_message_noEncodingSupport);
        return;/*www  . j a v  a  2 s. c om*/
    }

    Dialog dialog = new Dialog(parentShell) {
        private AbstractEncodingFieldEditor fEncodingEditor;
        private IPreferenceStore store = null;

        /*
         * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
         */
        protected void configureShell(Shell newShell) {
            super.configureShell(newShell);
            newShell.setText(fDialogTitle);
        }

        /*
         * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
         */
        protected Control createDialogArea(Composite parent) {
            Composite composite = (Composite) super.createDialogArea(parent);

            composite = new Composite(composite, SWT.NONE);
            GridLayout layout = new GridLayout();
            layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
            layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
            layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
            layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
            composite.setLayout(layout);

            GridData data = new GridData(GridData.FILL_BOTH);
            composite.setLayoutData(data);
            composite.setFont(parent.getFont());

            DialogPage page = new MessageDialogPage(composite) {
                public void setErrorMessage(String newMessage) {
                    super.setErrorMessage(newMessage);
                    setButtonEnabledState(IDialogConstants.OK_ID, newMessage == null);
                    setButtonEnabledState(APPLY_ID, newMessage == null);
                }

                private void setButtonEnabledState(int id, boolean state) {
                    Button button = getButton(id);
                    if (button != null)
                        button.setEnabled(state);
                }
            };

            if (resource != null) {
                fEncodingEditor = new ResourceEncodingFieldEditor("", composite, resource, null); //$NON-NLS-1$
                fEncodingEditor.setPage(page);
                fEncodingEditor.load();
            } else {
                fEncodingEditor = new EncodingFieldEditor(ENCODING_PREF_KEY, "", null, composite); //$NON-NLS-1$
                store = new PreferenceStore();
                String defaultEncoding = encodingSupport.getDefaultEncoding();
                store.setDefault(ENCODING_PREF_KEY, defaultEncoding);
                String encoding = encodingSupport.getEncoding();
                if (encoding != null)
                    store.setValue(ENCODING_PREF_KEY, encoding);
                fEncodingEditor.setPreferenceStore(store);

                fEncodingEditor.setPage(page);
                fEncodingEditor.load();

                if (encoding == null || encoding.equals(defaultEncoding) || encoding.length() == 0)
                    fEncodingEditor.loadDefault();
            }

            return composite;
        }

        /*
         * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
         */
        protected void createButtonsForButtonBar(Composite parent) {
            createButton(parent, APPLY_ID, TextEditorMessages.ChangeEncodingAction_button_apply_label, false);
            super.createButtonsForButtonBar(parent);
        }

        /*
         * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
         */
        protected void buttonPressed(int buttonId) {
            if (buttonId == APPLY_ID)
                apply();
            else
                super.buttonPressed(buttonId);
        }

        /*
         * @see org.eclipse.jface.dialogs.Dialog#okPressed()
         */
        protected void okPressed() {
            apply();
            super.okPressed();
        }

        private void apply() {
            fEncodingEditor.store();

            if (resource == null) {
                String encoding = fEncodingEditor.getPreferenceStore()
                        .getString(fEncodingEditor.getPreferenceName());
                encodingSupport.setEncoding(encoding);
            }
        }
    };
    dialog.open();
}

From source file:org.eclipse.ui.texteditor.MessageRegion.java

License:Open Source License

/**
 * Create the contents for the receiver.
 *
 * @param parent the Composite that the children will be created in
 *///from w ww  .  j  a  v a2s.  com
public void createContents(Composite parent) {
    messageComposite = new Composite(parent, SWT.NONE);
    GridLayout messageLayout = new GridLayout();
    messageLayout.numColumns = 2;
    messageLayout.marginWidth = 0;
    messageLayout.marginHeight = 0;
    messageLayout.makeColumnsEqualWidth = false;
    messageComposite.setLayout(messageLayout);
    messageImageLabel = new Label(messageComposite, SWT.NONE);

    GridData imageData = new GridData(GridData.VERTICAL_ALIGN_CENTER);
    Image sizingImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
    Rectangle imageBounds;
    if (sizingImage == null)
        imageBounds = new Rectangle(0, 0, IDialogConstants.VERTICAL_MARGIN * 2,
                IDialogConstants.VERTICAL_MARGIN * 2);
    else
        imageBounds = sizingImage.getBounds();
    imageData.heightHint = imageBounds.height + IDialogConstants.VERTICAL_SPACING;
    imageData.widthHint = imageBounds.width + IDialogConstants.HORIZONTAL_SPACING;
    messageImageLabel.setLayoutData(imageData);

    messageText = new Text(messageComposite, SWT.NONE);
    messageText.setEditable(false);
    messageText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));

    GridData textData = new GridData(
            GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
    messageText.setLayoutData(textData);
    hideRegion();

}

From source file:org.eclipse.ui.views.markers.internal.MarkerResolutionDialog.java

License:Open Source License

/**
 * Create the buttons for the table./*from  ww  w .java2s. c o m*/
 * 
 * @param control
 * @return Composite
 */
private Composite createTableButtons(Composite control) {

    Composite buttonComposite = new Composite(control, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    buttonComposite.setLayout(layout);

    Button selectAll = new Button(buttonComposite, SWT.PUSH);
    selectAll.setText(MarkerMessages.selectAllAction_title);
    selectAll.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));

    selectAll.addSelectionListener(new SelectionAdapter() {
        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        public void widgetSelected(SelectionEvent arg0) {
            markersTable.setAllChecked(true);
            setComplete(!resolutionsList.getSelection().isEmpty());
        }
    });

    Button deselectAll = new Button(buttonComposite, SWT.PUSH);
    deselectAll.setText(MarkerMessages.filtersDialog_deselectAll);
    deselectAll.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));

    deselectAll.addSelectionListener(new SelectionAdapter() {
        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        public void widgetSelected(SelectionEvent arg0) {
            markersTable.setAllChecked(false);
            setComplete(false);
        }
    });

    addMatching = new Button(buttonComposite, SWT.PUSH);
    addMatching.setText(MarkerMessages.MarkerResolutionDialog_AddOthers);
    addMatching.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));
    addMatching.setEnabled(true);
    addMatching.addSelectionListener(new SelectionAdapter() {
        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        public void widgetSelected(SelectionEvent arg0) {

            WorkbenchMarkerResolution selected = getSelectedWorkbenchResolution();
            if (selected == null) {
                return;
            }

            if (addMatchingMarkers(selected)) {
                addMatching.setEnabled(false);
            }
        }
    });

    return buttonComposite;
}

From source file:org.eclipse.umlgen.dsl.eth.presentation.components.ComponentsEditorDialog.java

License:Open Source License

/**
 * {@inheritDoc}/*from w  ww  . ja  va  2  s  . co  m*/
 *
 * @see org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite contents = new Composite(parent, SWT.NONE);
    {
        GridLayout layout = new GridLayout();
        layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
        layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
        layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
        layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
        contents.setLayout(layout);
        contents.setLayoutData(new GridData(GridData.FILL_BOTH));
        applyDialogFont(contents);
    }

    GridLayout contentsGridLayout = (GridLayout) contents.getLayout();
    contentsGridLayout.numColumns = 3;

    GridData contentsGridData = (GridData) contents.getLayoutData();
    contentsGridData.horizontalAlignment = SWT.FILL;
    contentsGridData.verticalAlignment = SWT.FILL;

    Text patternText = null;

    if (choiceOfValues != null) {
        Group filterGroupComposite = new Group(contents, SWT.NONE);
        filterGroupComposite.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_pattern_group"));
        filterGroupComposite.setLayout(new GridLayout(2, false));
        filterGroupComposite.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 3, 1));

        Label label = new Label(filterGroupComposite, SWT.NONE);
        label.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_pattern_label"));

        patternText = new Text(filterGroupComposite, SWT.BORDER);
        patternText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }

    Composite choiceComposite = new Composite(contents, SWT.NONE);
    {
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
        data.horizontalAlignment = SWT.END;
        choiceComposite.setLayoutData(data);

        GridLayout layout = new GridLayout();
        data.horizontalAlignment = SWT.FILL;
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 1;
        choiceComposite.setLayout(layout);

    }

    Label choiceLabel = new Label(choiceComposite, SWT.NONE);
    choiceLabel.setText(choiceOfValues == null ? EMFEditUIPlugin.INSTANCE.getString("_UI_Value_label")
            : EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_label"));
    GridData choiceLabelGridData = new GridData();
    choiceLabelGridData.verticalAlignment = SWT.FILL;
    choiceLabelGridData.horizontalAlignment = SWT.FILL;
    choiceLabel.setLayoutData(choiceLabelGridData);

    final Tree choiceTable = choiceOfValues == null ? null : new Tree(choiceComposite, SWT.MULTI | SWT.BORDER);
    if (choiceTable != null) {
        GridData choiceTableGridData = new GridData();
        choiceTableGridData.widthHint = Display.getCurrent().getBounds().width / 5;
        choiceTableGridData.heightHint = Display.getCurrent().getBounds().height / 3;
        choiceTableGridData.verticalAlignment = SWT.FILL;
        choiceTableGridData.horizontalAlignment = SWT.FILL;
        choiceTableGridData.grabExcessHorizontalSpace = true;
        choiceTableGridData.grabExcessVerticalSpace = true;
        choiceTable.setLayoutData(choiceTableGridData);
    }

    final TreeViewer choiceTreeViewer = choiceOfValues == null ? null : new TreeViewer(choiceTable);
    if (choiceOfValues != null) {
        choiceTreeViewer.setContentProvider(new ComponentsChoiceAdapterFactoryContentProvider(
                new TreeItemProviderAdapterFactory(), values.getChildren(), object));
        choiceTreeViewer.setLabelProvider(labelProvider);
        final PatternFilter filter = new PatternFilter() {
            @Override
            protected boolean isParentMatch(Viewer viewer, Object element) {
                return viewer instanceof AbstractTreeViewer && super.isParentMatch(viewer, element);
            }
        };
        choiceTreeViewer.addFilter(filter);
        choiceTreeViewer.setComparator(new ViewerComparator());
        assert patternText != null;
        patternText.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                filter.setPattern(((Text) e.widget).getText());
                choiceTreeViewer.refresh();
            }
        });
        choiceTreeViewer.setInput(new ItemProvider(choiceOfValues));

    }

    // We use multi even for a single line because we want to respond to the
    // enter key.
    //
    int style = multiLine ? SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER : SWT.MULTI | SWT.BORDER;
    final Text choiceText = choiceOfValues == null ? new Text(choiceComposite, style) : null;
    if (choiceText != null) {
        GridData choiceTextGridData = new GridData();
        choiceTextGridData.widthHint = Display.getCurrent().getBounds().width / 5;
        choiceTextGridData.verticalAlignment = SWT.BEGINNING;
        choiceTextGridData.horizontalAlignment = SWT.FILL;
        choiceTextGridData.grabExcessHorizontalSpace = true;
        if (multiLine) {
            choiceTextGridData.verticalAlignment = SWT.FILL;
            choiceTextGridData.grabExcessVerticalSpace = true;
        }
        choiceText.setLayoutData(choiceTextGridData);
    }

    Composite controlButtons = new Composite(contents, SWT.NONE);
    GridData controlButtonsGridData = new GridData();
    controlButtonsGridData.verticalAlignment = SWT.FILL;
    controlButtonsGridData.horizontalAlignment = SWT.FILL;
    controlButtons.setLayoutData(controlButtonsGridData);

    GridLayout controlsButtonGridLayout = new GridLayout();
    controlButtons.setLayout(controlsButtonGridLayout);

    new Label(controlButtons, SWT.NONE);

    final Button addButton = new Button(controlButtons, SWT.PUSH);
    addButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Add_label"));
    GridData addButtonGridData = new GridData();
    addButtonGridData.verticalAlignment = SWT.FILL;
    addButtonGridData.horizontalAlignment = SWT.FILL;
    addButton.setLayoutData(addButtonGridData);

    final Button removeButton = new Button(controlButtons, SWT.PUSH);
    removeButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Remove_label"));
    GridData removeButtonGridData = new GridData();
    removeButtonGridData.verticalAlignment = SWT.FILL;
    removeButtonGridData.horizontalAlignment = SWT.FILL;
    removeButton.setLayoutData(removeButtonGridData);

    Label spaceLabel = new Label(controlButtons, SWT.NONE);
    GridData spaceLabelGridData = new GridData();
    spaceLabelGridData.verticalSpan = 2;
    spaceLabel.setLayoutData(spaceLabelGridData);

    Composite featureComposite = new Composite(contents, SWT.NONE);
    {
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
        data.horizontalAlignment = SWT.END;
        featureComposite.setLayoutData(data);

        GridLayout layout = new GridLayout();
        data.horizontalAlignment = SWT.FILL;
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 1;
        featureComposite.setLayout(layout);
    }

    Label featureLabel = new Label(featureComposite, SWT.NONE);
    featureLabel.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Feature_label"));
    GridData featureLabelGridData = new GridData();
    featureLabelGridData.horizontalSpan = 2;
    featureLabelGridData.horizontalAlignment = SWT.FILL;
    featureLabelGridData.verticalAlignment = SWT.FILL;
    featureLabel.setLayoutData(featureLabelGridData);

    final Tree featureTable = new Tree(featureComposite, SWT.MULTI | SWT.BORDER);
    GridData featureTableGridData = new GridData();
    featureTableGridData.widthHint = Display.getCurrent().getBounds().width / 5;
    featureTableGridData.heightHint = Display.getCurrent().getBounds().height / 3;
    featureTableGridData.verticalAlignment = SWT.FILL;
    featureTableGridData.horizontalAlignment = SWT.FILL;
    featureTableGridData.grabExcessHorizontalSpace = true;
    featureTableGridData.grabExcessVerticalSpace = true;
    featureTable.setLayoutData(featureTableGridData);

    final TreeViewer featureTableViewer = new TreeViewer(featureTable);
    featureTableViewer.setContentProvider(contentProvider);
    featureTableViewer.setLabelProvider(labelProvider);
    featureTableViewer.setComparator(new ViewerComparator());
    featureTableViewer.setInput(values);
    if (!values.getChildren().isEmpty()) {
        featureTableViewer.setSelection(new StructuredSelection(values.getChildren().get(0)));
    }

    if (choiceTreeViewer != null) {
        choiceTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
            public void doubleClick(DoubleClickEvent event) {
                if (addButton.isEnabled()) {
                    addButton.notifyListeners(SWT.Selection, null);
                }
            }
        });

        featureTableViewer.addDoubleClickListener(new IDoubleClickListener() {
            public void doubleClick(DoubleClickEvent event) {
                if (removeButton.isEnabled()) {
                    removeButton.notifyListeners(SWT.Selection, null);
                }
            }
        });
    }

    if (choiceText != null) {
        choiceText.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent event) {
                if (!multiLine && (event.character == '\r' || event.character == '\n')) {
                    try {
                        Object value = EcoreUtil.createFromString((EDataType) eClassifier,
                                choiceText.getText());
                        values.getChildren().add(value);
                        choiceText.setText("");
                        featureTableViewer.setSelection(new StructuredSelection(value));
                        event.doit = false;
                    } catch (RuntimeException exception) {
                        // Ignore
                    }
                } else if (event.character == '\33') {
                    choiceText.setText("");
                    event.doit = false;
                }
            }
        });
    }

    addButton.addSelectionListener(new SelectionAdapter() {
        // event is null when choiceTableViewer is double clicked
        @Override
        public void widgetSelected(SelectionEvent event) {
            if (choiceTreeViewer != null) {
                IStructuredSelection selection = (IStructuredSelection) choiceTreeViewer.getSelection();
                for (Iterator<?> i = selection.iterator(); i.hasNext();) {
                    Object value = i.next();
                    if (isCandidateValue(value)) {
                        values.getChildren().add(value);
                    }
                }
                featureTableViewer.setSelection(selection);
                choiceTreeViewer.refresh();
            } else if (choiceText != null) {
                try {
                    Object value = EcoreUtil.createFromString((EDataType) eClassifier, choiceText.getText());
                    if (isCandidateValue(value)) {
                        values.getChildren().add(value);
                        choiceText.setText("");
                    }
                    featureTableViewer.setSelection(new StructuredSelection(value));
                } catch (RuntimeException exception) {
                    // Ignore
                }
            }
            choiceTreeViewer.refresh();
        }
    });

    removeButton.addSelectionListener(new SelectionAdapter() {
        // event is null when featureTableViewer is double clicked
        @Override
        public void widgetSelected(SelectionEvent event) {
            IStructuredSelection selection = (IStructuredSelection) featureTableViewer.getSelection();
            Object firstValue = null;
            for (Iterator<?> i = selection.iterator(); i.hasNext();) {
                Object value = i.next();
                if (firstValue == null) {
                    firstValue = value;
                }
                values.getChildren().remove(value);
            }

            if (!values.getChildren().isEmpty()) {
                featureTableViewer.setSelection(new StructuredSelection(values.getChildren().get(0)));
            }

            if (choiceTreeViewer != null) {
                choiceTreeViewer.setSelection(selection);
            } else if (choiceText != null) {
                if (firstValue != null) {
                    String value = EcoreUtil.convertToString((EDataType) eClassifier, firstValue);
                    choiceText.setText(value);
                }
            }
            choiceTreeViewer.refresh();
        }
    });

    return contents;
}

From source file:org.eclipse.umlgen.dsl.eth.presentation.connectors.ConnectorsEditorDialog.java

License:Open Source License

/**
 * {@inheritDoc}/*from   ww w  .  j  a v a 2  s .c om*/
 *
 * @see org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite contents = new Composite(parent, SWT.NONE);
    {
        GridLayout layout = new GridLayout();
        layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
        layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
        layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
        layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
        contents.setLayout(layout);
        contents.setLayoutData(new GridData(GridData.FILL_BOTH));
        applyDialogFont(contents);
    }

    GridLayout contentsGridLayout = (GridLayout) contents.getLayout();
    contentsGridLayout.numColumns = 3;

    GridData contentsGridData = (GridData) contents.getLayoutData();
    contentsGridData.horizontalAlignment = SWT.FILL;
    contentsGridData.verticalAlignment = SWT.FILL;

    Text patternText = null;

    if (choiceOfValues != null) {
        Group filterGroupComposite = new Group(contents, SWT.NONE);
        filterGroupComposite.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_pattern_group"));
        filterGroupComposite.setLayout(new GridLayout(2, false));
        filterGroupComposite.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 3, 1));

        Label label = new Label(filterGroupComposite, SWT.NONE);
        label.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_pattern_label"));

        patternText = new Text(filterGroupComposite, SWT.BORDER);
        patternText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }

    Composite choiceComposite = new Composite(contents, SWT.NONE);
    {
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
        data.horizontalAlignment = SWT.END;
        choiceComposite.setLayoutData(data);

        GridLayout layout = new GridLayout();
        data.horizontalAlignment = SWT.FILL;
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 1;
        choiceComposite.setLayout(layout);

    }

    Label choiceLabel = new Label(choiceComposite, SWT.NONE);
    choiceLabel.setText(choiceOfValues == null ? EMFEditUIPlugin.INSTANCE.getString("_UI_Value_label")
            : EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_label"));
    GridData choiceLabelGridData = new GridData();
    choiceLabelGridData.verticalAlignment = SWT.FILL;
    choiceLabelGridData.horizontalAlignment = SWT.FILL;
    choiceLabel.setLayoutData(choiceLabelGridData);

    final Tree choiceTable = choiceOfValues == null ? null : new Tree(choiceComposite, SWT.MULTI | SWT.BORDER);
    if (choiceTable != null) {
        GridData choiceTableGridData = new GridData();
        choiceTableGridData.widthHint = Display.getCurrent().getBounds().width / 5;
        choiceTableGridData.heightHint = Display.getCurrent().getBounds().height / 3;
        choiceTableGridData.verticalAlignment = SWT.FILL;
        choiceTableGridData.horizontalAlignment = SWT.FILL;
        choiceTableGridData.grabExcessHorizontalSpace = true;
        choiceTableGridData.grabExcessVerticalSpace = true;
        choiceTable.setLayoutData(choiceTableGridData);
    }

    final TreeViewer choiceTreeViewer = choiceOfValues == null ? null : new TreeViewer(choiceTable);
    if (choiceOfValues != null) {
        choiceTreeViewer.setContentProvider(new ConnectorsChoiceAdapterFactoryContentProvider(
                new TreeItemProviderAdapterFactory(), values.getChildren()));
        choiceTreeViewer.setLabelProvider(
                new ConnectorsChoiceLabelProvider(propertyDescriptor.getLabelProvider(object)));
        final PatternFilter filter = new PatternFilter() {
            @Override
            protected boolean isParentMatch(Viewer viewer, Object element) {
                return viewer instanceof AbstractTreeViewer && super.isParentMatch(viewer, element);
            }
        };
        choiceTreeViewer.addFilter(filter);
        choiceTreeViewer.setComparator(new ViewerComparator());
        assert patternText != null;
        patternText.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                filter.setPattern(((Text) e.widget).getText());
                choiceTreeViewer.refresh();
            }
        });
        choiceTreeViewer.setInput(new ItemProvider(choiceOfValues));

    }

    // We use multi even for a single line because we want to respond to the
    // enter key.
    //
    int style = multiLine ? SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER : SWT.MULTI | SWT.BORDER;
    final Text choiceText = choiceOfValues == null ? new Text(choiceComposite, style) : null;
    if (choiceText != null) {
        GridData choiceTextGridData = new GridData();
        choiceTextGridData.widthHint = Display.getCurrent().getBounds().width / 5;
        choiceTextGridData.verticalAlignment = SWT.BEGINNING;
        choiceTextGridData.horizontalAlignment = SWT.FILL;
        choiceTextGridData.grabExcessHorizontalSpace = true;
        if (multiLine) {
            choiceTextGridData.verticalAlignment = SWT.FILL;
            choiceTextGridData.grabExcessVerticalSpace = true;
        }
        choiceText.setLayoutData(choiceTextGridData);
    }

    Composite controlButtons = new Composite(contents, SWT.NONE);
    GridData controlButtonsGridData = new GridData();
    controlButtonsGridData.verticalAlignment = SWT.FILL;
    controlButtonsGridData.horizontalAlignment = SWT.FILL;
    controlButtons.setLayoutData(controlButtonsGridData);

    GridLayout controlsButtonGridLayout = new GridLayout();
    controlButtons.setLayout(controlsButtonGridLayout);

    new Label(controlButtons, SWT.NONE);

    final Button addButton = new Button(controlButtons, SWT.PUSH);
    addButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Add_label"));
    GridData addButtonGridData = new GridData();
    addButtonGridData.verticalAlignment = SWT.FILL;
    addButtonGridData.horizontalAlignment = SWT.FILL;
    addButton.setLayoutData(addButtonGridData);

    final Button removeButton = new Button(controlButtons, SWT.PUSH);
    removeButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Remove_label"));
    GridData removeButtonGridData = new GridData();
    removeButtonGridData.verticalAlignment = SWT.FILL;
    removeButtonGridData.horizontalAlignment = SWT.FILL;
    removeButton.setLayoutData(removeButtonGridData);

    Label spaceLabel = new Label(controlButtons, SWT.NONE);
    GridData spaceLabelGridData = new GridData();
    spaceLabelGridData.verticalSpan = 2;
    spaceLabel.setLayoutData(spaceLabelGridData);

    Composite featureComposite = new Composite(contents, SWT.NONE);
    {
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
        data.horizontalAlignment = SWT.END;
        featureComposite.setLayoutData(data);

        GridLayout layout = new GridLayout();
        data.horizontalAlignment = SWT.FILL;
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 1;
        featureComposite.setLayout(layout);
    }

    Label featureLabel = new Label(featureComposite, SWT.NONE);
    featureLabel.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Feature_label"));
    GridData featureLabelGridData = new GridData();
    featureLabelGridData.horizontalSpan = 2;
    featureLabelGridData.horizontalAlignment = SWT.FILL;
    featureLabelGridData.verticalAlignment = SWT.FILL;
    featureLabel.setLayoutData(featureLabelGridData);

    final Tree featureTable = new Tree(featureComposite, SWT.MULTI | SWT.BORDER);
    GridData featureTableGridData = new GridData();
    featureTableGridData.widthHint = Display.getCurrent().getBounds().width / 5;
    featureTableGridData.heightHint = Display.getCurrent().getBounds().height / 3;
    featureTableGridData.verticalAlignment = SWT.FILL;
    featureTableGridData.horizontalAlignment = SWT.FILL;
    featureTableGridData.grabExcessHorizontalSpace = true;
    featureTableGridData.grabExcessVerticalSpace = true;
    featureTable.setLayoutData(featureTableGridData);

    final TreeViewer featureTableViewer = new TreeViewer(featureTable);
    featureTableViewer.setContentProvider(contentProvider);
    featureTableViewer.setLabelProvider(labelProvider);
    featureTableViewer.setComparator(new ViewerComparator());
    featureTableViewer.setInput(values);
    if (!values.getChildren().isEmpty()) {
        featureTableViewer.setSelection(new StructuredSelection(values.getChildren().get(0)));
    }

    if (choiceTreeViewer != null) {
        choiceTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
            public void doubleClick(DoubleClickEvent event) {
                if (addButton.isEnabled()) {
                    addButton.notifyListeners(SWT.Selection, null);
                }
            }
        });

        featureTableViewer.addDoubleClickListener(new IDoubleClickListener() {
            public void doubleClick(DoubleClickEvent event) {
                if (removeButton.isEnabled()) {
                    removeButton.notifyListeners(SWT.Selection, null);
                }
            }
        });
    }

    if (choiceText != null) {
        choiceText.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent event) {
                if (!multiLine && (event.character == '\r' || event.character == '\n')) {
                    try {
                        Object value = EcoreUtil.createFromString((EDataType) eClassifier,
                                choiceText.getText());
                        values.getChildren().add(value);
                        choiceText.setText("");
                        featureTableViewer.setSelection(new StructuredSelection(value));
                        event.doit = false;
                    } catch (RuntimeException exception) {
                        // Ignore
                    }
                } else if (event.character == '\33') {
                    choiceText.setText("");
                    event.doit = false;
                }
            }
        });
    }

    addButton.addSelectionListener(new SelectionAdapter() {
        // event is null when choiceTableViewer is double clicked
        @Override
        public void widgetSelected(SelectionEvent event) {
            if (choiceTreeViewer != null) {
                IStructuredSelection selection = (IStructuredSelection) choiceTreeViewer.getSelection();
                for (Iterator<?> i = selection.iterator(); i.hasNext();) {
                    Object value = i.next();
                    if (isCandidateValue(value)) {
                        values.getChildren().add(value);
                    }
                }
                featureTableViewer.setSelection(selection);
            } else if (choiceText != null) {
                try {
                    Object value = EcoreUtil.createFromString((EDataType) eClassifier, choiceText.getText());
                    if (isCandidateValue(value)) {
                        values.getChildren().add(value);
                        choiceText.setText("");
                    }
                    featureTableViewer.setSelection(new StructuredSelection(value));
                } catch (RuntimeException exception) {
                    // Ignore
                }
            }
            choiceTreeViewer.refresh();
        }
    });

    removeButton.addSelectionListener(new SelectionAdapter() {
        // event is null when featureTableViewer is double clicked
        @Override
        public void widgetSelected(SelectionEvent event) {
            IStructuredSelection selection = (IStructuredSelection) featureTableViewer.getSelection();
            Object firstValue = null;
            for (Iterator<?> i = selection.iterator(); i.hasNext();) {
                Object value = i.next();
                if (firstValue == null) {
                    firstValue = value;
                }
                values.getChildren().remove(value);
            }

            if (!values.getChildren().isEmpty()) {
                featureTableViewer.setSelection(new StructuredSelection(values.getChildren().get(0)));
            }

            if (choiceTreeViewer != null) {
                choiceTreeViewer.setSelection(selection);
            } else if (choiceText != null) {
                if (firstValue != null) {
                    String value = EcoreUtil.convertToString((EDataType) eClassifier, firstValue);
                    choiceText.setText(value);
                }
            }
            choiceTreeViewer.refresh();
        }
    });

    return contents;
}

From source file:org.eclipse.vjet.eclipse.internal.ui.preferences.formatting.CreateProfileDialog.java

License:Open Source License

public Control createDialogArea(Composite parent) {

    final int numColumns = 2;

    GridData gd;/*  w  ww  .  j a  v a 2 s .  c  o  m*/

    final GridLayout layout = new GridLayout(numColumns, false);
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);

    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(layout);

    // Create "Profile name:" label
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = numColumns;
    gd.widthHint = convertWidthInCharsToPixels(60);
    final Label nameLabel = new Label(composite, SWT.WRAP);
    nameLabel.setText(FormatterMessages.CreateProfileDialog_profile_name_label_text);
    nameLabel.setLayoutData(gd);

    // Create text field to enter name
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = numColumns;
    fNameText = new Text(composite, SWT.SINGLE | SWT.BORDER);
    fNameText.setLayoutData(gd);
    fNameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            doValidation();
        }
    });

    // Create "Initialize settings ..." label
    gd = new GridData();
    gd.horizontalSpan = numColumns;
    Label profileLabel = new Label(composite, SWT.WRAP);
    profileLabel.setText(FormatterMessages.CreateProfileDialog_base_profile_label_text);
    profileLabel.setLayoutData(gd);

    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = numColumns;
    fProfileCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
    fProfileCombo.setLayoutData(gd);

    // "Open the edit dialog now" checkbox
    gd = new GridData();
    gd.horizontalSpan = numColumns;
    fEditCheckbox = new Button(composite, SWT.CHECK);
    fEditCheckbox.setText(FormatterMessages.CreateProfileDialog_open_edit_dialog_checkbox_text);
    fEditCheckbox.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            fOpenEditDialog = ((Button) e.widget).getSelection();
        }

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

    final IDialogSettings dialogSettings = VjetUIPlugin.getDefault().getDialogSettings();//.get(PREF_OPEN_EDIT_DIALOG);
    if (dialogSettings.get(PREF_OPEN_EDIT_DIALOG) != null) {
        fOpenEditDialog = dialogSettings.getBoolean(PREF_OPEN_EDIT_DIALOG);
    } else {
        fOpenEditDialog = true;
    }
    fEditCheckbox.setSelection(fOpenEditDialog);

    fProfileCombo.setItems(fSortedNames);
    fProfileCombo.setText(fProfileManager.getDefaultProfile().getName());
    updateStatus(fEmpty);

    applyDialogFont(composite);

    fNameText.setFocus();

    return composite;
}

From source file:org.eclipse.wst.common.frameworks.internal.ui.ErrorDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    // create a composite with standard margins and spacing
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);/*from www.  j  a v a2s.  co  m*/
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setFont(parent.getFont());
    ((GridLayout) composite.getLayout()).numColumns = 2;
    // create image
    Image image = composite.getDisplay().getSystemImage(SWT.ICON_ERROR);
    if (image != null) {
        Label label = new Label(composite, 0);
        image.setBackground(label.getBackground());
        label.setImage(image);
        label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_BEGINNING));
    }
    // create message
    if (message2 != null) {
        Label label = new Label(composite, SWT.WRAP);
        label.setText(message2);
        GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL
                | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
        data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
        label.setLayoutData(data);
        label.setFont(parent.getFont());
    }
    return composite;
}