Ejemplo n.º 1
0
 public void setFocus() {
   if (editor != null && editor.isActivated()) {
     editor.setFocus();
   } else if (canvas != null && !canvas.isDisposed()) {
     canvas.setFocus();
   }
 }
Ejemplo n.º 2
0
 protected boolean handleKeyTraverse(int traversal) {
   if (traversal == SWT.TRAVERSE_RETURN) {
     if (editor != null) {
       if (editor.isActivated()) {
         changeProperty(editor.getValue());
         hideEditor();
         update();
       } else {
         open();
       }
     }
     return false;
   } else if (traversal == SWT.TRAVERSE_ARROW_PREVIOUS) {
     //            selectPrev();
     return true;
   } else if (traversal == SWT.TRAVERSE_ARROW_NEXT) {
     //            selectNext();
     return true;
   } else if (traversal == SWT.TRAVERSE_TAB_NEXT) {
     //            return selectNext();
     return true;
   } else if (traversal == SWT.TRAVERSE_TAB_PREVIOUS) {
     //            return selectPrev();
     return true;
   } else if (traversal == SWT.TRAVERSE_ESCAPE) {
     if (editor.isActivated()) {
       hideEditor();
       update();
       return false;
     } else {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 3
0
  /**
   * Set the object to be edited.
   *
   * @param value The object to be edited.
   */
  public void setObject(Object value) {
    if (!(_type.isInstance(value))) {
      throw new IllegalArgumentException(value.getClass() + " is not of type " + _type);
    }
    _value = value;

    // Disable event generation.
    _squelchChangeEvents = true;

    // Iterate over each property, doing a lookup on the associated editor
    // and setting the editor's value to the value of the property.
    Iterator it = _prop2Editor.keySet().iterator();
    while (it.hasNext()) {
      PropertyDescriptor desc = (PropertyDescriptor) it.next();
      PropertyEditor editor = (PropertyEditor) _prop2Editor.get(desc);
      Method reader = desc.getReadMethod();
      if (reader != null) {
        try {
          Object val = reader.invoke(_value, null);
          editor.setValue(val);
        } catch (IllegalAccessException ex) {
          ex.printStackTrace();
        } catch (InvocationTargetException ex) {
          ex.getTargetException().printStackTrace();
        }
      }
    }

    // Enable event generation.
    _squelchChangeEvents = false;
  }
  @Override
  public void setModel(Property property, boolean readOnly, Predicate filter) {
    this.readOnly = readOnly;
    if (this.property != property) {
      editorVBox.getChildren().removeAll(implementorsBorderPane, confEditor);
    }

    if (property == null) {
      this.property = null;
      PropertyEditor.updateInfo(infoContainer, this.property);
      return;
    }

    if (this.property == property) {
      return;
    }

    editorVBox.getChildren().removeAll(implementorsBorderPane, confEditor);
    extractImplementors(property);
    this.filter = filter;
    this.property = property;
    updateModelValue();
    setRepresentativeName();

    setContent(null);
    setContent(editorVBox);
    choiceBox.setDisable(readOnly);
    PropertyEditor.updateInfo(infoContainer, this.property);
    editorVBox.getChildren().add(confEditor);
  }
Ejemplo n.º 5
0
 private void updateColorsFonts(Color foreground, Font font) {
   if (canvas != null && !canvas.isDisposed()) {
     canvas.setBackground(canvas.getParent().getBackground());
     canvas.setForeground(foreground);
     canvas.setFont(font);
     if (editor != null) {
       editor.setBackground(isSelected() ? selectedBackground : canvas.getBackground());
       editor.setForeground(foreground);
       editor.setFont(font);
     }
   }
 }
Ejemplo n.º 6
0
 public void dispose() {
   if (editor != null) {
     editor.dispose();
     editor = null;
   }
   if (canvas != null && !canvas.isDisposed()) {
     canvas.dispose();
   }
   canvas = null;
   if (valueImage != null && !valueImage.isDisposed()) {
     valueImage.dispose();
   }
   valueImage = null;
   if (nameLayout != null && !nameLayout.isDisposed()) {
     nameLayout.dispose();
   }
   nameLayout = null;
   if (valueLayout != null && !valueLayout.isDisposed()) {
     valueLayout.dispose();
   }
   valueLayout = null;
   //        if (border != null && !border.isDisposed()) {
   //            border.dispose();
   //        }
   //        border = null;
 }
Ejemplo n.º 7
0
  private void initPropertyEditor(final PropertyEditor editor) {
    editor.addEditingListener(
        new IEditingListener() {
          public void editingCanceled() {
            hideEditor();
            update();
          }

          public void editingFinished() {
            changeProperty(editor.getValue());
            hideEditor();
            update();
          }
        });
    editor.deactivate();
  }
Ejemplo n.º 8
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.xmind.ui.properties.PropertyEditor#setFont(org.eclipse.swt.graphics
  * .Font)
  */
 @Override
 public void setFont(Font font) {
   super.setFont(font);
   if (getControl() != null && !getControl().isDisposed()) {
     getControl().setFont(font);
   }
 }
Ejemplo n.º 9
0
  private void layoutControls() {
    Rectangle r = canvas.getBounds();
    int hw = Math.max(0, (r.width - MARGIN_H) / 2 - MARGIN_H);
    nameLayout.setWidth(Math.max(hw, 1));
    valueLayout.setWidth(Math.max(hw, 1));
    if (editor != null) {
      Control ec = editor.getControl();
      int eh = r.height - MARGIN_V - MARGIN_V;
      ec.setBounds(r.width - MARGIN_H - hw, (r.height - eh) / 2, hw, eh);
    }

    //        if (border != null) {
    //            border.dispose();
    //            border = null;
    //        }
    //        border = new Path(Display.getCurrent());
    //        float left = 0, top = 0, right = r.width, bottom = r.height;
    //        border.moveTo(right - RADIUS, top);
    //        border.cubicTo(right - RADIUS_BEND, top, right, top + RADIUS_BEND,
    //                right, top + RADIUS);
    //        border.lineTo(right, bottom - RADIUS);
    //        border.cubicTo(right, bottom - RADIUS_BEND, right - RADIUS_BEND,
    //                bottom, right - RADIUS, bottom);
    //        border.lineTo(left + RADIUS, bottom);
    //        border.cubicTo(left + RADIUS_BEND, bottom, left, bottom - RADIUS_BEND,
    //                left, bottom - RADIUS);
    //        border.lineTo(left, top + RADIUS);
    //        border.cubicTo(left, top + RADIUS_BEND, left + RADIUS_BEND, top, left
    //                + RADIUS, top);
    //        border.close();
  }
Ejemplo n.º 10
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.xmind.ui.properties.PropertyEditor#setForeground(org.eclipse.swt.
  * graphics.Color)
  */
 @Override
 public void setForeground(Color color) {
   super.setForeground(color);
   if (getControl() != null && !getControl().isDisposed()) {
     getControl().setForeground(color);
   }
 }
Ejemplo n.º 11
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.xmind.ui.properties.PropertyEditor#setBackground(org.eclipse.swt.
  * graphics.Color)
  */
 @Override
 public void setBackground(Color color) {
   super.setBackground(color);
   if (getControl() != null && !getControl().isDisposed()) getControl().setBackground(color);
   if (toolBar != null && toolBar.getControl() != null && !toolBar.getControl().isDisposed())
     toolBar.getControl().setBackground(color);
 }
