Example #1
0
  @Override
  protected Control createContents(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);

    GridLayout gridLayout = new GridLayout(2, false);

    container.setLayout(gridLayout);

    // Initialize and populate list
    final List list = new List(container, SWT.NONE);
    list.setLayoutData(new GridData(SWT.FILL));
    populateList(list);
    list.setSelection(0);
    list.setSize(10, 20);
    list.addSelectionListener(new SomeSelectionListener(list));

    Composite selectorContainer = new Composite(container, SWT.NONE);
    selectorContainer.setLayout(new GridLayout(1, false));

    // Add color editor
    Composite colorContainer = new Composite(selectorContainer, SWT.NONE);
    color = new ColorFieldEditor(SYNTAXCOLOR_COLOR + SYNTAXCOLOR_KEYWORD, "Color", colorContainer);

    // Create and add style group
    Group styleContainer = new Group(selectorContainer, SWT.NONE);
    styleContainer.setText("Style");

    GridLayout gridLayout2 = new GridLayout(1, false);
    styleContainer.setLayout(gridLayout2);

    Composite styleBoldContainer = new Composite(styleContainer, SWT.NONE);
    Composite styleItalicContainer = new Composite(styleContainer, SWT.NONE);
    Composite styleUnderlineContainer = new Composite(styleContainer, SWT.NONE);
    Composite styleStrikethroughContainer = new Composite(styleContainer, SWT.NONE);

    styleBold =
        new BooleanFieldEditor(SYNTAXCOLOR_BOLD + SYNTAXCOLOR_KEYWORD, "Bold", styleBoldContainer);
    styleItalic =
        new BooleanFieldEditor(
            SYNTAXCOLOR_ITALIC + SYNTAXCOLOR_KEYWORD, "Italic", styleItalicContainer);
    styleUnderline =
        new BooleanFieldEditor(
            SYNTAXCOLOR_UNDERLINE + SYNTAXCOLOR_KEYWORD, "Underline", styleUnderlineContainer);
    styleStrikethrough =
        new BooleanFieldEditor(
            SYNTAXCOLOR_STRIKETHROUGH + SYNTAXCOLOR_KEYWORD,
            "Strike through",
            styleStrikethroughContainer);

    // Link editors with the default preferenceStore
    color.setPreferenceStore(getDefaultPreferenceStore());
    styleBold.setPreferenceStore(getDefaultPreferenceStore());
    styleItalic.setPreferenceStore(getDefaultPreferenceStore());
    styleUnderline.setPreferenceStore(getDefaultPreferenceStore());
    styleStrikethrough.setPreferenceStore(getDefaultPreferenceStore());

    // Load values for keyword
    updateEditors(SYNTAXCOLOR_KEYWORD);
    return container;
  }
Example #2
0
  protected Control bindListOfValues(FormToolkit toolkit, Composite parent, final Object id) {
    final Composite panel = toolkit.createComposite(parent);
    panel.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout(3, false);
    zeroMargins(layout);
    panel.setLayout(layout);

    final Text name = toolkit.createText(panel, "");
    name.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    final Button add = new Button(panel, SWT.PUSH | SWT.BORDER);
    add.setText("Add");
    add.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));

    final Button delete = new Button(panel, SWT.PUSH | SWT.BORDER);
    delete.setText("Delete");
    // delete.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));

    final ListViewer viewer = new ListViewer(panel, SWT.BORDER);
    viewer.setContentProvider(new ObservableListContentProvider());

    final Control control = viewer.getControl();
    control.setLayoutData(new GridData(GridData.FILL_BOTH));
    if (control instanceof org.eclipse.swt.widgets.List) {
      org.eclipse.swt.widgets.List list = (org.eclipse.swt.widgets.List) control;
      list.setSize(400, 300);
    }

    List<String> listData;
    Object value = node.getPropertyValue(id);
    if (value instanceof List) {
      listData = (List<String>) value;
    } else {
      listData = new ArrayList<String>();
    }
    final WritableList input = new WritableList(listData, String.class);
    node.setPropertyValue(id, input);
    viewer.setInput(input);

    final Runnable addAction =
        new Runnable() {
          @Override
          public void run() {
            String p = name.getText();
            name.setText("");
            if (!input.contains(p)) {
              input.add(p);
              fireNodePropertyChangedEvent(id);

              // lets layout to make things a bit bigger if need be
              if (control instanceof org.eclipse.swt.widgets.List) {
                org.eclipse.swt.widgets.List list = (org.eclipse.swt.widgets.List) control;
                list.pack(true);
              }
              panel.layout(true, true);
              layoutForm();
            }
          }
        };
    final Runnable deleteAction =
        new Runnable() {
          @Override
          public void run() {
            if (!viewer.getSelection().isEmpty()) {
              IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
              Iterator iter = selection.iterator();
              while (iter.hasNext()) {
                String p = (String) iter.next();
                input.remove(p);
              }
              fireNodePropertyChangedEvent(id);
            }
          }
        };

    // return on entry field adds
    name.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(KeyEvent e) {
            if (e.stateMask == 0 && e.keyCode == '\r') {
              addAction.run();
            }
          }
        });
    // backspace on list to delete
    control.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(KeyEvent e) {
            if ((e.stateMask == 0 && e.keyCode == SWT.BS)
                || (e.stateMask == 0 && e.keyCode == SWT.DEL)) {
              deleteAction.run();
            }
          }
        });

    // enable / disable buttons
    add.setEnabled(false);
    delete.setEnabled(false);
    name.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            add.setEnabled(name.getText().length() > 0);
          }
        });
    viewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          @Override
          public void selectionChanged(SelectionChangedEvent event) {
            delete.setEnabled(!event.getSelection().isEmpty());
          }
        });

    delete.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            deleteAction.run();
          }
        });

    add.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            addAction.run();
          }
        });

    toolkit.adapt(control, true, true);
    return control;
  }