Search in sources :

Example 6 with ExpandableComposite

use of org.eclipse.ui.forms.widgets.ExpandableComposite in project yamcs-studio by yamcs.

the class AddToStackWizardPage2 method createControl.

@Override
public void createControl(Composite parent) {
    controlComposite = new Composite(parent, SWT.NONE);
    setControl(controlComposite);
    controlComposite.setLayout(new GridLayout());
    // command namespace selection
    Composite namespaceComposite = new Composite(controlComposite, SWT.NONE);
    namespaceComposite.setLayout(new GridLayout(2, false));
    Label chooseNamespace = new Label(namespaceComposite, SWT.NONE);
    chooseNamespace.setText("Choose Command Namespace: ");
    namespaceCombo = new Combo(namespaceComposite, SWT.READ_ONLY);
    namespaceCombo.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            command.setSelectedAliase(aliases.get(namespaceCombo.getSelectionIndex()));
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    // expandable command options
    ExpandableComposite ec = new ExpandableComposite(controlComposite, ExpandableComposite.TREE_NODE | ExpandableComposite.CLIENT_INDENT);
    ec.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    ec.setLayout(new GridLayout(1, false));
    ec.setExpanded(false);
    ec.setText("Command Options");
    Composite optionsComposite = new Composite(ec, SWT.NONE);
    optionsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    optionsComposite.setLayout(new GridLayout(2, false));
    Label l1 = new Label(optionsComposite, SWT.NONE);
    l1.setText("Comment");
    GridData gridData = new GridData(SWT.NONE, SWT.TOP, false, false);
    l1.setLayoutData(gridData);
    Text comment = new Text(optionsComposite, SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    comment.setText(command.getComment() != null ? command.getComment() : "");
    gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gridData.heightHint = 2 * comment.getLineHeight();
    comment.setLayoutData(gridData);
    ec.setClient(optionsComposite);
    ec.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            parent.layout(true);
            controlComposite.layout(true);
        }
    });
    comment.addModifyListener(evt -> {
        if (comment.getText().trim().isEmpty()) {
            command.setComment(null);
        } else {
            command.setComment(comment.getText());
        }
    });
    // argument table
    atb = new ArgumentTableBuilder(command);
    atb.createArgumentTable(controlComposite);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 7 with ExpandableComposite

use of org.eclipse.ui.forms.widgets.ExpandableComposite in project yamcs-studio by yamcs.

the class EditStackedCommandDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setLayout(new GridLayout());
    // command namespace selection
    // populate namespace combo
    // (switching ops name and qualified name)
    List<String> aliases = new ArrayList<String>();
    aliases.add(command.getMetaCommand().getQualifiedName());
    for (NamedObjectId noi : command.getMetaCommand().getAliasList()) {
        String alias = noi.getNamespace() + "/" + noi.getName();
        if (alias.equals(command.getMetaCommand().getQualifiedName()))
            continue;
        aliases.add(alias);
    }
    Composite namespaceComposite = new Composite(composite, SWT.NONE);
    namespaceComposite.setLayout(new GridLayout(2, false));
    Label chooseNamespace = new Label(namespaceComposite, SWT.NONE);
    chooseNamespace.setText("Choose Command Namespace: ");
    Combo namespaceCombo = new Combo(namespaceComposite, SWT.READ_ONLY);
    namespaceCombo.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            command.setSelectedAliase(aliases.get(namespaceCombo.getSelectionIndex()));
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    namespaceCombo.setItems(aliases.toArray(new String[aliases.size()]));
    for (int i = 0; i < aliases.size(); i++) {
        if (aliases.get(i).equals(command.getSelectedAlias())) {
            namespaceCombo.select(i);
        }
    }
    ExpandableComposite ec = new ExpandableComposite(composite, ExpandableComposite.TREE_NODE | ExpandableComposite.CLIENT_INDENT);
    ec.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    ec.setLayout(new GridLayout(1, false));
    ec.setText("Command Options");
    Composite optionsComposite = new Composite(ec, SWT.NONE);
    optionsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    optionsComposite.setLayout(new GridLayout(2, false));
    Label l1 = new Label(optionsComposite, SWT.NONE);
    l1.setText("Comment");
    GridData gridData = new GridData(SWT.NONE, SWT.TOP, false, false);
    l1.setLayoutData(gridData);
    Text comment = new Text(optionsComposite, SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    comment.setText(command.getComment() != null ? command.getComment() : "");
    ec.setExpanded(!comment.getText().isEmpty());
    gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gridData.heightHint = 2 * comment.getLineHeight();
    comment.setLayoutData(gridData);
    ec.setClient(optionsComposite);
    ec.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            parent.layout(true);
            composite.layout();
            optionsComposite.layout();
        }
    });
    comment.addModifyListener(evt -> {
        if (comment.getText().trim().isEmpty()) {
            command.setComment(null);
        } else {
            command.setComment(comment.getText());
        }
    });
    atb = new ArgumentTableBuilder(command);
    atb.createArgumentTable(composite);
    atb.updateCommandArguments();
    atb.pack();
    return composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ArrayList(java.util.ArrayList) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NamedObjectId(org.yamcs.protobuf.Yamcs.NamedObjectId) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)7 GridData (org.eclipse.swt.layout.GridData)6 Composite (org.eclipse.swt.widgets.Composite)5 ArrayList (java.util.ArrayList)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Action (org.eclipse.jface.action.Action)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 FormAttachment (org.eclipse.swt.layout.FormAttachment)2 FormData (org.eclipse.swt.layout.FormData)2 FormLayout (org.eclipse.swt.layout.FormLayout)2 Combo (org.eclipse.swt.widgets.Combo)2 Label (org.eclipse.swt.widgets.Label)2 Text (org.eclipse.swt.widgets.Text)2 ExpansionAdapter (org.eclipse.ui.forms.events.ExpansionAdapter)2 ExpansionEvent (org.eclipse.ui.forms.events.ExpansionEvent)2 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 FormToolkit (org.eclipse.ui.forms.widgets.FormToolkit)1