public void buildTree() {
    for (int i = 0; i < oldExpressions.size(); i++) {
      final Expression oldExpression = oldExpressions.get(i);
      CompareScript left = new CompareScript(oldExpression.getName(), oldExpression);
      left.setElement(oldExpression);
      left.setImage(adapterFactoryLabelProvider.getImage(oldExpression));
      final Expression newExpression = newExpressions.get(i);

      final CompareScript right = new CompareScript(newExpression.getName(), newExpression);
      right.setElement(newExpression);
      right.addContentChangeListener(
          new IContentChangeListener() {

            @Override
            public void contentChanged(IContentChangeNotifier compareScript) {
              if (compareScript instanceof CompareScript) {
                setDirty(true);
                if (getViewer() == null || getViewer().getControl().isDisposed()) return;
                getViewer().refresh(true);
              }
            }
          });
      right.setImage(adapterFactoryLabelProvider.getImage(newExpression));
      DiffNode leaf = new DiffNode(null, Differencer.CHANGE, null, left, right);
      final DiffNode poolNode = buildPathNodes(oldExpression.eContainer(), leaf);
      if (((CompareScript) poolNode.getAncestor()).getElement() instanceof Pool
          && root.getChildren().length == 0) {
        root.add(poolNode);
      }
    }
  }
 protected void addExpressionStyles(int lineOffset, int lineLenght, Vector<StyleRange> styles) {
   final String content = document.get();
   for (Expression exp : expressions) {
     if (supportedTypes.keySet().contains(exp.getType())) {
       try {
         int i = lineOffset;
         IRegion index = null;
         index = finder.find(i, exp.getName(), true, true, true, false);
         while (index != null && index.getOffset() < lineOffset + lineLenght) {
           if (PatternLineStyleListener.isNotEscapeWord(content, index.getOffset())) {
             styles.add(
                 new StyleRange(
                     index.getOffset(),
                     index.getLength(),
                     Display.getDefault().getSystemColor(supportedTypes.get(exp.getType())),
                     null,
                     SWT.BOLD));
           }
           i = index.getOffset() + index.getLength();
           if (i < lineOffset + lineLenght) {
             index = finder.find(i, exp.getName(), true, true, true, false);
           } else {
             index = null;
           }
         }
       } catch (BadLocationException e) {
         // Ignore
       }
     }
   }
 }
 public Expression createSingleDocumentInitialContentScriptExpression(final ContractInput input) {
   final Expression groovyScriptExpression =
       ExpressionHelper.createGroovyScriptExpression(
           fileContractInputAccessorScript(input), FileInputValue.class.getName());
   groovyScriptExpression.setName("Single document initial value script");
   addInputDependency(input, groovyScriptExpression);
   return groovyScriptExpression;
 }
 /*
  * (non-Javadoc)
  * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object)
  */
 @Override
 public IStatus validate(final Object value) {
   final String content = inputExpression.getContent();
   final WebPageRepositoryStore repositoryStore =
       repositoryAccessor.getRepositoryStore(WebPageRepositoryStore.class);
   return repositoryStore.getChild(content) == null
       ? ValidationStatus.error(
           Messages.bind(
               Messages.pageDoesntExists,
               String.format("%s (%s)", inputExpression.getName(), content)))
       : ValidationStatus.ok();
 }
