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

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

Introduction

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

Prototype

public ComboViewer(Composite parent, int style) 

Source Link

Document

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

Usage

From source file:net.sf.logsaw.ui.wizards.SimpleLogResourceWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    Composite root = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(3, false);
    layout.horizontalSpacing = 10;/*from  w w w. ja  v  a  2  s . c o  m*/
    root.setLayout(layout);

    Label label = new Label(root, SWT.NONE);
    label.setText(Messages.SimpleLogResourceWizardPage_label_file);
    fileText = new Text(root, SWT.BORDER);
    fileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    fileDecoration = UIUtils.createErrorDecorator(fileText,
            Messages.SimpleLogResourceWizardPage_error_selectFile);
    Button browseButton = new Button(root, SWT.PUSH);
    browseButton.setText(Messages.SimpleLogResourceWizardPage_label_browse);
    browseButton.addSelectionListener(new SelectionAdapter() {

        /* (non-Javadoc)
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(Display.getDefault().getActiveShell(), SWT.OPEN);
            String file = fd.open();
            if (file != null) {
                // Update text box
                fileText.setText(file);
            }
        }

    });

    fileText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            validateInput();
        }
    });

    Group group = new Group(root, SWT.NONE);
    group.setText(Messages.SimpleLogResourceWizardPage_label_advanced);
    GridData gridData = new GridData(SWT.FILL, SWT.NONE, true, false);
    gridData.horizontalSpan = 3;
    group.setLayoutData(gridData);
    group.setLayout(new GridLayout(2, false));

    label = new Label(group, SWT.NONE);
    label.setText(Messages.SimpleLogResourceWizardPage_label_fileEncoding);

    encodingCombo = new Combo(group, SWT.BORDER);
    encodingDecoration = UIUtils.createErrorDecorator(encodingCombo,
            Messages.SimpleLogResourceWizardPage_error_specifyEncoding);
    List<String> encodings = new ArrayList<String>();
    encodings.add(WorkbenchEncoding.getWorkbenchDefaultEncoding());
    for (Object obj : WorkbenchEncoding.getDefinedEncodings()) {
        encodings.add(obj.toString());
    }
    encodingCombo.setItems(encodings.toArray(new String[encodings.size()]));
    encodingCombo.select(0);
    encodingCombo.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            validateInput();
        }
    });

    label = new Label(group, SWT.NONE);
    label.setText(Messages.SimpleLogResourceWizardPage_label_locale);

    localeCombo = new Combo(group, SWT.BORDER);
    localeDecoration = UIUtils.createErrorDecorator(localeCombo,
            Messages.SimpleLogResourceWizardPage_error_specifyLocale);
    localeCombo.setItems(LocaleUtils.getLocaleIds());
    localeCombo.select(0);
    localeCombo.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            validateInput();
        }
    });

    label = new Label(group, SWT.NONE);
    label.setText(Messages.SimpleLogResourceWizardPage_label_timeZone);

    timeZoneComboViewer = new ComboViewer(group, SWT.BORDER | SWT.READ_ONLY);
    timeZoneDecoration = UIUtils.createErrorDecorator(timeZoneComboViewer.getControl(),
            Messages.SimpleLogResourceWizardPage_error_specifyTimeZone);
    WritableList model = new WritableList(Arrays.asList(UIUtils.getTimeZones()), TimeZone.class);
    ViewerSupport.bind(timeZoneComboViewer, model, PojoProperties.values(new String[] { "displayName" })); //$NON-NLS-1$
    TimeZone defTZ = UIUtils.getDefaultTimeZone();
    if (defTZ != null) {
        timeZoneComboViewer.setSelection(new StructuredSelection(defTZ));
    }

    // Initialize
    fileText.setText(filename != null ? filename : ""); //$NON-NLS-1$

    setControl(root);

    // Bind help context
    PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
            IHelpContexts.SIMPLE_LOG_RESOURCE_WIZARD_PAGE);
}

From source file:net.sf.rcer.conn.ui.login.LoginDialog.java

License:Open Source License

/**
 * Creates the UI elements. /*from  w ww  . j  av  a2s.c  o  m*/
 * @param composite
 */
private void createUserInterface(Composite composite) {
    GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);

    Composite grid = new Composite(composite, SWT.NONE);
    grid.setFont(composite.getFont());
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(grid);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(grid);

    Label connectionLabel = new Label(grid, SWT.NONE);
    connectionLabel.setText(Messages.LoginDialog_ConnectionLabel);

    connectionComboViewer = new ComboViewer(grid, SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(connectionComboViewer.getControl());

    Label clientLabel = new Label(grid, SWT.NONE);
    clientLabel.setText(Messages.LoginDialog_ClientLabel);

    clientText = new Text(grid, SWT.BORDER | SWT.SINGLE);
    clientText.setTextLimit(3);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(clientText);

    Label userLabel = new Label(grid, SWT.NONE);
    userLabel.setText(Messages.LoginDialog_UserLabel);

    userText = new Text(grid, SWT.BORDER | SWT.SINGLE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(userText);

    Label passwordLabel = new Label(grid, SWT.NONE);
    passwordLabel.setText(Messages.LoginDialog_PasswordLabel);

    passwordText = new Text(grid, SWT.BORDER | SWT.SINGLE);
    passwordText.setEchoChar('*');
    GridDataFactory.fillDefaults().grab(true, false).applyTo(passwordText);

    Label localeLabel = new Label(grid, SWT.NONE);
    localeLabel.setText(Messages.LoginDialog_LocaleLabel);

    localeCombo = new Combo(grid, SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(localeCombo);
}

From source file:net.sf.wickedshell.ui.preferences.WickedShellPreferencePage.java

License:Open Source License

/**
 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
 *//*ww  w  .  ja va2  s  .  co  m*/
public Control createContents(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    final GridLayout gridLayoutContainer = new GridLayout();
    gridLayoutContainer.marginWidth = 2;
    gridLayoutContainer.horizontalSpacing = 2;
    gridLayoutContainer.marginHeight = 2;
    container.setLayout(gridLayoutContainer);

    final Group groupShellSettings = new Group(container, SWT.NONE);
    final GridLayout gridLayoutShell = new GridLayout();
    gridLayoutShell.numColumns = 3;
    groupShellSettings.setLayout(gridLayoutShell);
    groupShellSettings.setText("Static Shell settings");
    groupShellSettings.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));

    final Label labelShell = new Label(groupShellSettings, SWT.NONE);
    labelShell.setLayoutData(new GridData());
    labelShell.setText("Default Static Shell:");

    comboViewerShellDescriptor = new ComboViewer(groupShellSettings, SWT.READ_ONLY);
    final Combo comboShellDescriptor = comboViewerShellDescriptor.getCombo();
    comboShellDescriptor.setToolTipText(
            "Please select the shell to be used. Ensure the selected shell to be installed and the executable is referenced in the path.");
    comboShellDescriptor.select(0);
    comboViewerShellDescriptor.setContentProvider(new ArrayContentProvider());
    comboViewerShellDescriptor.setLabelProvider(new ShellDescriptorLabelProvider());
    comboViewerShellDescriptor.addFilter(new ViewerFilter() {
        /**
         * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer,
         *      java.lang.Object, java.lang.Object)
         */
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            IShellDescriptor descriptor = (IShellDescriptor) element;
            return descriptor.isCurrentOSSupported();
        }
    });

    final GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1);
    gridData.horizontalIndent = 25;
    comboShellDescriptor.setLayoutData(gridData);

    final Label labelShellRootDirectory = new Label(groupShellSettings, SWT.NONE);
    labelShellRootDirectory.setText("Shell root directory:");

    textShellRootDirectory = new Text(groupShellSettings, SWT.BORDER);
    textShellRootDirectory.setToolTipText(
            "If you use an installed shell with a specific root directory, please enter this root directory here.");
    final GridData gridDataTextShellRootDirectory = new GridData(GridData.FILL, GridData.CENTER, true, false);
    gridDataTextShellRootDirectory.horizontalIndent = 25;
    textShellRootDirectory.setLayoutData(gridDataTextShellRootDirectory);

    buttonBrowseShellRootDirectory = new Button(groupShellSettings, SWT.NONE);
    buttonBrowseShellRootDirectory.setText("Browse...");
    buttonBrowseShellRootDirectory.addSelectionListener(new SelectionAdapter() {
        /**
         * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        public void widgetSelected(SelectionEvent selectionEvent) {
            DirectoryDialog shellRootDirectorySelectionDialog = new DirectoryDialog(getShell());
            String shellRootDirectory = shellRootDirectorySelectionDialog.open();
            if (shellRootDirectory != null) {
                textShellRootDirectory.setText(shellRootDirectory);
            }
        }
    });

    comboViewerShellDescriptor.addSelectionChangedListener(new ISelectionChangedListener() {
        /**
         * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
         */
        public void selectionChanged(SelectionChangedEvent event) {
            if (!event.getSelection().isEmpty()) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                IShellDescriptor descriptor = (IShellDescriptor) selection.getFirstElement();
                if (descriptor.hasCustomRoot()) {
                    textShellRootDirectory.setEnabled(true);
                    buttonBrowseShellRootDirectory.setEnabled(true);
                    IShellDescriptorProperties shellDescriptorProperties = DomainPlugin.getDefault()
                            .getShellDescriptorProperties(descriptor.getId());
                    textShellRootDirectory.setText(shellDescriptorProperties.getRootDirectory());

                } else {
                    textShellRootDirectory.setText(new String());
                    textShellRootDirectory.setEnabled(false);
                    buttonBrowseShellRootDirectory.setEnabled(false);
                }
            } else {
                textShellRootDirectory.setText(new String());
                textShellRootDirectory.setEnabled(false);
                buttonBrowseShellRootDirectory.setEnabled(false);
            }
        }
    });

    // Set the viewer's inputs
    try {
        comboViewerShellDescriptor.setInput(IShellDescriptor.Manager.getStaticShellDescriptors());
        IShellDescriptor shellDescriptor = PreferenceHelper.getActiveShellDescriptor();
        IShellDescriptorProperties shellDescriptorProperties = DomainPlugin.getDefault()
                .getShellDescriptorProperties(shellDescriptor.getId());
        comboViewerShellDescriptor.setSelection(new StructuredSelection(shellDescriptor));
        textShellRootDirectory.setText(shellDescriptorProperties.getRootDirectory());

    } catch (Exception exception) {
        shellLogger.error(exception.getMessage(), exception);
    }

    final Group groupStartupSettings = new Group(container, SWT.NONE);
    groupStartupSettings.setText("Startup settings (if supported by selected Shell)");
    groupStartupSettings.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    final GridLayout gridLayoutGroupStartupSettings = new GridLayout();
    gridLayoutGroupStartupSettings.numColumns = 3;
    groupStartupSettings.setLayout(gridLayoutGroupStartupSettings);

    buttonUseWorkspaceAsStartupDirectory = new Button(groupStartupSettings, SWT.CHECK);
    buttonUseWorkspaceAsStartupDirectory.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
    buttonUseWorkspaceAsStartupDirectory.setText("Use workspace as startup directory");
    buttonUseWorkspaceAsStartupDirectory.setSelection(ShellPlugin.getDefault().getPreferenceStore()
            .getBoolean(ShellID.USE_WORKSPACE_AS_STARTUP_DIRECTORY_STRING_KEY));
    buttonUseWorkspaceAsStartupDirectory.addSelectionListener(new SelectionAdapter() {
        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        public void widgetSelected(SelectionEvent event) {
            if (buttonUseWorkspaceAsStartupDirectory.getSelection()) {
                textCustomStartupDirectory.setText(new String());
            } else {
                textCustomStartupDirectory.setText(ShellPlugin.getDefault().getPreferenceStore()
                        .getString(ShellID.CUSTOM_STARTUP_DIRECTORY_STRING_KEY));
            }
            textCustomStartupDirectory.setEnabled(!buttonUseWorkspaceAsStartupDirectory.getSelection());
            buttonBrowseCustomStartupDirectory.setEnabled(!buttonUseWorkspaceAsStartupDirectory.getSelection());
        }
    });

    final Label customStartupDirectoryLabel = new Label(groupStartupSettings, SWT.NONE);
    customStartupDirectoryLabel.setText("Custom startup directory:");

    textCustomStartupDirectory = new Text(groupStartupSettings, SWT.BORDER);
    textCustomStartupDirectory.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    textCustomStartupDirectory.setText(ShellPlugin.getDefault().getPreferenceStore()
            .getString(ShellID.CUSTOM_STARTUP_DIRECTORY_STRING_KEY));
    textCustomStartupDirectory.setEnabled(!buttonUseWorkspaceAsStartupDirectory.getSelection());

    buttonBrowseCustomStartupDirectory = new Button(groupStartupSettings, SWT.NONE);
    buttonBrowseCustomStartupDirectory.setText("Browse...");
    buttonBrowseCustomStartupDirectory.setEnabled(!buttonUseWorkspaceAsStartupDirectory.getSelection());
    buttonBrowseCustomStartupDirectory.addSelectionListener(new SelectionAdapter() {
        /**
         * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        public void widgetSelected(SelectionEvent selectionEvent) {
            DirectoryDialog shellCustomStartupDirectorySelectionDialog = new DirectoryDialog(getShell());
            String customStartupDirectory = shellCustomStartupDirectorySelectionDialog.open();
            if (customStartupDirectory != null) {
                textCustomStartupDirectory.setText(customStartupDirectory);
            }
        }
    });
    // Set the viewer's input
    return container;
}

From source file:net.sourceforge.eclipseccase.ui.dialogs.ActivityDialog.java

License:Open Source License

protected ComboViewer createComboViewer(Composite composite, String[] activities) {
    ComboViewer comboViewer = new ComboViewer(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
    comboViewer.setLabelProvider(new ActivityListLabelProvider());
    comboViewer.setContentProvider(new ArrayContentProvider());
    comboViewer.setInput(activities);/*from   w ww.  j  a  v a  2s.  c  o m*/
    // comboViewer.setSorter(new ViewerSorter() {
    // @Override
    // public int compare(Viewer viewer, Object p1, Object p2) {
    // return ((Activity) p1).getHeadline().compareToIgnoreCase(((Activity)
    // p2).getHeadline());
    // }
    //
    // });

    return comboViewer;
}

From source file:net.sourceforge.eclipseccase.ui.dialogs.SelectViewDialog.java

License:Open Source License

protected ComboViewer createComboViewer(Composite composite, String[] activities) {
    ComboViewer comboViewer = new ComboViewer(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
    comboViewer.setLabelProvider(new ActivityListLabelProvider());
    comboViewer.setContentProvider(new ArrayContentProvider());
    comboViewer.setInput(views);//  w w w  . j av  a  2 s .  c om

    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
    comboViewer.getCombo().setLayoutData(data);

    return comboViewer;
}

From source file:net.sourceforge.eclipseccase.ui.wizards.MergeWizardPage.java

License:Open Source License

protected void createComboViewer(Composite composite) {
    final ComboViewer comboViewer = new ComboViewer(composite, SWT.SIMPLE | SWT.READ_ONLY | SWT.SCROLL_PAGE);
    comboViewer.setLabelProvider(new MergeLabelProvider());
    comboViewer.setContentProvider(new ArrayContentProvider());
    loadBranches();//ww  w.j a v  a2s.c  o  m
    comboViewer.setInput(branches);
    if (comboViewer.getSelection().isEmpty()) {
        comboViewer.getCombo().select(0);
        setSelectedBranch(comboViewer.getCombo().getText());
    }

    AutocompleteComboViewerInput ac = new AutocompleteComboViewerInput(comboViewer);

    //Handles selections in the dd-list when not utilizing autocomplete.
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (!selection.isEmpty()) {
                setSelectedBranch((String) (selection.getFirstElement()));
            } else {

            }
        }
    });

    composite.setToolTipText("To select branch, type the name and search will narrow.");

}

