Пример #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();
 }
Пример #2
0
  @Override
  public Image getIcon(final int iconType) {
    Image icon = img.get(iconType);
    if (icon != null) return icon;

    // try to get a special icon
    icon = BeanSupport.getBeanIcon(component.getBeanClass(), iconType);
    if (icon == null) {
      final String className = component.getBeanClass().getName();
      final String classDetails =
          (String) component.getAuxValue(RADComponent.AUX_VALUE_CLASS_DETAILS);
      if (!iconsInitialized) {
        // getIconForClass invokes getNodes(true) which cannot be called in Mutex
        EventQueue.invokeLater(
            new Runnable() {
              @Override
              public void run() {
                Image icon = PaletteUtils.getIconForClass(className, classDetails, iconType, true);
                iconsInitialized = true;
                if (icon != null) {
                  img.put(iconType, icon);
                  fireIconChange();
                }
              }
            });
      } else {
        icon = PaletteUtils.getIconForClass(className, classDetails, iconType, false);
      }

      if (icon == null) {
        // get icon from BeanInfo
        java.beans.BeanInfo bi = component.getBeanInfo();
        if (bi != null) {
          icon = bi.getIcon(iconType);
        }

        if (icon == null) {
          // use default icon
          icon = super.getIcon(iconType);
        }
      }
    }
    img.put(iconType, icon);
    return icon;
  }
Пример #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();
 }
Пример #4
0
 private void addLayoutActions(List<Action> actions) {
   if (component.getParentComponent() instanceof RADVisualContainer) {
     actions.add(SystemAction.get(AlignAction.class));
     actions.add(SystemAction.get(SetAnchoringAction.class));
     actions.add(SystemAction.get(SetResizabilityAction.class));
     actions.add(SystemAction.get(ChooseSameSizeAction.class));
     actions.add(SystemAction.get(DefaultSizeAction.class));
     actions.add(SystemAction.get(EncloseAction.class));
     actions.add(SystemAction.get(CustomizeEmptySpaceAction.class));
     actions.add(null);
   }
 }
Пример #5
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;
  }
Пример #6
0
  private void addContainerActions(List<Action> actions) {
    if (component instanceof RADVisualContainer) {
      if (!((RADVisualContainer) component).hasDedicatedLayoutSupport()) {
        actions.add(SystemAction.get(SelectLayoutAction.class));
        actions.add(SystemAction.get(CustomizeLayoutAction.class));
      }
      if (MenuEditLayer.isMenuBarContainer(component)) {
        actions.add(SystemAction.get(InsertMenuAction.class));
      } else if (MenuEditLayer.isMenuRelatedContainer(component)) {
        actions.add(SystemAction.get(AddSubItemAction.class));
      } else { // only use the AddAction for non-menu containers
        actions.add(SystemAction.get(AddAction.class));
      }
    }
    if (getNewTypes().length != 0) {
      actions.add(null);
      actions.add(SystemAction.get(NewAction.class));
    }
    if (EditContainerAction.isEditableComponent(component)) {
      actions.add(SystemAction.get(EditContainerAction.class));
    }
    if (DesignParentAction.isParentEditableComponent(component)) {
      actions.add(SystemAction.get(DesignParentAction.class));
    }
    if (component.getParentComponent() == null) {
      if (component instanceof RADVisualComponent) {
        actions.add(SystemAction.get(DefaultSizeAction.class));
      }
      if (component instanceof RADVisualContainer
          && !((RADVisualContainer) component).hasDedicatedLayoutSupport()) {
        actions.add(SystemAction.get(CustomizeEmptySpaceAction.class));
      }
    }

    addSeparator(actions);
  }
Пример #7
0
 @Override
 public FormProperty getProperty(String name) {
   return component.getPropertyByName(name, FormProperty.class, true);
   //        Node.Property prop = component.getPropertyByName(name, true);
   //        return (FormProperty) (prop instanceof FormProperty ? prop : null);
 }
Пример #8
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);
 }
Пример #9
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();
 }
Пример #10
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;
  }
Пример #11
0
 /**
  * Test whether there is a customizer for this node. If true, the customizer can be obtained via
  * {@link #getCustomizer}.
  *
  * @return <CODE>true</CODE> if there is a customizer
  */
 @Override
 public boolean hasCustomizer() {
   return !component.isReadOnly()
       && ((component.getBeanInfo().getBeanDescriptor().getCustomizerClass() != null));
 }
Пример #12
0
 /**
  * Set the system name. Fires a property change event. Also may change the display name according
  * to {@link #displayFormat}.
  *
  * @param s the new name
  */
 @Override
 public void setName(String s) {
   component.rename(s);
 }
Пример #13
0
 @Override
 public String getName() {
   return component.getName();
 }
Пример #14
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;
  }
Пример #15
0
 /* List new types that can be created in this node.
  * @return new types
  */
 @Override
 public NewType[] getNewTypes() {
   return component.getNewTypes();
 }
Пример #16
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}));
 }