@Override
 public void deactivate() {
   if (isActive()) {
     doDeActivate();
     ActionsInput input = getWidgetModel().getActionsInput();
     for (AbstractWidgetAction a : input.getActionsList()) {
       a.dispose();
     }
     super.deactivate();
     // remove listener from all properties.
     for (String id : getWidgetModel().getAllPropertyIDs()) {
       getWidgetModel()
           .getProperty(id)
           .removeAllPropertyChangeListeners(); // removePropertyChangeListener(propertyListenerMap.get(id));
     }
     if (executionMode == ExecutionMode.RUN_MODE) {
       // remove script listeners before stopping PV.
       for (ScriptData scriptData : scriptDataList) {
         ScriptService.getInstance().unRegisterScript(scriptData);
       }
       if (hasStartedPVs) {
         // this is just a guard statement
         // if the widget was deactivated before it became fully active (and connected its pv),
         // we should not attempt to stop those pvs; this can happen with linking container
         for (Object pv : pvMap.values().toArray()) {
           ((IPV) pv).stop();
         }
       }
     }
     propertyListenerMap.clear();
     // propertyListenerMap = null;
     SingleSourceHelper.rapDeactivateBaseEditPart(this);
   }
 }
Exemple #2
0
 /**
  * In order for the right-click menu to work, this shell must be registered with a view. Register
  * the context menu against the view. Make the view the default.
  *
  * @param view
  */
 public void registerWithView(IViewPart view) {
   this.view = view;
   actionRegistry.registerAction(new RefreshOPIAction(this));
   SingleSourceHelper.registerRCPRuntimeActions(actionRegistry, this);
   OPIRunnerContextMenuProvider contextMenuProvider =
       new OPIRunnerContextMenuProvider(viewer, this);
   getSite().registerContextMenu(contextMenuProvider, viewer);
   viewer.setContextMenu(contextMenuProvider);
 }
  @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);
  }