From source file:net.sourceforge.eclipsetrader.ats.ui.tradingsystem.properties.GeneralPage.java

License:Open Source License

protected Control createContents(Composite parent) {
    Composite content = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout(2, false);
    gridLayout.marginWidth = gridLayout.marginHeight = 0;
    content.setLayout(gridLayout);/*from  w ww  .  ja  v  a  2 s.  co  m*/
    content.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));

    Label label = new Label(content, SWT.NONE);
    label.setText("Name");
    label.setLayoutData(new GridData(127, SWT.DEFAULT));
    name = new Text(content, SWT.BORDER);
    name.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    name.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            setValid(isValid());
        }
    });

    label = new Label(content, SWT.NONE);
    label.setText("Account");
    label.setLayoutData(new GridData(127, SWT.DEFAULT));
    account = new ComboViewer(content, SWT.READ_ONLY);
    account.getControl().setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    account.setContentProvider(new ArrayContentProvider());
    account.setLabelProvider(new LabelProvider() {
        public String getText(Object element) {
            return ((Account) element).getDescription();
        }
    });
    account.setInput(CorePlugin.getRepository().allAccounts().toArray());
    account.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            setValid(isValid());
        }
    });

    label = new Label(content, SWT.NONE);
    label.setText("Trading Provider");
    label.setLayoutData(new GridData(127, SWT.DEFAULT));
    tradingProvider = new ComboViewer(content, SWT.READ_ONLY);
    tradingProvider.getControl().setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    tradingProvider.setContentProvider(new ArrayContentProvider());
    tradingProvider.setLabelProvider(new LabelProvider() {
        public String getText(Object element) {
            return ((IConfigurationElement) element).getAttribute("name");
        }
    });
    tradingProvider.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            setValid(isValid());
        }
    });

    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint extensionPoint = registry.getExtensionPoint(CorePlugin.TRADING_PROVIDERS_EXTENSION_POINT);
    if (extensionPoint != null)
        tradingProvider.setInput(extensionPoint.getConfigurationElements());

    performDefaults();

    return content;
}

