@Override
  public EditPart createEditPart(EditPart context, Object model) {

    AbstractGraphicalEditPart part = null;

    BControl control = (BControl) model;

    if (control instanceof Visualization) {
      part = new VisualizationPart();
    } else {
      try {
        IBControlService service =
            (IBControlService)
                BMotionEditorPlugin.getControlServices()
                    .get(control.getType())
                    .createExecutableExtension("service");
        part = service.createEditPart();
      } catch (CoreException e) {
        e.printStackTrace();
      }
    }

    if (part != null) part.setModel(control);

    // TODO: check if part == null
    return part;
  }
  @Override
  public void refreshVisuals() {
    AbstractGraphicalEditPart parent = (AbstractGraphicalEditPart) getParent();
    parent.setLayoutConstraint(
        this, getFigure(), new Rectangle(getGraphics().getObjectConstraint(getModel())));

    String name =
        getGraphics()
            .getTextProvider()
            .getText(getModel(), CorePackage.eINSTANCE.getAbstractModelElement_Name());
    name = name == null || name.equals("null") ? "" : name;
    if (simuationAssignedLeafs == null || simuationAssignedLeafs.isEmpty()) {
      getFigure().getLabel(null).setText(name);
      getFigure().setBackgroundColor(ColorConstants.orange);
      getFigure().setForegroundColor(ColorConstants.black);
    } else {
      getFigure().setBackgroundColor(ColorConstants.blue);
      getFigure().setForegroundColor(ColorConstants.white);
      StringBuffer txt = new StringBuffer();
      txt.append(name + "\n");
      for (DataLeaf l : simuationAssignedLeafs) {
        String lname = l.getName() != null ? l.getName() : (l.getId() != null ? l.getId() : "<?>");
        txt.append(lname + "\n");
      }
      getFigure().getLabel(null).setText(txt.toString());
    }

    if (getViewer() != null && getViewer().getControl() != null) getViewer().getControl().redraw();
  }
 private void identifySourceFigure(Request req) {
   if (req instanceof CreateConnectionRequest) {
     CreateConnectionRequest r = (CreateConnectionRequest) req;
     if (r.getSourceEditPart() instanceof AbstractGraphicalEditPart) {
       AbstractGraphicalEditPart ep = (AbstractGraphicalEditPart) r.getSourceEditPart();
       rec = ep.getFigure().getBounds();
     }
   } else {
     rec = null;
   }
 }
 /**
  * Method used to retrieve the EObject linked with the Object passed as parameter
  *
  * @param object : Object from which EObject has to be revealed
  * @return EObject
  */
 protected final EObject convertToEMF(Object object) {
   EObject eObject = null;
   if (object instanceof GraphicalEditPart) {
     AbstractGraphicalEditPart myGEP = (AbstractGraphicalEditPart) object;
     Object model = myGEP.getModel();
     if (model instanceof View) eObject = ((View) model).getElement();
     return eObject;
   } else if (object instanceof EObject) {
     return (EObject) object;
   } else {
     return null;
   }
 }
Exemple #5
0
 /** Upon deactivation, detach from the model element as a property change listener. */
 @Override
 public void deactivate() {
   if (isActive()) {
     super.deactivate();
     ((ModelElement) getModel()).removePropertyChangeListener(this);
   }
 }
  public void deactivate() {
    if (!isActive()) return;

    getModel().removePropertyChangeListener(delegate);
    delegate = null;
    super.deactivate();
  }
 /** @generated */
 protected void registerModel() {
   super.registerModel();
   View view = (View) getModel();
   if (view != null && view.isSetElement() && view.getElement() != null) {
     getViewer().getEditPartRegistry().put(view.getElement(), this);
   }
 }
Exemple #8
0
 /** Upon activation, attach to the model element as a property change listener. */
 @Override
 public void activate() {
   if (!isActive()) {
     super.activate();
     ((ModelElement) getModel()).addPropertyChangeListener(this);
   }
 }
 @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);
   }
 }
 /** @generated */
 public void deactivate() {
   getTransactionalUpdateManager().uninstall();
   uninstallLinkNotationModelRefresher();
   uninstallNotationModelRefresher();
   getTransactionalUpdateManager().removeUpdatableEditPart(getDiagram().getElement(), this);
   super.deactivate();
 }
 /** @generated */
 public void activate() {
   super.activate();
   getTransactionalUpdateManager().addUpdatableEditPart(getDiagram().getElement(), this);
   installNotationModelRefresher();
   installLinkNotationModelRefresher();
   getTransactionalUpdateManager().install(TransactionUtil.getEditingDomain(getDiagram()));
 }
 @Override
 public void performRequest(Request request) {
   if (request.getType() == REQ_DIRECT_EDIT) {
     performDirectEdit();
   } else {
     super.performRequest(request);
   }
 }
 @Override
 public void deactivate() {
   if (!isActive()) {
     return;
   }
   super.deactivate();
   ((ControlModel) getModel()).removePropertyChangeListener(this);
 }
 @Override
 public void activate() {
   if (isActive()) {
     return;
   }
   super.activate();
   ((ControlModel) getModel()).addPropertyChangeListener(this);
 }
 /**
  * Resizes the figure. Use {@link AbstractBaseEditPart} to implement more complex refreshing
  * behavior.
  *
  * @param refreshableFigure the figure
  */
 protected synchronized void doRefreshVisuals(final IFigure refreshableFigure) {
   super.refreshVisuals();
   AbstractWidgetModel model = getWidgetModel();
   GraphicalEditPart parent = (GraphicalEditPart) getParent();
   if (parent != null) {
     parent.setLayoutConstraint(
         this, refreshableFigure, new Rectangle(model.getLocation(), model.getSize()));
   }
 }
 /** @generated */
 protected void unregisterModel() {
   super.unregisterModel();
   View view = (View) getModel();
   if (view != null
       && view.isSetElement()
       && view.getElement() != null
       && getViewer().getEditPartRegistry().get(view.getElement()) == this) {
     getViewer().getEditPartRegistry().remove(view.getElement());
   }
 }
  public void activate() {
    if (isActive()) return;

    super.activate();
    delegate = new PropertyChangeDelegate(this);

    Component component = getModel();
    component.addPropertyChangeListener(delegate);

    if (getParent().clearNewlyCreatedFlag(component.getID())) {
      performDirectEdit();
    }
  }
