コード例 #1
0
    @Override
    public void createBindings(EObject be) {
      final Import imp = (Import) be;

      Composite composite = getAttributesParent();
      TextObjectEditor editor;
      String label;
      EStructuralFeature feature;

      feature = null;
      label = Messages.DefinitionsPropertyComposite_Prefix_Label;
      editor =
          new TextAndButtonObjectEditor(this, be, feature) {

            @Override
            protected void buttonClicked(int buttonId) {
              IInputValidator validator =
                  new IInputValidator() {

                    @Override
                    public String isValid(String newText) {
                      String ns = NamespaceUtil.getNamespaceForPrefix(imp.eResource(), newText);
                      if (ns == null) return null;
                      return NLS.bind(
                          Messages.DefinitionsPropertyComposite_Invalid_Duplicate, newText, ns);
                    }
                  };
              String initialValue = getText();
              InputDialog dialog =
                  new InputDialog(
                      getShell(),
                      Messages.DefinitionsPropertyComposite_Prefix_Label,
                      Messages.DefinitionsPropertyComposite_Prefix_Message,
                      initialValue,
                      validator);
              if (dialog.open() == Window.OK) {
                setValue(dialog.getValue());
              }
            }

            protected boolean setValue(final Object value) {
              // remove old prefix
              String prefix = text.getText();
              NamespaceUtil.removeNamespaceForPrefix(imp.eResource(), prefix);
              // and add new
              NamespaceUtil.addNamespace(imp.eResource(), (String) value, imp.getNamespace());
              setText((String) value);
              return true;
            }

            protected String getText() {
              return getNamespacePrefix();
            }
          };
      editor.createControl(composite, label);

      feature = Bpmn2Package.eINSTANCE.getImport_Namespace();
      label = ModelUtil.getLabel(be, feature);
      editor = new TextObjectEditor(this, be, feature);
      editor.createControl(composite, label);
      editor.setEditable(false);

      feature = Bpmn2Package.eINSTANCE.getImport_Location();
      label = ModelUtil.getLabel(be, feature);
      editor = new TextObjectEditor(this, be, feature);
      editor.createControl(composite, label);
      editor.setEditable(false);

      feature = Bpmn2Package.eINSTANCE.getImport_ImportType();
      label = ModelUtil.getLabel(be, feature);
      editor = new TextObjectEditor(this, be, feature);
      editor.createControl(composite, label);
      editor.setEditable(false);
    }
  @Override
  public void createBindings(EObject be) {
    final TimerEventDefinition event = (TimerEventDefinition) be;

    Composite composite = getAttributesParent();

    createLabel(composite, Messages.TimerEventDefinitionDetailComposite_Type);
    Composite buttonComposite = toolkit.createComposite(composite);
    buttonComposite.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    FillLayout layout = new FillLayout();
    layout.marginWidth = 10;
    layout.spacing = 20;
    buttonComposite.setLayout(layout);

    timeDateButton =
        toolkit.createButton(
            buttonComposite, Messages.TimerEventDefinitionDetailComposite_Time_Date, SWT.RADIO);
    timeCycleButton =
        toolkit.createButton(
            buttonComposite, Messages.TimerEventDefinitionDetailComposite_Interval, SWT.RADIO);
    timeDurationButton =
        toolkit.createButton(
            buttonComposite, Messages.TimerEventDefinitionDetailComposite_Duration, SWT.RADIO);

    if (!isModelObjectEnabled(event.eClass(), PACKAGE.getTimerEventDefinition_TimeDate()))
      timeDateButton.setVisible(false);
    if (!isModelObjectEnabled(event.eClass(), PACKAGE.getTimerEventDefinition_TimeCycle()))
      timeCycleButton.setVisible(false);
    if (!isModelObjectEnabled(event.eClass(), PACKAGE.getTimerEventDefinition_TimeDuration()))
      timeDurationButton.setVisible(false);

    if (event.getTimeDate() != null) {
      expression = (FormalExpression) event.getTimeDate();
      timeDateButton.setSelection(true);
      timerType = TimerType.TIMEDATE;
    } else if (event.getTimeCycle() != null) {
      expression = (FormalExpression) event.getTimeCycle();
      timeCycleButton.setSelection(true);
      timerType = TimerType.TIMECYCLE;
    } else if (event.getTimeDuration() != null) {
      expression = (FormalExpression) event.getTimeDuration();
      timeDurationButton.setSelection(true);
      timerType = TimerType.TIMEDURATION;
    } else {
      timerType = TimerType.NONE;
      expression = createModelObject(FormalExpression.class);
    }

    timeValueEditor = new TextObjectEditor(this, expression, PACKAGE.getFormalExpression_Body());

    timeDateButton.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            if (timeDateButton.getSelection() && timerType != TimerType.TIMEDATE) {
              TransactionalEditingDomain domain = getDiagramEditor().getEditingDomain();
              domain
                  .getCommandStack()
                  .execute(
                      new RecordingCommand(domain) {
                        @Override
                        protected void doExecute() {
                          FormalExpression exp =
                              expression; // createModelObject(FormalExpression.class);
                          event.eUnset(PACKAGE.getTimerEventDefinition_TimeCycle());
                          event.eUnset(PACKAGE.getTimerEventDefinition_TimeDuration());
                          event.setTimeDate(exp);
                          String body = exp.getBody();
                          if (body == null || "null".equals(body)) // $NON-NLS-1$
                          body = ""; // $NON-NLS-1$
                          exp.setBody(""); // $NON-NLS-1$
                          exp.setBody(body);
                          timeValueEditor.setObject(exp);
                          timerType = TimerType.TIMEDATE;
                        }
                      });
            }
          }
        });

    timeCycleButton.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            if (timeCycleButton.getSelection() && timerType != TimerType.TIMECYCLE) {
              TransactionalEditingDomain domain = getDiagramEditor().getEditingDomain();
              domain
                  .getCommandStack()
                  .execute(
                      new RecordingCommand(domain) {
                        @Override
                        protected void doExecute() {
                          FormalExpression exp =
                              expression; // createModelObject(FormalExpression.class);
                          event.eUnset(PACKAGE.getTimerEventDefinition_TimeDate());
                          event.eUnset(PACKAGE.getTimerEventDefinition_TimeDuration());
                          event.setTimeCycle(exp);
                          String body = exp.getBody();
                          if (body == null || "null".equals(body)) // $NON-NLS-1$
                          body = ""; // $NON-NLS-1$
                          exp.setBody(""); // $NON-NLS-1$
                          exp.setBody(body);
                          timeValueEditor.setObject(exp);
                          timerType = TimerType.TIMECYCLE;
                        }
                      });
            }
          }
        });

    timeDurationButton.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            if (timeDurationButton.getSelection() && timerType != TimerType.TIMEDURATION) {
              TransactionalEditingDomain domain = getDiagramEditor().getEditingDomain();
              domain
                  .getCommandStack()
                  .execute(
                      new RecordingCommand(domain) {
                        @Override
                        protected void doExecute() {
                          FormalExpression exp =
                              expression; // createModelObject(FormalExpression.class);
                          event.eUnset(PACKAGE.getTimerEventDefinition_TimeDate());
                          event.eUnset(PACKAGE.getTimerEventDefinition_TimeCycle());
                          event.setTimeDuration(exp);
                          String body = exp.getBody();
                          if (body == null || "null".equals(body)) // $NON-NLS-1$
                          body = ""; // $NON-NLS-1$
                          exp.setBody(""); // $NON-NLS-1$
                          exp.setBody(body);
                          timeValueEditor.setObject(exp);
                          timerType = TimerType.TIMEDURATION;
                        }
                      });
            }
          }
        });

    timeValueEditor.createControl(composite, Messages.TimerEventDefinitionDetailComposite_Value);
  }