From source file:net.sourceforge.eclipsetrader.ats.ui.tradingsystem.wizards.GeneralPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite content = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout(2, false);
    gridLayout.marginWidth = gridLayout.marginHeight = 0;
    content.setLayout(gridLayout);/*from ww w  .j av a2s .  c o  m*/
    content.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    setControl(content);

    Label label = new Label(content, SWT.NONE);
    label.setText("Name");
    label.setLayoutData(new GridData(127, SWT.DEFAULT));
    name = new Text(content, SWT.BORDER);
    name.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    name.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            setPageComplete(isPageComplete());
        }
    });

    label = new Label(content, SWT.NONE);
    label.setText("Account");
    label.setLayoutData(new GridData(127, SWT.DEFAULT));
    account = new ComboViewer(content, SWT.READ_ONLY);
    account.getControl().setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    account.setContentProvider(new ArrayContentProvider());
    account.setLabelProvider(new LabelProvider() {
        public String getText(Object element) {
            return ((Account) element).getDescription();
        }
    });
    account.setInput(CorePlugin.getRepository().allAccounts().toArray());
    account.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            setPageComplete(isPageComplete());
        }
    });

    label = new Label(content, SWT.NONE);
    label.setText("Trading Provider");
    label.setLayoutData(new GridData(127, SWT.DEFAULT));
    tradingProvider = new ComboViewer(content, SWT.READ_ONLY);
    tradingProvider.getControl().setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    tradingProvider.setContentProvider(new ArrayContentProvider());
    tradingProvider.setLabelProvider(new LabelProvider() {
        public String getText(Object element) {
            return ((IConfigurationElement) element).getAttribute("name");
        }
    });
    tradingProvider.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            setPageComplete(isPageComplete());
        }
    });

    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint extensionPoint = registry.getExtensionPoint(CorePlugin.TRADING_PROVIDERS_EXTENSION_POINT);
    if (extensionPoint != null)
        tradingProvider.setInput(extensionPoint.getConfigurationElements());
}