Ejemplo n.º 5
0
 private void fillViewerInput(final EObject context) {
   final Set<Parameter> input = new HashSet<Parameter>();
   final IExpressionProvider provider =
       ExpressionEditorService.getInstance()
           .getExpressionProvider(ExpressionConstants.PARAMETER_TYPE);
   for (final Expression e : provider.getExpressions(context)) {
     if (editorInputExpression.isReturnTypeFixed()) {
       if (compatibleReturnType(editorInputExpression, e)) {
         input.add((Parameter) e.getReferencedElements().get(0));
       }
     } else {
       input.add((Parameter) e.getReferencedElements().get(0));
     }
   }
   viewer.setInput(input);
 }
  @Override
  public void create() {
    super.create();
    String expressionType = inputExpression.getType();
    if (ExpressionConstants.CONSTANT_TYPE.equals(expressionType)) {
      if (!isSupportedConstantType(inputExpression.getReturnType())) {
        expressionType = ExpressionConstants.SCRIPT_TYPE;
      }
    }
    IExpressionProvider currentProvider =
        ExpressionEditorService.getInstance().getExpressionProvider(expressionType);
    if (currentProvider != null && expressionTypeViewer != null) {
      expressionTypeViewer.setSelection(new StructuredSelection(currentProvider));
    }

    getShell().layout(true, true);
  }
 @Override
 protected List<Connector> getExistingConnectors(AbstractProcess process) {
   List<Connector> connectors =
       ModelHelper.getAllItemsOfType(process, ProcessPackage.Literals.CONNECTOR);
   Set<Connector> toRemove = new HashSet<Connector>();
   for (Connector c : connectors) {
     if (c instanceof ActorFilter) {
       toRemove.add(c);
     }
     if (c.eContainer() instanceof Expression) {
       Expression exp = (Expression) c.eContainer();
       if (!ExpressionConstants.CONNECTOR_TYPE.equals(exp.getType())) {
         toRemove.add(c);
       }
     }
   }
   connectors.removeAll(toRemove);
   return connectors;
 }
 protected void switchEditorType() {
   if (!control.isVisible()) {
     switchToExpressionMode();
     bindExpression();
   } else {
     if (MessageDialog.openQuestion(
         mc.getShell(), Messages.eraseExpressionTitle, Messages.eraseExpressionMsg)) {
       switchToCheckBoxMode();
       // Reset checkbox to false
       final Expression falseExp = ExpressionFactory.eINSTANCE.createExpression();
       falseExp.setName(Boolean.FALSE.toString());
       falseExp.setContent(Boolean.FALSE.toString());
       falseExp.setReturnType(Boolean.class.getName());
       falseExp.setType(ExpressionConstants.CONSTANT_TYPE);
       updateSelection(null, falseExp);
       bindExpression();
     }
   }
   mc.layout(true, true);
 }
 @Override
 public void setSelection(final ISelection selection) {
   if (!selection.isEmpty()) {
     final Expression exp = (Expression) ((IStructuredSelection) selection).getFirstElement();
     if (exp != null) {
       if (ExpressionConstants.CONSTANT_TYPE.equals(exp.getType())) {
         if (!checkBoxControl.isVisible()) {
           switchToCheckBoxMode();
           mc.layout(true, true);
         }
       } else {
         if (!control.isVisible()) {
           switchToExpressionMode();
           mc.layout(true, true);
         }
       }
     }
   }
   super.setSelection(selection);
 }
 private EObject resolveProxy(EObject ref) {
   ResourceSet rSet = null;
   if (ref.eIsProxy() && EcoreUtil.getURI(ref).lastSegment().endsWith(".proc")) {
     rSet = studioExpression.eResource().getResourceSet();
   }
   EObject dep = EcoreUtil2.resolve(ref, rSet);
   if (rSet != null) {
     rSet.getResources().remove(ref.eResource());
   }
   return dep;
 }
 private Expression createExpression(final Data d) {
   final Expression exp = ExpressionFactory.eINSTANCE.createExpression();
   exp.setType(ExpressionConstants.VARIABLE_TYPE);
   exp.setContent(d.getName());
   exp.setName(d.getName());
   exp.setReturnType(org.bonitasoft.studio.common.DataUtil.getTechnicalTypeFor(d));
   exp.getReferencedElements().add(ExpressionHelper.createDependencyFromEObject(d));
   return exp;
 }
  private DiffNode buildPathNodes(EObject container, DiffNode node) {
    DiffNode parentNode = new DiffNode(Differencer.NO_CHANGE);
    node.setParent(parentNode);
    parentNode.add(node);
    CompareScript ancestor = null;
    String name = adapterFactoryLabelProvider.getText(container);
    Expression expr = ExpressionHelper.createConstantExpression(name, String.class.getName());
    expr.setName(name);
    ancestor = new CompareScript(expr.getName(), expr);
    ancestor.setElement(container);
    ancestor.setImage(adapterFactoryLabelProvider.getImage(container));
    parentNode.setAncestor(ancestor);

    if (insertParentNode(parentNode)) {
      return parentNode;
    }
    if (container instanceof Pool) {
      return parentNode;
    }
    if (container instanceof ConnectorParameter) {
      return buildPathNodes(container.eContainer().eContainer(), parentNode);
    }
    return buildPathNodes(container.eContainer(), parentNode);
  }
 /*
  * (non-Javadoc)
  * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object)
  */
 @Override
 public IStatus validate(final Object value) {
   final String content = inputExpression.getContent();
   final WebPageRepositoryStore repositoryStore =
       repositoryAccessor.getRepositoryStore(WebPageRepositoryStore.class);
   String errorMessage = null;
   if (ProcessPackage.Literals.RECAP_FLOW__OVERVIEW_FORM_MAPPING.equals(feature)) {
     errorMessage = Messages.bind(Messages.pageDoesntExist, content);
   } else {
     errorMessage = Messages.bind(Messages.formDoesntExist, content);
   }
   return repositoryStore.getChild(content) == null
       ? ValidationStatus.error(errorMessage)
       : ValidationStatus.ok();
 }
 @Override
 public Expression caseExpression_ProcessRef(Expression_ProcessRef object) {
   EObject resolvedProxy = resolveProxy(object.getValue());
   for (EObject dep : studioExpression.getReferencedElements()) {
     if (dep instanceof Data && resolvedProxy instanceof Data) {
       if (((Data) dep).getName().equals(((Data) resolvedProxy).getName())) {
         return EngineExpressionUtil.createVariableExpression((Data) dep);
       }
     } else if (dep instanceof Parameter && resolvedProxy instanceof Parameter) {
       if (((Parameter) dep).getName().equals(((Parameter) resolvedProxy).getName())) {
         return EngineExpressionUtil.createParameterExpression((Parameter) dep);
       }
     }
   }
   return null;
 }
 /** @param calledProcessName */
 public ListSubprocesses(Expression calledProcessName) {
   subprocessName = calledProcessName.getContent();
 }
