コード例 #1
0
  /** {@inheritDoc} */
  @Override
  public void registerPropertyChangeHandlers() {

    // text
    IWidgetPropertyChangeHandler textHandler =
        new IWidgetPropertyChangeHandler() {
          @Override
          public boolean handleChange(
              final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            button.setText(newValue.toString());
            button.setSize(button.getSize());
            return true;
          }
        };
    editpart.setPropertyChangeHandler(ActionButtonModel.PROP_TEXT, textHandler);

    // image
    IWidgetPropertyChangeHandler imageHandler =
        new IWidgetPropertyChangeHandler() {
          @Override
          public boolean handleChange(
              final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            NativeButtonFigure figure = (NativeButtonFigure) refreshableFigure;
            IPath absolutePath = (IPath) newValue;
            if (absolutePath != null && !absolutePath.isEmpty() && !absolutePath.isAbsolute())
              absolutePath =
                  ResourceUtil.buildAbsolutePath(editpart.getWidgetModel(), absolutePath);
            figure.setImagePath(absolutePath);
            return true;
          }
        };
    editpart.setPropertyChangeHandler(ActionButtonModel.PROP_IMAGE, imageHandler);

    // button style
    final IWidgetPropertyChangeHandler buttonStyleHandler =
        new IWidgetPropertyChangeHandler() {
          @Override
          public boolean handleChange(
              final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            editpart.updatePropSheet();
            return true;
          }
        };
    editpart
        .getWidgetModel()
        .getProperty(ActionButtonModel.PROP_TOGGLE_BUTTON)
        .addPropertyChangeListener(
            new PropertyChangeListener() {
              @Override
              public void propertyChange(PropertyChangeEvent evt) {
                buttonStyleHandler.handleChange(
                    evt.getOldValue(), evt.getNewValue(), editpart.getFigure());
              }
            });
  }
コード例 #2
0
 @Override
 public IFigure doCreateFigure() {
   ActionButtonModel model = editpart.getWidgetModel();
   int style = SWT.None;
   style |= model.isToggleButton() ? SWT.TOGGLE : SWT.PUSH;
   style |= SWT.WRAP;
   final NativeButtonFigure buttonFigure = new NativeButtonFigure(editpart, style);
   button = buttonFigure.getSWTWidget();
   button.setText(model.getText());
   button.addTraverseListener(
       e -> {
         if (skipTraverse) return;
         e.doit = false;
         skipTraverse = true;
         if (e.stateMask == 0) {
           SingleSourceHelper.swtControlTraverse(button, SWT.TRAVERSE_TAB_PREVIOUS);
         } else {
           SingleSourceHelper.swtControlTraverse(button, SWT.TRAVERSE_TAB_NEXT);
         }
         skipTraverse = false;
       });
   buttonFigure.setImagePath(model.getImagePath());
   return buttonFigure;
 }