From source file:net.ssehub.easy.producer.ui.productline_editor.instantiator.InsertInstantiatorDialog.java

License:Apache License

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(1, true);
    composite.setLayout(layout);//from  w  ww  .  jav a 2s.  co  m
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    applyDialogFont(composite);

    Label label = new Label(composite, SWT.NONE);
    label.setText("Available instantiators");

    combo = new ComboViewer(composite, SWT.SINGLE);
    combo.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((IMetaOperation) element).getSignature();
        }
    });
    for (IMetaOperation op : sortedInstantiators()) {
        combo.add(op);
    }
    combo.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
                IMetaOperation op = (IMetaOperation) ((IStructuredSelection) selection).getFirstElement();
                fillParams(op);
            }
        }
    });

    label = new Label(composite, SWT.NONE);
    label.setText("Parameters / Arguments:");

    params = new TableViewer(composite, SWT.VERTICAL);
    Table table = params.getTable();
    GridData tGridData = new GridData(GridData.FILL_BOTH);
    tGridData.minimumHeight = 100;
    table.setLayoutData(tGridData);
    TableLayout tLayout = new TableLayout();
    table.setLayout(tLayout);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    tLayout.addColumnData(new ColumnWeightData(3, 50, true));
    TableViewerColumn tableViewerColumn = new TableViewerColumn(params, SWT.NONE);
    tableViewerColumn.getColumn().setText("type");
    tableViewerColumn.getColumn().setResizable(true);

    tLayout.addColumnData(new ColumnWeightData(3, 50, true));
    tableViewerColumn = new TableViewerColumn(params, SWT.NONE);
    tableViewerColumn.getColumn().setText("argument");
    tableViewerColumn.getColumn().setResizable(true);
    tableViewerColumn.setEditingSupport(new ArgumentEditingSupport(params));

    params.setLabelProvider(new ParamTableLabelProvider());
    params.setContentProvider(new ParamTableContentProvider());

    // TODO support named arguments

    before = new Button(composite, SWT.CHECK);
    before.setText("Insert before selected element (after if unselected)");
    if (InsertionPoint.BEFORE_THIS == insertionPoint) {
        before.setSelection(true);
    } else {
        before.setSelection(false);
    }
    return composite;
}

