@Override
  public Object execute(ExecutionEvent event) {
    // Determine whether the execution event carries an
    // SWT event with it and whether its loaded wth a
    // ITeiidServer reference.
    Object object = event.getTrigger();
    if (object instanceof Event) {
      Event swtEvent = (Event) object;
      Object data = swtEvent.data;
      if (data instanceof ITeiidServer) serverBeingEdited = (ITeiidServer) data;
    }

    run();
    return null;
  }
Пример #2
0
 @Override
 public final Object execute(final ExecutionEvent event) throws ExecutionException {
   if ((action.getStyle() == IAction.AS_CHECK_BOX)
       || (action.getStyle() == IAction.AS_RADIO_BUTTON)) {
     action.setChecked(!action.isChecked());
   }
   final Object trigger = event.getTrigger();
   try {
     if (trigger instanceof Event) {
       action.runWithEvent((Event) trigger);
     } else {
       action.runWithEvent(new Event());
     }
   } catch (Exception e) {
     throw new ExecutionException(
         "While executing the action, an exception occurred", e); // $NON-NLS-1$
   }
   return null;
 }
Пример #3
0
  /** {@inheritDoc} */
  public Object execute(ExecutionEvent event) throws ExecutionException {
    if (getCommonNavigator() == null || getCommonNavigator().getCommonViewer() == null) {
      return null; // The model explorer is not displayed (The editor is closed?)
    }

    CommonViewer viewer = getCommonNavigator().getCommonViewer();

    String[] newContents = null;

    Object trigger = event.getTrigger();

    if (trigger instanceof Event) {
      // State based on the widget
      Event triggerEvent = (Event) trigger;
      if (triggerEvent.widget instanceof ToolItem) {
        if (((ToolItem) triggerEvent.widget).getSelection()) {
          newContents = new String[] {DIAGRAM_CONTENTS};
        } else {
          newContents = new String[] {UML_MODEL_CONTENTS};
        }
      }
    }

    if (newContents == null) {
      // Revert the current state
      INavigatorContentService navigatorContent = viewer.getNavigatorContentService();

      if (navigatorContent.isActive(DIAGRAM_CONTENTS)) {
        newContents = new String[] {UML_MODEL_CONTENTS};
      } else {
        newContents = new String[] {DIAGRAM_CONTENTS};
      }
    }

    UpdateActiveExtensionsOperation updateExtensions =
        new UpdateActiveExtensionsOperation(viewer, newContents);
    updateExtensions.execute(null, null);

    return null;
  }
Пример #4
0
  public Object execute(ExecutionEvent event) {
    ISelection selection;
    try {
      selection =
          ServiceUtilsForHandlers.getInstance()
              .getNestedActiveIEditorPart(event)
              .getSite()
              .getSelectionProvider()
              .getSelection();
      if (selection.isEmpty()) {
        return null;
      }
    } catch (ServiceException ex) {
      Activator.log.error(ex);
      return null;
    }

    if (!(selection instanceof IStructuredSelection)) {
      return null;
    }

    IStructuredSelection sSelection = (IStructuredSelection) selection;
    Object element = sSelection.getFirstElement();

    View view = NotationHelper.findView(element);
    if (view == null) {
      Activator.log.warn(
          "Cannot create a Style from the selected element ; the element is not a View");
      return null;
    }

    Shell parentShell = ((Event) event.getTrigger()).widget.getDisplay().getActiveShell();

    if (view.getElement() == null || view instanceof Diagram) {
      MessageDialog.open(
          MessageDialog.WARNING,
          parentShell,
          "Style error",
          "The selected element's style cannot be exported",
          SWT.NONE);
      return null;
    }

    Map<Declaration, Boolean> declarations = handleStyles(view);
    Map<Attribute, Boolean> conditions = handleSemantic(view);

    String selectorName = view.getElement().eClass().getName();

    AbstractStyleDialog dialog =
        createStyleDialog(parentShell, declarations, conditions, selectorName, view);

    if (dialog.open() != Window.OK) {
      return null;
    }

    Ruleset ruleset = getRuleset(dialog);
    SimpleSelector selector = CssFactory.eINSTANCE.createSimpleSelector();

    if (dialog.useSelectorName()) {
      selector.setElementName(selectorName);
    } else {
      selector.setElementName("*"); // $NON-NLS-1$
    }

    if (dialog.getDiagramRestriction()) {
      String diagramType = getDiagramType(view.getDiagram());
      CompositeSelector compositeSelector = CssFactory.eINSTANCE.createCompositeSelector();
      compositeSelector.setRight(selector);

      SimpleSelector diagramSelector = CssFactory.eINSTANCE.createSimpleSelector();
      diagramSelector.setElementName(diagramType);
      compositeSelector.setLeft(diagramSelector);

      ruleset.getSelectors().add(compositeSelector);
    } else {
      ruleset.getSelectors().add(selector);
    }

    if (dialog.getCSSClass() != null) {
      String cssClass = dialog.getCSSClass();
      org.eclipse.papyrus.infra.gmfdiag.css.Class classCondition =
          CssFactory.eINSTANCE.createClass();
      classCondition.setClass(cssClass);
      selector.getCondition().add(classCondition);
    }

    for (SelectorCondition condition : conditions.keySet()) {
      if (conditions.get(condition)) {
        selector.getCondition().add(condition);
      }
    }

    for (Declaration declaration : declarations.keySet()) {
      if (declarations.get(declaration)) {
        ruleset.getProperties().add(declaration);
      }
    }

    Stylesheet xtextStylesheet = getStyleSheet(dialog, view);

    if (xtextStylesheet == null) {
      return null;
    }

    Resource resource = xtextStylesheet.eResource();

    if (!xtextStylesheet.getContents().contains(ruleset)) {
      xtextStylesheet.getContents().add(ruleset);
    }

    try {
      resource.save(new HashMap<Object, Object>());
      BaseCSSEngine.INSTANCE.reset();
      DiagramHelper.setNeedsRefresh();
      DiagramHelper.refreshDiagrams();
    } catch (IOException ex) {
      Activator.log.error(ex);
      MessageDialog.open(
          MessageDialog.ERROR,
          parentShell,
          "Style error",
          "An unexpected error occured while trying to save the Stylesheet",
          SWT.NONE);
    } catch (Exception ex) {
      Activator.log.error(ex);
      MessageDialog.open(
          MessageDialog.ERROR,
          parentShell,
          "Style error",
          "An unexpected error occured while trying to save the Stylesheet",
          SWT.NONE);
    }

    return null;
  }