Exemple #18
0
  @Override
  public void activate() {
    super.activate();
    ((PropertiesChangeSupport) getModel()).addPropertyChangeListener(this);
    Display.getDefault()
        .syncExec(
            new Runnable() {

              @Override
              public void run() {
                verifyValid();
              }
            });
  }
Exemple #19
0
  @Override
  public void deactivate() {
    super.deactivate();
    ((PropertiesChangeSupport) getModel()).removePropertyChangeListener(this);
    SharedThreadPool.getInstance()
        .execute(
            new Runnable() {

              @Override
              @TaskDescription("Clear workflow node in validation support.")
              public void run() {
                validationSupport.setWorkflowNodeAndValidation(null);
              }
            });
  }
 public void deactivate() {
   super.deactivate();
   ((DecisionTreeDiagram) getModel()).getListeners().removePropertyChangeListener(this);
 }
 @Override
 public void setModel(Object model) {
   ConflictWeb conflictWeb = (ConflictWeb) model;
   super.setModel(model);
   conflictWeb.addListener(listener);
 }
  /**
   * DOC talend Comment method "getTemplate".
   *
   * @param event
   * @return the validate drag able node list
   */
  @Override
  protected Object getTemplate(DragSourceEvent event) {
    final RootEditPart rootEditPart = getViewer().getRootEditPart();
    if (rootEditPart instanceof AbstractGraphicalEditPart) {
      AbstractGraphicalEditPart graphicPart = (AbstractGraphicalEditPart) rootEditPart;
      final IFigure figure = graphicPart.getFigure();
      final IFigure findFigureAt = figure.findFigureAt(new Point(event.x, event.y));
      if (findFigureAt instanceof ISash) {
        return findFigureAt;
      }
    }
    List<EditPart> filtedSelection = new ArrayList<EditPart>();
    for (Object part : getViewer().getSelectedEditParts()) {
      if (part instanceof TreeNodeEditPart || part instanceof VarNodeEditPart) {
        filtedSelection.add((EditPart) part);
      }
    }

    if (filtedSelection == null || filtedSelection.isEmpty()) {
      return null;
    }
    List toTransfer = new ArrayList();
    TransferdType type = null;
    List<TableEntityPart> partList = new ArrayList<TableEntityPart>();
    EditPart lastSelection = filtedSelection.get(filtedSelection.size() - 1);
    if (lastSelection instanceof TreeNodeEditPart
        && !(lastSelection instanceof OutputTreeNodeEditPart)) {
      type = TransferdType.INPUT;
    } else if (lastSelection instanceof VarNodeEditPart) {
      type = TransferdType.VAR;
    }

    if (type != null) {
      if (filtedSelection.size() > 1) {
        partList.addAll(lastSelection.getParent().getChildren());
        Map<EditPart, Integer> partAndIndex = new HashMap<EditPart, Integer>();
        if (type == TransferdType.INPUT) {
          for (EditPart treePart : filtedSelection) {
            if (!XmlMapUtil.isDragable((TreeNode) treePart.getModel())) {
              return null;
            }
          }

          MapperTablePart abstractInOutTreePart =
              MapperUtils.getMapperTablePart((TableEntityPart) lastSelection);
          if (abstractInOutTreePart != null) {
            partList = MapperUtils.getFlatChildrenPartList(abstractInOutTreePart);
          }
        } else {
          partList.addAll(lastSelection.getParent().getChildren());
        }

        for (EditPart selected : filtedSelection) {
          int indexOf = partList.indexOf(selected);
          if (indexOf != -1) {
            partAndIndex.put(selected, indexOf);
            int index = 0;
            for (int i = 0; i < toTransfer.size(); i++) {
              if (indexOf > partAndIndex.get(toTransfer.get(i))) {
                index = i + 1;
              }
            }
            toTransfer.add(index, selected);
          }
        }

      } else {
        if (lastSelection.getModel() instanceof TreeNode
            && !XmlMapUtil.isDragable((TreeNode) lastSelection.getModel())) {
          return null;
        }
        toTransfer.add(lastSelection);
      }
      return new TransferedObject(toTransfer, type);
    }
    return null;
  }
  @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);
  }