Ejemplo n.º 12
0
 /*
  * (non-Javadoc)
  *
  * @see org.xmind.ui.properties.PropertyEditor#setFocus()
  */
 @Override
 public void setFocus() {
   if (text != null && !text.isDisposed()) {
     text.setFocus();
   } else {
     super.setFocus();
   }
 }
Ejemplo n.º 13
0
 @Override
 public void actionPerformed(java.awt.event.ActionEvent e) {
   try {
     PropertyEditor propEd = property.getPropertyEditor();
     propEd.setValue(property.getValue());
     final Component custEditor = propEd.getCustomEditor();
     Object[] options = buttons();
     DialogDescriptor descriptor =
         new DialogDescriptor(
             custEditor,
             (String) getValue(Action.NAME),
             true,
             options,
             DialogDescriptor.CANCEL_OPTION,
             DialogDescriptor.DEFAULT_ALIGN,
             HelpCtx.DEFAULT_HELP,
             (ActionEvent e1) -> {
               try {
                 String action = e1.getActionCommand();
                 switch (action) {
                   case OK_COMMAND:
                     Object value = property.getPropertyEditor().getValue();
                     property.setValue(value);
                     break;
                   case RESTORE_COMMAND:
                     property.restoreDefaultValue();
                     break;
                 }
                 dialog.dispose();
               } catch (Exception ex) {
                 NotifyDescriptor descriptor2 =
                     new NotifyDescriptor.Message(
                         NbBundle.getMessage(PropertyAction.class, "MSG_InvalidValue")); // NOI18N
                 DialogDisplayer.getDefault().notify(descriptor2);
               }
             });
     descriptor.setClosingOptions(new Object[0]);
     dialog = DialogDisplayer.getDefault().createDialog(descriptor);
     dialog.setVisible(true);
     dialog = null;
   } catch (Exception ex) {
     ErrorManager.getDefault().notify(ex);
   }
 }
