Example #1
0
 public RADComponentNode(Children children, RADComponent component) {
   super(children, component.getFormModel());
   this.component = component;
   component.setNodeReference(this);
   //        getCookieSet().add(this);
   if (component instanceof ComponentContainer) getCookieSet().add(new ComponentsIndex());
   updateName();
 }
Example #2
0
  @Override
  public Action getPreferredAction() {
    FormEditor formEditor = FormEditor.getFormEditor(component.getFormModel());
    if (formEditor == null) {
      return null;
    }

    for (Action action : formEditor.getDefaultComponentActions()) {
      if (action.isEnabled()) {
        return action;
      }
    }

    return null;
  }
Example #3
0
 /**
  * Remove the node from its parent and deletes it. The default implementation obtains write access
  * to the {@link Children#MUTEX children's lock}, and removes the node from its parent(if any).
  * Also fires a property change.
  *
  * <p>This may be overridden by subclasses to do any additional cleanup.
  *
  * @exception java.io.IOException if something fails
  */
 @Override
 public void destroy() throws java.io.IOException {
   if (component.getNodeReference() == this) {
     if (MetaComponentCreator.isTransparentLayoutComponent(component.getParentComponent())) {
       component = component.getParentComponent();
     }
     if (EventQueue.isDispatchThread()) {
       component.getFormModel().removeComponent(component, true);
     } else {
       EventQueue.invokeLater(
           new Runnable() {
             @Override
             public void run() {
               component.getFormModel().removeComponent(component, true);
             }
           });
     }
   } // otherwise the component was likely already removed with a parent component
   super.destroy();
 }
Example #4
0
 /**
  * Accumulate the paste types that this node can handle for a given transferable.
  *
  * @param t a transferable containing clipboard data
  * @param s a list of {@link PasteType}s that will have added to it all types valid for this node
  */
 @Override
 protected void createPasteTypes(Transferable t, java.util.List<PasteType> s) {
   CopySupport.createPasteTypes(t, s, component.getFormModel(), component);
 }
Example #5
0
 /**
  * Test whether this node can be cut. The default implementation assumes it can if this node is
  * writeable.
  *
  * @return <code>true</code> if it can
  */
 @Override
 public boolean canCut() {
   return !component.isReadOnly() && component != component.getFormModel().getTopRADComponent();
 }
Example #6
0
  /**
   * Creates the customizer component for the node.
   *
   * @return the component, or null if there is no customizer
   */
  @Override
  protected Component createCustomizer() {
    Class customizerClass = component.getBeanInfo().getBeanDescriptor().getCustomizerClass();
    if (customizerClass == null) {
      if (javax.swing.JTable.class.isAssignableFrom(component.getBeanClass())) {
        customizerClass = TableCustomizer.class;
      } else {
        return null;
      }
    }

    Object customizerObject;
    try {
      customizerObject = customizerClass.newInstance();
    } catch (InstantiationException e) {
      ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
      return null;
    } catch (IllegalAccessException e) {
      ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
      return null;
    }

    if (!(customizerObject instanceof Component) || !(customizerObject instanceof Customizer))
      return null;

    if (customizerObject instanceof NodeCustomizer)
      ((NodeCustomizer) customizerObject).attach(component.getNodeReference());

    // Issue 203352 - default values of properties must be initialized
    // before the customizer is shown/used
    component.ensureDefaultPropertyValuesInitialization();

    Customizer customizer = (Customizer) customizerObject;

    customizer.setObject(component.getBeanInstance());

    if (customizerObject instanceof FormAwareEditor) {
      // Hack - returns some property
      Node.Property prop = component.getProperties()[0].getProperties()[0];
      ((FormAwareEditor) customizerObject)
          .setContext(component.getFormModel(), (FormProperty) prop);
    }

    customizer.addPropertyChangeListener(
        new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            FormProperty[] properties;
            if (evt.getPropertyName() != null) {
              FormProperty changedProperty = component.getBeanProperty(evt.getPropertyName());
              if (changedProperty != null) properties = new FormProperty[] {changedProperty};
              else return; // non-existing property?
            } else {
              properties = component.getAllBeanProperties();
              evt = null;
            }
            updatePropertiesFromCustomizer(properties, evt);
          }
        });
    // [undo/redo for customizer probably does not work...]

    return (Component) customizerObject;
  }
