/**
  * Run a widget action which is attached to the widget.
  *
  * @param index the index of the action in the actions list.
  */
 public void executeAction(int index) {
   AbstractWidgetAction action;
   try {
     action = getWidgetModel().getActionsInput().getActionsList().get(index);
     if (action != null) action.run();
     else throw new IndexOutOfBoundsException();
   } catch (IndexOutOfBoundsException e) {
     ConsoleService.getInstance()
         .writeError(
             NLS.bind(
                 "No action at index {0} is configured for {1}",
                 index, getWidgetModel().getName()));
   }
 }
  @Override
  public void activate() {
    if (!isActive()) {
      super.activate();
      initFigure(getFigure());

      // add listener to all properties.
      for (String id : getWidgetModel().getAllPropertyIDs()) {

        AbstractWidgetProperty property = getWidgetModel().getProperty(id);
        if (property != null) {
          WidgetPropertyChangeListener listener = new WidgetPropertyChangeListener(this, property);
          property.addPropertyChangeListener(listener);
          propertyListenerMap.put(id, listener);

          property.setExecutionMode(executionMode);
          property.setWidgetModel(getWidgetModel());
        }
      }
      registerBasePropertyChangeHandlers();
      registerPropertyChangeHandlers();

      if (executionMode == ExecutionMode.RUN_MODE) {
        // hook open display action
        Set<String> allPropIds = getWidgetModel().getAllPropertyIDs();
        if (allPropIds.contains(AbstractWidgetModel.PROP_ACTIONS)
            && allPropIds.contains(AbstractWidgetModel.PROP_ENABLED)) {
          hookMouseClickAction();
        }

        // script and rules execution
        ScriptsInput scriptsInput = getWidgetModel().getScriptsInput();
        scriptDataList = new ArrayList<ScriptData>(scriptsInput.getScriptList());
        for (RuleData rd : getWidgetModel().getRulesInput().getRuleDataList()) {
          scriptDataList.add(rd.convertToScriptData());
        }
        for (final ScriptData scriptData : scriptDataList) {
          final IPV[] pvArray = new IPV[scriptData.getPVList().size()];
          int i = 0;
          for (PVTuple pvTuple : scriptData.getPVList()) {
            String pvName = pvTuple.pvName;
            if (pvMap.containsKey(pvName)) {
              pvArray[i] = pvMap.get(pvName);
            } else {
              try {
                IPV pv = BOYPVFactory.createPV(pvName, false, 2);
                pvMap.put(pvName, pv);
                addToConnectionHandler(pvName, pv);
                pvArray[i] = pv;
              } catch (Exception e) {
                String message =
                    NLS.bind(
                        "Unable to connect to PV: {0}! \n"
                            + "This may cause error when executing the script.",
                        pvName);
                OPIBuilderPlugin.getLogger().log(Level.WARNING, message, e);
                ConsoleService.getInstance().writeError(message);
                pvArray[i] = null;
              }
            }
            i++;
          }

          ScriptService.getInstance()
              .registerScript(scriptData, AbstractBaseEditPart.this, pvArray);

          UIBundlingThread.getInstance()
              .addRunnable(
                  new Runnable() {
                    @Override
                    public void run() {
                      if (!isActive()) {
                        // already deactivated
                        return;
                      }
                      hasStartedPVs = true;
                      for (IPV pv : pvArray)
                        if (pv != null && !pv.isStarted())
                          try {
                            pv.start();
                          } catch (Exception e) {
                            OPIBuilderPlugin.getLogger()
                                .log(
                                    Level.WARNING,
                                    "Unable to start PV " + pv.getName(),
                                    e); //$NON-NLS-1$
                          }
                    }
                  });
        }
      }
      doActivate();
    }

    // Rap specified code
    displayDisposeListener =
        new Runnable() {

          @Override
          public void run() {
            deactivate();
          }
        };
    SingleSourceHelper.rapActivateBaseEditPart(this);
  }
Exemplo n.º 3
0
 /**
  * Write pure string to CSS console in specified color.
  *
  * @param string the output string.
  * @param red the red component of RGB
  * @param green the green component of RGB
  * @param blue the blue component of RGB
  */
 public static void writeString(String string, int red, int green, int blue) {
   ConsoleService.getInstance().writeString(string, new RGB(red, green, blue));
 }
Exemplo n.º 4
0
 /**
  * Write pure string to CSS console without any extra headers in black color.
  *
  * @param string the output string.
  */
 public static void writeString(String string) {
   ConsoleService.getInstance().writeString(string);
 }
Exemplo n.º 5
0
 /**
  * Write Warning information to CSS console.
  *
  * @param message the output string.
  */
 public static void writeWarning(String message) {
   ConsoleService.getInstance().writeWarning(message);
 }
Exemplo n.º 6
0
 /**
  * Write Error information to CSS console.
  *
  * @param message the output string.
  */
 public static void writeError(String message) {
   ConsoleService.getInstance().writeError(message);
 }