Ejemplo n.º 14
0
    public void propertyChange(PropertyChangeEvent e) {
      if (_squelchChangeEvents) return;

      PropertyEditor editor = (PropertyEditor) e.getSource();
      PropertyDescriptor prop = (PropertyDescriptor) _editor2Prop.get(editor);
      Method writer = prop.getWriteMethod();
      if (writer != null) {
        try {
          Object[] params = {editor.getValue()};
          writer.invoke(_value, params);
          setObject(_value);
          firePropertyChange(_value, prop.getName(), null, editor.getValue());
        } catch (IllegalAccessException ex) {
          ex.printStackTrace();
        } catch (InvocationTargetException ex) {
          ex.getTargetException().printStackTrace();
        }
      }
    }
Ejemplo n.º 15
0
 private Point computeCanvasSize(int wHint, int hHint) {
   if (wHint < 0 || hHint < 0) {
     if (editor != null && editor.getControl() != null && !editor.getControl().isDisposed()) {
       Point editorSize =
           editor
               .getControl()
               .computeSize(
                   wHint < 0 ? SWT.DEFAULT : Math.max(0, (wHint - MARGIN_H) / 2 - MARGIN_H - 1),
                   hHint,
                   true);
       if (wHint < 0) wHint = editorSize.x * 2;
       if (hHint < 0) hHint = editorSize.y;
     } else {
       if (wHint < 0) wHint = 100;
       if (hHint < 0) hHint = 1;
     }
     Rectangle nb = nameLayout.getBounds();
     Rectangle vb = valueLayout.getBounds();
     hHint = Math.max(hHint, Math.max(nb.height, vb.height)) + MARGIN_V + MARGIN_V;
   }
   return new Point(wHint, hHint);
 }
Ejemplo n.º 16
0
 /*
  * (non-Javadoc)
  *
  * @see org.xmind.ui.properties.PropertyEditor#activateWidget()
  */
 @Override
 protected void activateWidget() {
   super.activateWidget();
   Display.getCurrent()
       .asyncExec(
           new Runnable() {
             public void run() {
               if (toolBar == null
                   || toolBar.getControl() == null
                   || toolBar.getControl().isDisposed()) return;
               picker.open();
             }
           });
 }