Example #7
0
  @Override
  public Action[] getActions(boolean context) {
    if (actions == null) {
      List<Action> actions = new ArrayList<Action>(20);
      RADComponent topComp = component.getFormModel().getTopRADComponent();

      if (component.isReadOnly()) {
        if (component == topComp) {
          actions.add(SystemAction.get(TestAction.class));
          actions.add(null);
        }
        Event[] events = component.getKnownEvents();
        for (int i = 0; i < events.length; i++) {
          if (events[i].hasEventHandlers()) {
            actions.add(SystemAction.get(EventsAction.class));
            actions.add(null);
            break;
          }
        }

        actions.add(SystemAction.get(CopyAction.class));
      } else {
        if (InPlaceEditLayer.supportsEditingFor(component.getBeanClass(), false)) {
          actions.add(SystemAction.get(InPlaceEditAction.class));
        }
        if (javax.swing.JTable.class.isAssignableFrom(component.getBeanClass())) {
          actions.add(SystemAction.get(CustomizeTableAction.class));
        }
        if (component != topComp) {
          actions.add(SystemAction.get(ChangeVariableNameAction.class));
        } else {
          actions.add(SystemAction.get(TestAction.class));
        }
        if (FormEditor.getBindingSupport(component.getFormModel()) != null) {
          // zxb:删除掉绑定菜单项。
          // actions.add(SystemAction.get(BindAction.class));
        }
        actions.add(SystemAction.get(EventsAction.class));
        actions.add(null);

        java.util.List actionProps = component.getActionProperties();
        Iterator iter = actionProps.iterator();
        while (iter.hasNext()) {
          final RADProperty prop = (RADProperty) iter.next();
          Action action = PropertyAction.createIfEditable(prop);
          if (action != null) {
            actions.add(action);
          }
        }
        addSeparator(actions);

        if (component instanceof ComponentContainer) {
          addContainerActions(actions);
          addLayoutActions(actions);
        } else {
          addLayoutActions(actions);
          addContainerActions(actions);
        }
        if (component != topComp) {
          actions.add(SystemAction.get(MoveUpAction.class));
          actions.add(SystemAction.get(MoveDownAction.class));
        }
        if (component instanceof ComponentContainer) {
          actions.add(SystemAction.get(ReorderAction.class));
        }
        addSeparator(actions);

        if (component != topComp) {
          actions.add(SystemAction.get(CutAction.class));
        }
        actions.add(SystemAction.get(CopyAction.class));
        if (component instanceof ComponentContainer) {
          actions.add(SystemAction.get(PasteAction.class));
        }
        if (component != topComp) {
          actions.add(SystemAction.get(DuplicateAction.class));
          actions.add(SystemAction.get(DeleteAction.class));
        }

        actions.add(null);
        // zxb:删除掉自定义代码菜单项。
        // actions.add(SystemAction.get(CustomCodeAction.class));
      }
      actions.add(null);

      javax.swing.Action[] superActions = super.getActions(context);
      for (int i = 0; i < superActions.length; i++) actions.add(superActions[i]);

      this.actions = new Action[actions.size()];
      actions.toArray(this.actions);
    }
    return actions;
  }
Example #8
0
 void updateName() {
   String compClassName = Utilities.getShortClassName(component.getBeanClass());
   if (component == component.getFormModel().getTopRADComponent())
     setDisplayName(nodeNoNameFormat.format(new Object[] {compClassName}));
   else setDisplayName(nodeNameFormat.format(new Object[] {getName(), compClassName}));
 }