Example #1
0
 public static int getColumnAtPos(TableItem item, int x, int y) {
   int columnCount = item.getParent().getColumnCount();
   for (int i = 0; i < columnCount; i++) {
     Rectangle rect = item.getBounds(i);
     if (rect.contains(x, y)) {
       return i;
     }
   }
   return -1;
 }
  /**
   * @param item
   * @param text
   */
  private void corectValueTest(final TableItem item, String text) {
    TypeEditorValidator tEV = typeEditorValidators.get(table1.indexOf(item));
    String s = tEV.isValid(text);
    if (item.getChecked()) {
      if (s == null) {
        item.getParent().setToolTipText("");
        if (vavueCorect.get(tEV) != corect) {
          vavueCorect.put(tEV, corect);
        }
      } else {
        item.getParent().setToolTipText(s);
        if (vavueCorect.get(tEV) != incorect) {
          vavueCorect.put(tEV, incorect);
        }
      }

    } else {
      vavueCorect.remove(tEV);
    }
    refreshOkButton();
  }
 /**
  * This returns the location of the mouse in the vertical direction, relative to the item widget,
  * from 0 (top) to 1 (bottom). NOTE : Copied from DragAndDropCommand.
  *
  * @param event the {@link DropTargetEvent}
  * @return the float representing the vertical direction
  */
 protected float getLocation(DropTargetEvent event) {
   float result = 0.0F;
   if (event.item instanceof TreeItem) {
     TreeItem treeItem = (TreeItem) event.item;
     Control control = treeItem.getParent();
     Point point = control.toControl(new Point(event.x, event.y));
     Rectangle bounds = treeItem.getBounds();
     result = (float) (point.y - bounds.y) / (float) bounds.height;
   } else if (event.item instanceof TableItem) {
     TableItem tableItem = (TableItem) event.item;
     Control control = tableItem.getParent();
     Point point = control.toControl(new Point(event.x, event.y));
     Rectangle bounds = tableItem.getBounds(0);
     result = (float) (point.y - bounds.y) / (float) bounds.height;
   }
   return result;
 }
  private void editItem(final TableItem item) {
    NamespacedProperty expression =
        ((PublishEventMediatorAttributeImpl) item.getData()).getAttributeExpression();

    // value type table editor
    valueTypeEditor = initTableEditor(valueTypeEditor, item.getParent());
    cmbValueType = new Combo(item.getParent(), SWT.READ_ONLY);
    cmbValueType.setItems(
        new String[] {
          AttributeValueType.STRING.getLiteral(), AttributeValueType.EXPRESSION.getLiteral()
        });
    cmbValueType.setText(item.getText(2));
    valueTypeEditor.setEditor(cmbValueType, item, 2);

    item.getParent().redraw();
    item.getParent().layout();
    cmbValueType.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event evt) {
            item.setText(2, cmbValueType.getText());
          }
        });

    attributeValueEditor = initTableEditor(attributeValueEditor, item.getParent());
    attributeValue = new PropertyText(item.getParent(), SWT.NONE, cmbValueType);
    attributeValue.addProperties(item.getText(1), expression);
    attributeValueEditor.setEditor(attributeValue, item, 1);
    item.getParent().redraw();
    item.getParent().layout();
    attributeValue.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            item.setText(1, attributeValue.getText());
            Object property = attributeValue.getProperty();
            if (property instanceof NamespacedProperty) {
              item.setData(EXPRESSION_DATA, (NamespacedProperty) property);
            }
          }
        });
  }
  private void editItem(final TableItem item) {
    final ArgumentWrapper wrapper = (ArgumentWrapper) item.getData();

    argumentTypeEditor = initTableEditor(argumentTypeEditor, item.getParent());
    cmbArgumentType = new Combo(item.getParent(), SWT.READ_ONLY);
    cmbArgumentType.setItems(new String[] {LITERAL_VALUE, LITERAL_EXPRESSION});
    cmbArgumentType.setText(item.getText(0));
    argumentTypeEditor.setEditor(cmbArgumentType, item, 0);
    item.getParent().redraw();
    item.getParent().layout();
    cmbArgumentType.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event evt) {
            item.setText(0, cmbArgumentType.getText());
            if (cmbArgumentType.getSelectionIndex() == 1) {
              wrapper.setExpression(true);
              item.setText(1, wrapper.getArgumentExpression().getPropertyValue());

              String evalString = MediaType.XML.toString();
              if (wrapper.getEvaluator() != null) {
                evalString = wrapper.getEvaluator().toString();
              }
              item.setText(2, evalString);
              cmbArgumentEvaluator.setText(evalString);
              cmbArgumentEvaluator.setEnabled(true);
            } else {
              wrapper.setExpression(false);
              item.setText(1, wrapper.getArgumentValue());
              item.setText(2, "");
              cmbArgumentEvaluator.setText("");
              cmbArgumentEvaluator.setEnabled(false);
            }
          }
        });

    argumentValueEditor = initTableEditor(argumentValueEditor, item.getParent());
    argumentValue = new PropertyText(item.getParent(), SWT.NONE, cmbArgumentType);
    argumentValue.addProperties(wrapper.getArgumentValue(), wrapper.getArgumentExpression());
    argumentValueEditor.setEditor(argumentValue, item, 1);
    item.getParent().redraw();
    item.getParent().layout();
    argumentValue.addModifyListener(
        new ModifyListener() {

          public void modifyText(ModifyEvent e) {
            item.setText(1, argumentValue.getText());
            Object property = argumentValue.getProperty();
            if (property instanceof NamespacedProperty) {
              /*					if (wrapper.getEvaluator() == MediaType.XML) {
              	wrapper.setArgumentExpression((NamespacedProperty)property);
              } else if (wrapper.getEvaluator() == MediaType.JSON){
              	String modifiedText = argumentValue.getText();
              	NamespacedProperty namespacedProperty = (NamespacedProperty)property;
              	namespacedProperty.setPropertyValue(modifiedText);
              	wrapper.setArgumentExpression(namespacedProperty);
              }*/
              wrapper.setArgumentExpression((NamespacedProperty) property);
            } else {
              wrapper.setArgumentValue(property.toString());
            }
          }
        });

    argumentEvaluatorEditor = initTableEditor(argumentEvaluatorEditor, item.getParent());
    cmbArgumentEvaluator = new Combo(item.getParent(), SWT.READ_ONLY);
    cmbArgumentEvaluator.setItems(new String[] {LITERAL_XML, LITERAL_JSON});
    cmbArgumentEvaluator.setText(item.getText(2));
    argumentEvaluatorEditor.setEditor(cmbArgumentEvaluator, item, 2);
    cmbArgumentEvaluator.setEnabled(wrapper.isExpression());
    item.getParent().redraw();
    item.getParent().layout();
    cmbArgumentEvaluator.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event evt) {

            item.setText(2, cmbArgumentEvaluator.getText());
            if (cmbArgumentEvaluator.getSelectionIndex() == 0) {
              wrapper.setEvaluator(MediaType.XML);
              // argumentValue.setForcefullInlineEditing(false);
            } else {
              wrapper.setEvaluator(MediaType.JSON);
              // argumentValue.setForcefullInlineEditing(true);
            }
          }
        });

    /*		if (wrapper.isExpression()) {
    	if (wrapper.getEvaluator() == MediaType.XML){
    		argumentValue.setForcefullInlineEditing(false);
    	} else if (wrapper.getEvaluator() == MediaType.JSON){
    		argumentValue.setForcefullInlineEditing(true);
    	}
    }*/
  }