Search in sources :

Example 1 with AddRemoveListener

use of org.bndtools.utils.swt.AddRemoveButtonBarPart.AddRemoveListener in project bndtools by bndtools.

the class RunPropertiesPart method createSection.

private void createSection(Section section, FormToolkit toolkit) {
    section.setText("Runtime Properties");
    final Composite composite = toolkit.createComposite(section);
    section.setClient(composite);
    // Create controls: Run Properties
    Label lblRunProperties = toolkit.createLabel(composite, "OSGi Framework properties:");
    tblRunProperties = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewRunProperties = new TableViewer(tblRunProperties);
    runPropertiesModifier = new MapEntryCellModifier<>(viewRunProperties);
    tblRunProperties.setHeaderVisible(true);
    final TableColumn tblRunPropsCol1 = new TableColumn(tblRunProperties, SWT.NONE);
    tblRunPropsCol1.setText("Name");
    tblRunPropsCol1.setWidth(100);
    final TableColumn tblRunPropsCol2 = new TableColumn(tblRunProperties, SWT.NONE);
    tblRunPropsCol1.setText("Value");
    tblRunPropsCol1.setWidth(100);
    viewRunProperties.setUseHashlookup(true);
    viewRunProperties.setColumnProperties(MapEntryCellModifier.getColumnProperties());
    runPropertiesModifier.addCellEditorsToViewer();
    viewRunProperties.setCellModifier(runPropertiesModifier);
    viewRunProperties.setContentProvider(new MapContentProvider());
    viewRunProperties.setLabelProvider(new PropertiesTableLabelProvider());
    Control createRemovePropsToolBar = createRemovePropsPart.createControl(composite, SWT.FLAT | SWT.VERTICAL);
    // Create controls: program args
    Label lblProgramArgs = toolkit.createLabel(composite, "Launcher Arguments:");
    txtProgramArgs = toolkit.createText(composite, "", SWT.MULTI | SWT.BORDER);
    ToolTips.setupMessageAndToolTipFromSyntax(txtProgramArgs, Constants.RUNPROGRAMARGS);
    // Create controls: vm args
    Label lblVmArgs = toolkit.createLabel(composite, "JVM Arguments:");
    txtVmArgs = toolkit.createText(composite, "", SWT.MULTI | SWT.BORDER);
    ToolTips.setupMessageAndToolTipFromSyntax(txtVmArgs, Constants.RUNVM);
    // Layout
    GridLayout gl;
    GridData gd;
    gl = new GridLayout(2, false);
    gl.marginWidth = 0;
    gl.marginHeight = 0;
    composite.setLayout(gl);
    lblRunProperties.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    gd.heightHint = 50;
    gd.widthHint = 50;
    tblRunProperties.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.TOP, false, true);
    createRemovePropsToolBar.setLayoutData(gd);
    lblProgramArgs.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd.heightHint = 40;
    gd.widthHint = 50;
    txtProgramArgs.setLayoutData(gd);
    lblVmArgs.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd.heightHint = 40;
    gd.widthHint = 50;
    txtVmArgs.setLayoutData(gd);
    // Listeners
    viewRunProperties.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            createRemovePropsPart.setRemoveEnabled(!viewRunProperties.getSelection().isEmpty());
        }
    });
    createRemovePropsPart.addListener(new AddRemoveListener() {

        @Override
        public void addSelected() {
            runProperties.put("name", "");
            viewRunProperties.add("name");
            markDirty();
            viewRunProperties.editElement("name", 0);
        }

        @Override
        public void removeSelected() {
            @SuppressWarnings("rawtypes") Iterator iter = ((IStructuredSelection) viewRunProperties.getSelection()).iterator();
            while (iter.hasNext()) {
                Object item = iter.next();
                runProperties.remove(item);
                viewRunProperties.remove(item);
            }
            markDirty();
        }
    });
    runPropertiesModifier.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            markDirty();
        }
    });
    txtProgramArgs.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent ev) {
            lock.ifNotModifying(new Runnable() {

                @Override
                public void run() {
                    markDirty();
                    programArgs = txtProgramArgs.getText();
                    if (programArgs.length() == 0)
                        programArgs = null;
                }
            });
        }
    });
    txtVmArgs.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent ev) {
            lock.ifNotModifying(new Runnable() {

                @Override
                public void run() {
                    markDirty();
                    vmArgs = txtVmArgs.getText();
                    if (vmArgs.length() == 0)
                        vmArgs = null;
                }
            });
        }
    });
    composite.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            Rectangle area = composite.getClientArea();
            Point preferredSize = tblRunProperties.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            int width = area.width - 2 * tblRunProperties.getBorderWidth();
            if (preferredSize.y > area.height + tblRunProperties.getHeaderHeight()) {
                // Subtract the scrollbar width from the total column width
                // if a vertical scrollbar will be required
                Point vBarSize = tblRunProperties.getVerticalBar().getSize();
                width -= vBarSize.x;
            }
            Point oldSize = tblRunProperties.getSize();
            if (oldSize.x > area.width) {
                // table is getting smaller so make the columns
                // smaller first and then resize the table to
                // match the client area width
                tblRunPropsCol1.setWidth(width / 3);
                tblRunPropsCol2.setWidth(width - tblRunPropsCol1.getWidth());
                tblRunProperties.setSize(area.width, area.height);
            } else {
                // table is getting bigger so make the table
                // bigger first and then make the columns wider
                // to match the client area width
                tblRunProperties.setSize(area.width, area.height);
                tblRunPropsCol1.setWidth(width / 3);
                tblRunPropsCol2.setWidth(width - tblRunPropsCol1.getWidth());
            }
        }
    });
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) ModifyListener(org.eclipse.swt.events.ModifyListener) ControlAdapter(org.eclipse.swt.events.ControlAdapter) Label(org.eclipse.swt.widgets.Label) Rectangle(org.eclipse.swt.graphics.Rectangle) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) MapContentProvider(bndtools.editor.common.MapContentProvider) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Iterator(java.util.Iterator) PropertyChangeEvent(java.beans.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Point(org.eclipse.swt.graphics.Point) TableColumn(org.eclipse.swt.widgets.TableColumn) AddRemoveListener(org.bndtools.utils.swt.AddRemoveButtonBarPart.AddRemoveListener) GridData(org.eclipse.swt.layout.GridData) PropertiesTableLabelProvider(bndtools.editor.common.PropertiesTableLabelProvider) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 2 with AddRemoveListener

use of org.bndtools.utils.swt.AddRemoveButtonBarPart.AddRemoveListener in project bndtools by bndtools.

the class ReposPreferencePage method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(1, false);
    layout.marginRight = 10;
    composite.setLayout(layout);
    Group group = new Group(composite, SWT.NONE);
    group.setText("Templates Repositories");
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    group.setLayout(new GridLayout(2, false));
    final Button btnEnableTemplateRepo = new Button(group, SWT.CHECK);
    btnEnableTemplateRepo.setText("Enable templates repositories");
    btnEnableTemplateRepo.setSelection(enableTemplateRepo);
    btnEnableTemplateRepo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    ControlDecoration decoration = new ControlDecoration(btnEnableTemplateRepo, SWT.RIGHT | SWT.TOP, composite);
    decoration.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
    decoration.setMarginWidth(3);
    decoration.setDescriptionText("These repositories are used to load\ntemplates, in addition to repositories\nconfigured in the Bnd OSGi Workspace.");
    decoration.setShowHover(true);
    decoration.setShowOnlyOnFocus(false);
    Label lblRepos = new Label(group, SWT.NONE);
    lblRepos.setText("Repository URLs:");
    lblRepos.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    final Table tblRepos = new Table(group, SWT.BORDER | SWT.MULTI);
    vwrRepos = new TableViewer(tblRepos);
    vwrRepos.setContentProvider(ArrayContentProvider.getInstance());
    vwrRepos.setLabelProvider(new URLLabelProvider(tblRepos.getDisplay()));
    vwrRepos.setInput(templateRepos);
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gd.widthHint = 260;
    gd.heightHint = 80;
    tblRepos.setLayoutData(gd);
    tblRepos.setEnabled(enableTemplateRepo);
    final AddRemoveButtonBarPart addRemoveRepoPart = new AddRemoveButtonBarPart();
    Control addRemovePanel = addRemoveRepoPart.createControl(group, SWT.FLAT | SWT.VERTICAL);
    addRemovePanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    addRemoveRepoPart.setRemoveEnabled(false);
    addRemoveRepoPart.addListener(new AddRemoveListener() {

        @Override
        public void addSelected() {
            doAddRepo();
        }

        @Override
        public void removeSelected() {
            doRemoveRepo();
        }
    });
    vwrRepos.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            addRemoveRepoPart.setRemoveEnabled(!vwrRepos.getSelection().isEmpty());
        }
    });
    tblRepos.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.DEL && e.stateMask == 0)
                doRemoveRepo();
        }
    });
    btnEnableTemplateRepo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            enableTemplateRepo = btnEnableTemplateRepo.getSelection();
            tblRepos.setEnabled(enableTemplateRepo);
            validate();
        }
    });
    return composite;
}
Also used : Group(org.eclipse.swt.widgets.Group) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) AddRemoveButtonBarPart(org.bndtools.utils.swt.AddRemoveButtonBarPart) KeyEvent(org.eclipse.swt.events.KeyEvent) URLLabelProvider(bndtools.shared.URLLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) AddRemoveListener(org.bndtools.utils.swt.AddRemoveButtonBarPart.AddRemoveListener) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 3 with AddRemoveListener