Ejemplo n.º 17
0
 protected void handleMouseMove(int x, int y) {
   setShowingHover(isInHover(x, y));
   if (editor != null) {
     if (!editor.isActivated()) {
       if (isInEditorHover(x, y)) {
         setShowingEditorHover(true);
       } else {
         setShowingEditorHover(false);
       }
     } else {
       setShowingEditorHover(false);
     }
   }
 }
Ejemplo n.º 18
0
 public static PropertyAction createIfEditable(RADProperty<?> property) {
   PropertyEditor propEd = property.getPropertyEditor();
   return propEd != null && propEd.supportsCustomEditor() ? new PropertyAction(property) : null;
 }
Ejemplo n.º 19
0
 private void updateEditor() {
   if (editor != null) {
     editor.setValue(source.getPropertyValue(descriptor.getId()));
   }
 }
Ejemplo n.º 20
0
  /**
   * Standard constructor.
   *
   * @param type Type that you are going to be creating and editor for.
   * @param readOnly Set to true to create a read-only customizer.
   */
  public DynamicCustomizer(Class type, boolean readOnly) {
    super(new GridBagLayout());
    _readOnly = readOnly;
    _type = type;

    LabelFieldGBC gbc = new LabelFieldGBC();
    try {
      BeanInfo info = Introspector.getBeanInfo(type);
      // Set up pretty display stuff.
      setBorder(BorderFactory.createTitledBorder(info.getBeanDescriptor().getDisplayName()));
      setToolTipText(info.getBeanDescriptor().getShortDescription());

      // Get the properties and sort them.
      PropertyDescriptor[] props = info.getPropertyDescriptors();
      Arrays.sort(props, new PropertyComparator());
      for (int i = 0; i < props.length; i++) {
        // Ignore the "class" property, if it is provided.
        if (props[i].getName().equals("class")) continue;
        // Create a label for the field.
        JLabel label = new JLabel(props[i].getDisplayName() + ":");

        // Lookup the editor.
        PropertyEditor editor = getEditorForProperty(props[i]);

        // Add a listener to the editor so we know when to update
        // the bean's fields.
        editor.addPropertyChangeListener(_eListener);

        // XXX What we need to do right here is provide a component
        // that makes use of the "paintable" capability of the editor.
        Component comp = editor.getCustomEditor();
        if (comp == null) {
          comp = new JLabel("<No editor available.>");
          ((JLabel) comp).setBorder(BorderFactory.createEtchedBorder());
        }

        // See if it is a read-only property. If so, then just
        // display it.
        if (_readOnly || props[i].getWriteMethod() == null) {
          comp.setEnabled(false);
        }

        // Setup the accellerator key.
        label.setLabelFor(comp);
        label.setDisplayedMnemonic(label.getText().charAt(0));

        // Set the tool tip text, if any.
        String tip = props[i].getShortDescription();
        if (tip != null) {
          label.setToolTipText(tip);
          if (comp instanceof JComponent) {
            ((JComponent) comp).setToolTipText(tip);
          }
        }

        // Add the label and fields.
        add(label, gbc.forLabel());
        add(comp, gbc.forField());

        // Set the mappings between editor and property, etc. for
        // quick lookup later.
        _prop2Editor.put(props[i], editor);
        _editor2Prop.put(editor, props[i]);
      }
      // Filler...
      add(new JLabel(), gbc.forLastLabel());

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
 public void reset(
     ValuePropertyMetadata propMeta, Set<Class<?>> selectedClasses, boolean multiLineSupported) {
   super.reset(propMeta, selectedClasses);
   this.multiLineSupported = multiLineSupported;
   textNode.setPromptText(null);
 }
Ejemplo n.º 22
0
 private void showEditor() {
   if (editor != null) {
     editor.activate();
   }
 }
Ejemplo n.º 23
0
  public Reference createReference(Object bean) throws NamingException {
    try {
      BeanInfo bi = Introspector.getBeanInfo(bean.getClass());
      PropertyDescriptor[] pds = bi.getPropertyDescriptors();
      List refAddrs = new ArrayList();
      String factoryClassLocation = defaultFactoryClassLocation;

      boolean using_ref_props = referenceProperties.size() > 0;

      // we only include this so that on dereference we are not surprised to find some properties
      // missing
      if (using_ref_props)
        refAddrs.add(
            new BinaryRefAddr(REF_PROPS_KEY, SerializableUtils.toByteArray(referenceProperties)));

      for (int i = 0, len = pds.length; i < len; ++i) {
        PropertyDescriptor pd = pds[i];
        String propertyName = pd.getName();
        // System.err.println("Making Reference: " + propertyName);

        if (using_ref_props && !referenceProperties.contains(propertyName)) {
          // System.err.println("Not a ref_prop -- continuing.");
          continue;
        }

        Class propertyType = pd.getPropertyType();
        Method getter = pd.getReadMethod();
        Method setter = pd.getWriteMethod();
        if (getter != null
            && setter != null) // only use properties that are both readable and writable
        {
          Object val = getter.invoke(bean, EMPTY_ARGS);
          // System.err.println( "val: " + val );
          if (propertyName.equals("factoryClassLocation")) {
            if (String.class != propertyType)
              throw new NamingException(
                  this.getClass().getName()
                      + " requires a factoryClassLocation property to be a string, "
                      + propertyType.getName()
                      + " is not valid.");
            factoryClassLocation = (String) val;
          }

          if (val == null) {
            RefAddr addMe = new BinaryRefAddr(propertyName, NULL_TOKEN_BYTES);
            refAddrs.add(addMe);
          } else if (Coerce.canCoerce(propertyType)) {
            RefAddr addMe = new StringRefAddr(propertyName, String.valueOf(val));
            refAddrs.add(addMe);
          } else // other Object properties
          {
            RefAddr addMe = null;
            PropertyEditor pe = BeansUtils.findPropertyEditor(pd);
            if (pe != null) {
              pe.setValue(val);
              String textValue = pe.getAsText();
              if (textValue != null) addMe = new StringRefAddr(propertyName, textValue);
            }
            if (addMe == null) // property editor approach failed
            addMe =
                  new BinaryRefAddr(
                      propertyName,
                      SerializableUtils.toByteArray(
                          val, indirector, IndirectPolicy.INDIRECT_ON_EXCEPTION));
            refAddrs.add(addMe);
          }
        } else {
          // 				System.err.println(this.getClass().getName() +
          // 						   ": Skipping " + propertyName + " because it is " + (setter == null ?
          // "read-only." : "write-only."));

          if (logger.isLoggable(MLevel.WARNING))
            logger.warning(
                this.getClass().getName()
                    + ": Skipping "
                    + propertyName
                    + " because it is "
                    + (setter == null ? "read-only." : "write-only."));
        }
      }
      Reference out =
          new Reference(bean.getClass().getName(), factoryClassName, factoryClassLocation);
      for (Iterator ii = refAddrs.iterator(); ii.hasNext(); ) out.add((RefAddr) ii.next());
      return out;
    } catch (Exception e) {
      // e.printStackTrace();
      if (Debug.DEBUG && logger.isLoggable(MLevel.FINE))
        logger.log(MLevel.FINE, "Exception trying to create Reference.", e);

      throw new NamingException("Could not create reference from bean: " + e.toString());
    }
  }
Ejemplo n.º 24
0
  protected void getBeanElementProperties(Element element, Object bean, PropertyDescriptor pd)
      throws IntrospectionException, IllegalAccessException {
    Element propertyElement = null;
    Class classOfProperty = pd.getPropertyType();
    Object[] argsNone = {};
    // If the property is "class" and the type is java.lang.Class.class then
    // this is the class of the bean, which we've already encoded.
    // In this special case, return null.
    if (!((pd.getName().charAt(0) == 'c') && pd.getName().equals("class"))
        && !classOfProperty.equals(java.lang.Class.class)) {
      // Don't process property if it is in the list of fields to be ignored
      boolean omittedField = false;
      try {
        Field field = bean.getClass().getDeclaredField(pd.getName());
        omittedField = field.isAnnotationPresent(ObjectXmlOmitField.class);
      } catch (NoSuchFieldException nsfe) {
      }
      if (!omittedField) {
        String propertyName = formatName(pd.getName());
        // Hereafter, we're trying to create a representation of the property
        // based on the property's value.
        // The very first thing we need to do is get the value of the
        // property as an object. If we can't do that, we can't get any
        // representation of the property at all.
        Object propertyValue = null;
        try {
          Method getter = pd.getReadMethod();
          if (getter != null) {
            propertyValue = getter.invoke(bean, argsNone);
          }
        } catch (Exception ex) {
          // couldn't get value
          System.err.println(ex.getMessage());
        }
        // See if this property's value is something we can represent as a
        // standard data type that can be converted to an xsd type,
        // or if it's something that must be represented as a JavaBean.
        if (propertyElement == null) {

          PropertyEditor propEditor = PropertyEditorManager.findEditor(classOfProperty);
          // If the property editor is not null, pass the property's
          // value to the PropertyEditor, and then ask the PropertyEditor
          // for the object and then attempt to convert it to a standard type.

          if ((propEditor != null)
              || (classOfProperty == java.util.Calendar.class)
              || (classOfProperty == java.util.Date.class)) {
            // The object is a standard type
            // (e.g. a wrapper around a primitive type, a String, or a Date or Calendar object)
            try {
              Object object;
              if ((classOfProperty == java.util.Calendar.class)
                  || (classOfProperty == java.util.Date.class)) object = propertyValue;
              else {
                propEditor.setValue(propertyValue);
                object = propEditor.getValue();
              }
              Element childElement = getStandardObjectElement(document, object, propertyName);
              if (includeNullValues
                  || !childElement
                      .getAttribute(
                          NamespaceConstants.NSPREFIX_SCHEMA_XSI
                              + ":"
                              + org.apache.axis.Constants.ATTR_TYPE)
                      .equals("anyType")) {
                if (!includeTypeInfo) {
                  childElement.removeAttribute(
                      NamespaceConstants.NSPREFIX_SCHEMA_XSI
                          + ":"
                          + org.apache.axis.Constants.ATTR_TYPE);
                  childElement.removeAttribute(NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":null");
                }
                try {
                  Field field = bean.getClass().getDeclaredField(propertyName);
                  if (field.isAnnotationPresent(ObjectXmlAsAttribute.class)) {
                    String attrName = null;
                    if (includeTypeInfo) attrName = nsPrefix + ":" + propertyName;
                    else attrName = propertyName;
                    element.setAttribute(attrName, childElement.getFirstChild().getNodeValue());
                  } else if (field.isAnnotationPresent(ObjectXmlAsValue.class))
                    element.setTextContent(childElement.getFirstChild().getNodeValue());
                  else element.appendChild(childElement);
                } catch (NoSuchFieldException nfse) {
                  element.appendChild(childElement);
                }
              }
            } catch (Exception e) {
            }
          } else {
            // The object is not an XSD-encoded datatype, it must be a JavaBean
            try {
              String propertyTypeName = null;
              if (propertyValue != null) {
                // get object type
                Class propertyType = pd.getPropertyType();
                propertyTypeName = propertyType.getName();
              }
              getBeanElements(element, propertyName, propertyTypeName, propertyValue);
            } catch (Exception e) {
            }
          }
        }
      }
    }
  }
Ejemplo n.º 25
0
 private void hideEditor() {
   if (editor != null) {
     editor.deactivate();
   }
 }