private void updateWritable(final AbstractWidgetModel widgetModel, IPV pv) {
   if (lastWriteAccess == null || lastWriteAccess.get() != pv.isWriteAllowed()) {
     if (lastWriteAccess == null) lastWriteAccess = new AtomicBoolean();
     lastWriteAccess.set(pv.isWriteAllowed());
     if (lastWriteAccess.get()) {
       UIBundlingThread.getInstance()
           .addRunnable(
               editpart.getViewer().getControl().getDisplay(),
               new Runnable() {
                 public void run() {
                   IFigure figure = editpart.getFigure();
                   if (figure.getCursor() == Cursors.NO) figure.setCursor(savedCursor);
                   figure.setEnabled(widgetModel.isEnabled());
                   figure.repaint();
                 }
               });
     } else {
       UIBundlingThread.getInstance()
           .addRunnable(
               editpart.getViewer().getControl().getDisplay(),
               new Runnable() {
                 public void run() {
                   IFigure figure = editpart.getFigure();
                   if (figure.getCursor() != Cursors.NO) savedCursor = figure.getCursor();
                   figure.setEnabled(false);
                   figure.setCursor(Cursors.NO);
                   figure.repaint();
                 }
               });
     }
   }
 }
 /**
  * Set PV to given value. Should accept Double, Double[], Integer, String, maybe more.
  *
  * @param pvPropId
  * @param value
  */
 public void setPVValue(String pvPropId, Object value) {
   fireSetPVValue(pvPropId, value);
   final IPV pv = pvMap.get(pvPropId);
   if (pv != null) {
     try {
       if (pvPropId.equals(controlPVPropId)
           && controlPVValuePropId != null
           && getUpdateSuppressTime() > 0) { // activate suppress timer
         synchronized (this) {
           if (updateSuppressTimer == null || timerTask == null) initUpdateSuppressTimer();
           if (!updateSuppressTimer.isDue()) updateSuppressTimer.reset();
           else startUpdateSuppressTimer();
         }
       }
       pv.setValue(value);
     } catch (final Exception e) {
       UIBundlingThread.getInstance()
           .addRunnable(
               new Runnable() {
                 public void run() {
                   String message = "Failed to write PV:" + pv.getName();
                   ErrorHandlerUtil.handleError(message, e);
                 }
               });
     }
   }
 }
Пример #3
0
  @Override
  public void activate() {
    getWidgetModel()
        .setTabItemHandler(
            new ITabItemHandler() {

              public void addTab(int index, TabItem tabItem) {
                TabEditPart.this.addTab(index, tabItem);
              }

              public void removeTab(int index) {
                TabEditPart.this.removeTab(index);
              }
            });
    super.activate();

    UIBundlingThread.getInstance()
        .addRunnable(
            new Runnable() {
              public void run() {
                // add initial tab
                int j = getTabFigure().getTabAmount();
                while (j < getWidgetModel().getTabsAmount()) {
                  addTab();
                  j++;
                }
              }
            });

    UIBundlingThread.getInstance()
        .addRunnable(
            new Runnable() {
              public void run() {
                int index = getWidgetModel().getActiveTab();
                getTabFigure().setActiveTabIndex(index);
                getWidgetModel()
                    .getChildren()
                    .get(index)
                    .setPropertyValue(AbstractWidgetModel.PROP_VISIBLE, true);
              }
            });
  }
  /**
   * Call {@link #setValue(Object)} in UI Thread. This method can be called in non-UI thread.
   *
   * @param value
   * @since 3.1.3
   */
  public final void setValueInUIThread(final Object value) {
    UIBundlingThread.getInstance()
        .addRunnable(
            getViewer().getControl().getDisplay(),
            new Runnable() {

              @Override
              public void run() {
                setValue(value);
              }
            });
  }
Пример #5
0
 private void updateTabAreaSize() {
   UIBundlingThread.getInstance()
       .addRunnable(
           new Runnable() {
             public void run() {
               Dimension tabAreaSize = getTabAreaSize();
               for (AbstractWidgetModel child : getWidgetModel().getChildren()) {
                 child.setSize(tabAreaSize);
               }
             }
           });
 }
  @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);
  }