use of org.bndtools.utils.swt.AddRemoveButtonBarPart.AddRemoveListener in project bndtools by bndtools.

the class EditableParametersPart method createControl.

public Control createControl(Composite parent) {
    this.parent = parent;
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    composite.setLayout(layout);
    Label titleLabel = new Label(composite, SWT.NONE);
    titleLabel.setText(title);
    titleLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));
    Table table = new Table(composite, SWT.BORDER | SWT.MULTI);
    viewer = new TableViewer(table);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    final Image iconImg = imageDescriptor.createImage(parent.getDisplay());
    viewer.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            @SuppressWarnings("unchecked") Pair<String, Attrs> entry = (Pair<String, Attrs>) cell.getElement();
            StyledString label = new StyledString(entry.getFirst(), BoldStyler.INSTANCE_DEFAULT);
            for (Entry<String, String> attribEntry : entry.getSecond().entrySet()) {
                label.append("; " + attribEntry.getKey() + "=", StyledString.QUALIFIER_STYLER);
                label.append(attribEntry.getValue());
            }
            cell.setText(label.toString());
            cell.setStyleRanges(label.getStyleRanges());
            cell.setImage(iconImg);
        }
    });
    viewer.setInput(entries);
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gd.widthHint = 280;
    gd.heightHint = 80;
    table.setLayoutData(gd);
    final AddRemoveButtonBarPart buttonBarPart = new AddRemoveButtonBarPart();
    ToolBar buttonBar = buttonBarPart.createControl(composite, SWT.FLAT | SWT.VERTICAL);
    buttonBar.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    final Image imgEdit = ImageDescriptor.createFromURL(BUNDLE.getEntry("icons/edit.gif")).createImage(parent.getDisplay());
    final Image imgEditDisabled = ImageDescriptor.createFromURL(BUNDLE.getEntry("icons/edit-disabled.gif")).createImage(parent.getDisplay());
    final ToolItem btnEdit = new ToolItem(buttonBar, SWT.PUSH);
    btnEdit.setImage(imgEdit);
    btnEdit.setDisabledImage(imgEditDisabled);
    buttonBarPart.setRemoveEnabled(false);
    btnEdit.setEnabled(false);
    buttonBarPart.addListener(new AddRemoveListener() {

        @Override
        public void addSelected() {
            doAdd();
        }

        @Override
        public void removeSelected() {
            doRemove();
        }
    });
    btnEdit.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doEdit();
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            boolean enabled = !viewer.getSelection().isEmpty();
            buttonBarPart.setRemoveEnabled(enabled);
            btnEdit.setEnabled(enabled);
        }
    });
    viewer.addOpenListener(new IOpenListener() {

        @Override
        public void open(OpenEvent event) {
            doEdit();
        }
    });
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.DEL && e.stateMask == 0)
                doRemove();
        }
    });
    composite.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent ev) {
            iconImg.dispose();
            imgEdit.dispose();
            imgEditDisabled.dispose();
        }
    });
    return composite;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) Attrs(aQute.bnd.header.Attrs) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) StyledString(org.eclipse.jface.viewers.StyledString) Image(org.eclipse.swt.graphics.Image) DisposeEvent(org.eclipse.swt.events.DisposeEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolItem(org.eclipse.swt.widgets.ToolItem) Pair(aQute.libg.tuple.Pair) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StyledString(org.eclipse.jface.viewers.StyledString) ViewerCell(org.eclipse.jface.viewers.ViewerCell) AddRemoveButtonBarPart(org.bndtools.utils.swt.AddRemoveButtonBarPart) AddRemoveListener(org.bndtools.utils.swt.AddRemoveButtonBarPart.AddRemoveListener) IOpenListener(org.eclipse.jface.viewers.IOpenListener) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) TableViewer(org.eclipse.jface.viewers.TableViewer) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Aggregations

AddRemoveListener (org.bndtools.utils.swt.AddRemoveButtonBarPart.AddRemoveListener)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 TableViewer (org.eclipse.jface.viewers.TableViewer)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 AddRemoveButtonBarPart (org.bndtools.utils.swt.AddRemoveButtonBarPart)2 KeyAdapter (org.eclipse.swt.events.KeyAdapter)2 KeyEvent (org.eclipse.swt.events.KeyEvent)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Control (org.eclipse.swt.widgets.Control)2 Table (org.eclipse.swt.widgets.Table)2 Attrs (aQute.bnd.header.Attrs)1 Pair (aQute.libg.tuple.Pair)1 MapContentProvider (bndtools.editor.common.MapContentProvider)1 PropertiesTableLabelProvider (bndtools.editor.common.PropertiesTableLabelProvider)1 URLLabelProvider (bndtools.shared.URLLabelProvider)1