From source file:net.texo.USDLSecurityEditor.PageBuilder.java

License:Open Source License

/**
 * Creates the security mechanism group.
 *
 * @param parent the parent//from   w ww .  ja  v  a  2s  .co m
 * @param aspect the aspect
 * @param action the action
 * @return the group
 */
public Group createSecurityMechanismGroup(final Composite parent, final SecurityAspect aspect,
        final SecurityMechanism action) {

    if (parent == null)
        return null;
    if (aspect == null)
        return null;
    if (action == null)
        return null;

    Group gAction = new Group(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(gAction);
    gAction.setText(action.getType().getLiteral());

    Font font = gAction.getFont();
    FontData[] fd = font.getFontData();
    for (int i = 0; i < fd.length; ++i) {
        fd[i].setStyle(SWT.BOLD);
    }
    Font newFont = new Font(parent.getDisplay(), fd);
    gAction.setFont(newFont);

    toolkit.createLabel(gAction, "Requirement Level: ");
    Composite cReqLvlMarker = toolkit.createComposite(gAction);
    RowLayoutFactory.swtDefaults().applyTo(cReqLvlMarker);

    ComboViewer cvReqLevel = new ComboViewer(cReqLvlMarker, SWT.READ_ONLY);
    cvReqLevel.setContentProvider(ArrayContentProvider.getInstance());
    ArrayList<String> list = new ArrayList<String>();
    for (Iterator<SecurityRequirementLevel> j = SecurityRequirementLevel.VALUES.iterator(); j.hasNext();) {
        list.add(j.next().getLiteral());
    }
    cvReqLevel.setInput(list);
    cvReqLevel.addSelectionChangedListener(new ReqLevelForActionListener(editor, aspect, action));
    cvReqLevel.setSelection(new StructuredSelection(
            ((SecurityMechanism) editor.model.getRealizingAction(aspect.getType(), action.getType())).getLevel()
                    .getName()));

    Label lMarker = toolkit.createLabel(cReqLvlMarker, "");
    lMarker.setVisible(false);
    //lMarker.setImage(Activator.getImageDescriptor(ISharedImages.IMG_OBJS_WARN_TSK).createImage());
    lMarker.setImage(Activator.getImageDescriptor("icons/warning.png").createImage());

    toolkit.createLabel(gAction, "Supported Mechanisms: ");
    List lMechanisms = new List(gAction, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
    GridDataFactory.swtDefaults().hint(300, 45).applyTo(lMechanisms);
    lMechanisms.setEnabled(true);

    /** TODO **/
    SecurityMechanismProxy pAction = new SecurityMechanismProxy(editor, aspect, (SecurityMechanism) action,
            gAction, cvReqLevel, lMarker, lMechanisms);
    editor.ActionProxies.put(action, pAction);
    /****/

    return gAction;
}