Ejemplo n.º 16
0
 @Override
 public void okPressed() {
   if (!editorInputExpression.getContent().equals(editorInputExpression.getName())) {
     editorInputExpression.setName(editorInputExpression.getContent());
   }
 }
 private void addInputDependency(
     final ContractInput input, final Expression groovyScriptExpression) {
   groovyScriptExpression
       .getReferencedElements()
       .add(ExpressionHelper.createDependencyFromEObject(rootInput(input)));
 }
  protected void showContent(String type) {
    IExpressionProvider provider =
        ExpressionEditorService.getInstance().getExpressionProvider(type);

    Assert.isNotNull(provider);

    for (Control c : contentComposite.getChildren()) {
      c.dispose();
    }

    if (currentExpressionEditor != null) {
      currentExpressionEditor.dispose();
    }

    currentExpressionEditor = provider.getExpressionEditor(inputExpression, context);
    currentExpressionEditor.setIsPageFlowContext(isPageFlowContext);
    if (currentExpressionEditor != null) {
      currentExpressionEditor.createExpressionEditor(contentComposite, isPassword);
      contentComposite.layout(true, true);
      if (helpControl != null) {
        //				helpControl.setVisible(currentExpressionEditor.provideDialogTray());
        helpControl.setVisible(false);
        if (currentExpressionEditor.provideDialogTray()) {
          ToolItem item = ((ToolBar) helpControl).getItem(0);
          item.setSelection(true);
          openTrayListener.handleEvent(new Event());
        } else if (getTray() != null) {
          closeTray();
        }
      }
      if (dataBindingContext != null) {
        dataBindingContext.dispose();
      }
      dataBindingContext = new EMFDataBindingContext();

      UpdateValueStrategy selectionToExpressionType = new UpdateValueStrategy();
      IConverter convert =
          new Converter(IExpressionProvider.class, String.class) {

            @Override
            public Object convert(Object arg0) {
              return ((IExpressionProvider) arg0).getExpressionType();
            }
          };
      selectionToExpressionType.setConverter(convert);

      if (domain != null) {
        domain
            .getCommandStack()
            .execute(
                SetCommand.create(
                    domain, inputExpression, ExpressionPackage.Literals.EXPRESSION__TYPE, type));
      } else {
        inputExpression.setType(type);
      }
      currentExpressionEditor.bindExpression(
          dataBindingContext, context, inputExpression, viewerTypeFilters, expressionViewer);
      currentExpressionEditor.addListener(
          new Listener() {
            @Override
            public void handleEvent(Event event) {
              Button okButton = getButton(OK);
              if (okButton != null && !okButton.isDisposed()) {
                okButton.setEnabled(currentExpressionEditor.canFinish());
              }
            }
          });
      DialogSupport.create(this, dataBindingContext);
    }
  }