Java 类com.intellij.uiDesigner.designSurface.InsertComponentProcessor 实例源码

项目:intellij-ce-playground    文件:CreateSnapShotAction.java   
private void collectUnknownLayoutManagerClasses(final Project project, final SnapShotRemoteComponent rc,
                                                final Set<String> layoutManagerClasses) throws IOException {
  RadComponentFactory factory = InsertComponentProcessor.getRadComponentFactory(project, rc.getClassName());
  if (factory instanceof RadContainer.Factory && rc.getLayoutManager().length() > 0 &&
      !LayoutManagerRegistry.isKnownLayoutClass(rc.getLayoutManager())) {
    layoutManagerClasses.add(rc.getLayoutManager());
  }

  SnapShotRemoteComponent[] children = rc.getChildren();
  if (children == null) {
    children = myClient.listChildren(rc.getId());
    rc.setChildren(children);
  }
  for(SnapShotRemoteComponent child: children) {
    collectUnknownLayoutManagerClasses(project, child, layoutManagerClasses);
  }
}
项目:tools-idea    文件:CreateSnapShotAction.java   
private void collectUnknownLayoutManagerClasses(final Project project, final SnapShotRemoteComponent rc,
                                                final Set<String> layoutManagerClasses) throws IOException {
  RadComponentFactory factory = InsertComponentProcessor.getRadComponentFactory(project, rc.getClassName());
  if (factory instanceof RadContainer.Factory && rc.getLayoutManager().length() > 0 &&
      !LayoutManagerRegistry.isKnownLayoutClass(rc.getLayoutManager())) {
    layoutManagerClasses.add(rc.getLayoutManager());
  }

  SnapShotRemoteComponent[] children = rc.getChildren();
  if (children == null) {
    children = myClient.listChildren(rc.getId());
    rc.setChildren(children);
  }
  for(SnapShotRemoteComponent child: children) {
    collectUnknownLayoutManagerClasses(project, child, layoutManagerClasses);
  }
}
项目:consulo-ui-designer    文件:CreateSnapShotAction.java   
private void collectUnknownLayoutManagerClasses(final Project project, final SnapShotRemoteComponent rc,
                                                final Set<String> layoutManagerClasses) throws IOException {
  RadComponentFactory factory = InsertComponentProcessor.getRadComponentFactory(project, rc.getClassName());
  if (factory instanceof RadContainer.Factory && rc.getLayoutManager().length() > 0 &&
      !LayoutManagerRegistry.isKnownLayoutClass(rc.getLayoutManager())) {
    layoutManagerClasses.add(rc.getLayoutManager());
  }

  SnapShotRemoteComponent[] children = rc.getChildren();
  if (children == null) {
    children = myClient.listChildren(rc.getId());
    rc.setChildren(children);
  }
  for(SnapShotRemoteComponent child: children) {
    collectUnknownLayoutManagerClasses(project, child, layoutManagerClasses);
  }
}
项目:intellij-ce-playground    文件:BindingProperty.java   
@Nullable
public static String suggestBindingFromText(final RadComponent component, String text) {
  if (StringUtil.startsWithIgnoreCase(text, PREFIX_HTML)) {
    text = Pattern.compile("<.+?>").matcher(text).replaceAll("");
  }
  ArrayList<String> words = new ArrayList<String>(StringUtil.getWordsIn(text));
  if (words.size() > 0) {
    StringBuilder nameBuilder = new StringBuilder(StringUtil.decapitalize(words.get(0)));
    for(int i=1; i<words.size() && i < 4; i++) {
      nameBuilder.append(StringUtil.capitalize(words.get(i)));
    }
    final String shortClassName = StringUtil.capitalize(InsertComponentProcessor.getShortClassName(component.getComponentClassName()));
    if (shortClassName.equalsIgnoreCase(nameBuilder.toString())) {
      // avoid "buttonButton" case
      return null;
    }
    nameBuilder.append(shortClassName);

    RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component);
    Project project = root.getProject();
    String binding = JavaCodeStyleManager.getInstance(project).propertyNameToVariableName(nameBuilder.toString(), VariableKind.FIELD);
    if (FormEditingUtil.findComponentWithBinding(root, binding, component) != null) {
      binding = InsertComponentProcessor.getUniqueBinding(root, nameBuilder.toString());
    }
    return binding;
  }
  return null;
}
项目:intellij-ce-playground    文件:BindingProperty.java   
public static String getDefaultBinding(final RadComponent c) {
  RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(c);
  String binding = null;
  String text = FormInspectionUtil.getText(c.getModule(), c);
  if (text != null) {
    binding = suggestBindingFromText(c, text);
  }
  if (binding == null) {
    binding = InsertComponentProcessor.suggestBinding(root, c.getComponentClassName());
  }
  return binding;
}
项目:intellij-ce-playground    文件:PaletteListPopupStep.java   
public void hideNonAtomic() {
  for(int i=myItems.size()-1; i >= 0; i--) {
    ComponentItem item = myItems.get(i);
    if (InsertComponentProcessor.getRadComponentFactory(myProject, item.getClassName()) != null || item.getBoundForm() != null) {
      myItems.remove(i);
    }
  }
}
项目:intellij-ce-playground    文件:AddTabAction.java   
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
  RadTabbedPane tabbedPane = (RadTabbedPane) selection.get(0);
  Palette palette = Palette.getInstance(editor.getProject());

  final RadComponent radComponent = InsertComponentProcessor.createPanelComponent(editor);
  final ComponentDropLocation dropLocation = tabbedPane.getDropLocation(null);
  dropLocation.processDrop(editor, new RadComponent[] { radComponent }, null, 
                           new ComponentItemDragObject(palette.getPanelItem()));
}
项目:tools-idea    文件:BindingProperty.java   
@Nullable
public static String suggestBindingFromText(final RadComponent component, String text) {
  if (StringUtil.startsWithIgnoreCase(text, PREFIX_HTML)) {
    text = Pattern.compile("<.+?>").matcher(text).replaceAll("");
  }
  ArrayList<String> words = new ArrayList<String>(StringUtil.getWordsIn(text));
  if (words.size() > 0) {
    StringBuilder nameBuilder = new StringBuilder(StringUtil.decapitalize(words.get(0)));
    for(int i=1; i<words.size() && i < 4; i++) {
      nameBuilder.append(StringUtil.capitalize(words.get(i)));
    }
    final String shortClassName = StringUtil.capitalize(InsertComponentProcessor.getShortClassName(component.getComponentClassName()));
    if (shortClassName.equalsIgnoreCase(nameBuilder.toString())) {
      // avoid "buttonButton" case
      return null;
    }
    nameBuilder.append(shortClassName);

    RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component);
    Project project = root.getProject();
    String binding = JavaCodeStyleManager.getInstance(project).propertyNameToVariableName(nameBuilder.toString(), VariableKind.FIELD);
    if (FormEditingUtil.findComponentWithBinding(root, binding, component) != null) {
      binding = InsertComponentProcessor.getUniqueBinding(root, nameBuilder.toString());
    }
    return binding;
  }
  return null;
}
项目:tools-idea    文件:BindingProperty.java   
public static String getDefaultBinding(final RadComponent c) {
  RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(c);
  String binding = null;
  String text = FormInspectionUtil.getText(c.getModule(), c);
  if (text != null) {
    binding = suggestBindingFromText(c, text);
  }
  if (binding == null) {
    binding = InsertComponentProcessor.suggestBinding(root, c.getComponentClassName());
  }
  return binding;
}
项目:tools-idea    文件:PaletteListPopupStep.java   
public void hideNonAtomic() {
  for(int i=myItems.size()-1; i >= 0; i--) {
    ComponentItem item = myItems.get(i);
    if (InsertComponentProcessor.getRadComponentFactory(myProject, item.getClassName()) != null || item.getBoundForm() != null) {
      myItems.remove(i);
    }
  }
}
项目:tools-idea    文件:AddTabAction.java   
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
  RadTabbedPane tabbedPane = (RadTabbedPane) selection.get(0);
  Palette palette = Palette.getInstance(editor.getProject());

  final RadComponent radComponent = InsertComponentProcessor.createPanelComponent(editor);
  final ComponentDropLocation dropLocation = tabbedPane.getDropLocation(null);
  dropLocation.processDrop(editor, new RadComponent[] { radComponent }, null, 
                           new ComponentItemDragObject(palette.getPanelItem()));
}
项目:consulo-ui-designer    文件:BindingProperty.java   
@Nullable
public static String suggestBindingFromText(final RadComponent component, String text) {
  if (StringUtil.startsWithIgnoreCase(text, PREFIX_HTML)) {
    text = Pattern.compile("<.+?>").matcher(text).replaceAll("");
  }
  ArrayList<String> words = new ArrayList<String>(StringUtil.getWordsIn(text));
  if (words.size() > 0) {
    StringBuilder nameBuilder = new StringBuilder(StringUtil.decapitalize(words.get(0)));
    for(int i=1; i<words.size() && i < 4; i++) {
      nameBuilder.append(StringUtil.capitalize(words.get(i)));
    }
    final String shortClassName = StringUtil.capitalize(InsertComponentProcessor.getShortClassName(component.getComponentClassName()));
    if (shortClassName.equalsIgnoreCase(nameBuilder.toString())) {
      // avoid "buttonButton" case
      return null;
    }
    nameBuilder.append(shortClassName);

    RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component);
    Project project = root.getProject();
    String binding = JavaCodeStyleManager.getInstance(project).propertyNameToVariableName(nameBuilder.toString(), VariableKind.FIELD);
    if (FormEditingUtil.findComponentWithBinding(root, binding, component) != null) {
      binding = InsertComponentProcessor.getUniqueBinding(root, nameBuilder.toString());
    }
    return binding;
  }
  return null;
}
项目:consulo-ui-designer    文件:BindingProperty.java   
public static String getDefaultBinding(final RadComponent c) {
  RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(c);
  String binding = null;
  String text = FormInspectionUtil.getText(c.getModule(), c);
  if (text != null) {
    binding = suggestBindingFromText(c, text);
  }
  if (binding == null) {
    binding = InsertComponentProcessor.suggestBinding(root, c.getComponentClassName());
  }
  return binding;
}
项目:consulo-ui-designer    文件:PaletteListPopupStep.java   
public void hideNonAtomic() {
  for(int i=myItems.size()-1; i >= 0; i--) {
    ComponentItem item = myItems.get(i);
    if (InsertComponentProcessor.getRadComponentFactory(myProject, item.getClassName()) != null || item.getBoundForm() != null) {
      myItems.remove(i);
    }
  }
}
项目:consulo-ui-designer    文件:AddTabAction.java   
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
  RadTabbedPane tabbedPane = (RadTabbedPane) selection.get(0);
  Palette palette = Palette.getInstance(editor.getProject());

  final RadComponent radComponent = InsertComponentProcessor.createPanelComponent(editor);
  final ComponentDropLocation dropLocation = tabbedPane.getDropLocation(null);
  dropLocation.processDrop(editor, new RadComponent[] { radComponent }, null, 
                           new ComponentItemDragObject(palette.getPanelItem()));
}
项目:intellij-ce-playground    文件:MorphAction.java   
private static boolean morphComponent(final GuiEditor editor, final RadComponent oldComponent, ComponentItem targetItem) {
  targetItem = InsertComponentProcessor.replaceAnyComponentItem(editor, targetItem, "Morph to Non-Palette Component");
  if (targetItem == null) {
    return false;
  }
  final RadComponent newComponent = InsertComponentProcessor.createInsertedComponent(editor, targetItem);
  if (newComponent == null) return false;
  newComponent.setBinding(oldComponent.getBinding());
  newComponent.setCustomLayoutConstraints(oldComponent.getCustomLayoutConstraints());
  newComponent.getConstraints().restore(oldComponent.getConstraints());

  updateBoundFieldType(editor, oldComponent, targetItem);

  final IProperty[] oldProperties = oldComponent.getModifiedProperties();
  final Palette palette = Palette.getInstance(editor.getProject());
  for(IProperty prop: oldProperties) {
    IntrospectedProperty newProp = palette.getIntrospectedProperty(newComponent, prop.getName());
    if (newProp == null || !prop.getClass().equals(newProp.getClass())) continue;
    Object oldValue = prop.getPropertyValue(oldComponent);
    try {
      //noinspection unchecked
      newProp.setValue(newComponent, oldValue);
    }
    catch (Exception e) {
      // ignore
    }
  }

  retargetComponentProperties(editor, oldComponent, newComponent);
  final RadContainer parent = oldComponent.getParent();
  int index = parent.indexOfComponent(oldComponent);
  parent.removeComponent(oldComponent);
  parent.addComponent(newComponent, index);
  newComponent.setSelected(true);

  if (oldComponent.isDefaultBinding()) {
    final String text = FormInspectionUtil.getText(newComponent.getModule(), newComponent);
    if (text != null) {
      String binding = BindingProperty.suggestBindingFromText(newComponent, text);
      if (binding != null) {
        new BindingProperty(newComponent.getProject()).setValueEx(newComponent, binding);
      }
    }
    newComponent.setDefaultBinding(true);
  }
  return true;
}
项目:tools-idea    文件:MorphAction.java   
private static boolean morphComponent(final GuiEditor editor, final RadComponent oldComponent, ComponentItem targetItem) {
  targetItem = InsertComponentProcessor.replaceAnyComponentItem(editor, targetItem, "Morph to Non-Palette Component");
  if (targetItem == null) {
    return false;
  }
  final RadComponent newComponent = InsertComponentProcessor.createInsertedComponent(editor, targetItem);
  if (newComponent == null) return false;
  newComponent.setBinding(oldComponent.getBinding());
  newComponent.setCustomLayoutConstraints(oldComponent.getCustomLayoutConstraints());
  newComponent.getConstraints().restore(oldComponent.getConstraints());

  updateBoundFieldType(editor, oldComponent, targetItem);

  final IProperty[] oldProperties = oldComponent.getModifiedProperties();
  final Palette palette = Palette.getInstance(editor.getProject());
  for(IProperty prop: oldProperties) {
    IntrospectedProperty newProp = palette.getIntrospectedProperty(newComponent, prop.getName());
    if (newProp == null || !prop.getClass().equals(newProp.getClass())) continue;
    Object oldValue = prop.getPropertyValue(oldComponent);
    try {
      //noinspection unchecked
      newProp.setValue(newComponent, oldValue);
    }
    catch (Exception e) {
      // ignore
    }
  }

  retargetComponentProperties(editor, oldComponent, newComponent);
  final RadContainer parent = oldComponent.getParent();
  int index = parent.indexOfComponent(oldComponent);
  parent.removeComponent(oldComponent);
  parent.addComponent(newComponent, index);
  newComponent.setSelected(true);

  if (oldComponent.isDefaultBinding()) {
    final String text = FormInspectionUtil.getText(newComponent.getModule(), newComponent);
    if (text != null) {
      String binding = BindingProperty.suggestBindingFromText(newComponent, text);
      if (binding != null) {
        new BindingProperty(newComponent.getProject()).setValueEx(newComponent, binding);
      }
    }
    newComponent.setDefaultBinding(true);
  }
  return true;
}
项目:consulo-ui-designer    文件:MorphAction.java   
private static boolean morphComponent(final GuiEditor editor, final RadComponent oldComponent, ComponentItem targetItem) {
  targetItem = InsertComponentProcessor.replaceAnyComponentItem(editor, targetItem, "Morph to Non-Palette Component");
  if (targetItem == null) {
    return false;
  }
  final RadComponent newComponent = InsertComponentProcessor.createInsertedComponent(editor, targetItem);
  if (newComponent == null) return false;
  newComponent.setBinding(oldComponent.getBinding());
  newComponent.setCustomLayoutConstraints(oldComponent.getCustomLayoutConstraints());
  newComponent.getConstraints().restore(oldComponent.getConstraints());

  updateBoundFieldType(editor, oldComponent, targetItem);

  final IProperty[] oldProperties = oldComponent.getModifiedProperties();
  final Palette palette = Palette.getInstance(editor.getProject());
  for(IProperty prop: oldProperties) {
    IntrospectedProperty newProp = palette.getIntrospectedProperty(newComponent, prop.getName());
    if (newProp == null || !prop.getClass().equals(newProp.getClass())) continue;
    Object oldValue = prop.getPropertyValue(oldComponent);
    try {
      //noinspection unchecked
      newProp.setValue(newComponent, oldValue);
    }
    catch (Exception e) {
      // ignore
    }
  }

  retargetComponentProperties(editor, oldComponent, newComponent);
  final RadContainer parent = oldComponent.getParent();
  int index = parent.indexOfComponent(oldComponent);
  parent.removeComponent(oldComponent);
  parent.addComponent(newComponent, index);
  newComponent.setSelected(true);

  if (oldComponent.isDefaultBinding()) {
    final String text = FormInspectionUtil.getText(newComponent.getModule(), newComponent);
    if (text != null) {
      String binding = BindingProperty.suggestBindingFromText(newComponent, text);
      if (binding != null) {
        new BindingProperty(newComponent.getProject()).setValueEx(newComponent, binding);
      }
    }
    newComponent.setDefaultBinding(true);
  }
  return true;
}
项目:consulo-ui-designer    文件:ComponentTree.java   
@Override
public void drop(DropTargetDropEvent dtde)
{
    try
    {
        final DraggedComponentList dcl = DraggedComponentList.fromTransferable(dtde.getTransferable());
        ComponentItem componentItem = SimpleTransferable.getData(dtde.getTransferable(), ComponentItem.class);
        if(dcl != null || componentItem != null)
        {
            final TreePath path = getPathForLocation((int) dtde.getLocation().getX(), (int) dtde.getLocation().getY());
            final RadComponent targetComponent = getComponentFromPath(path);
            if(!myEditor.ensureEditable())
            {
                return;
            }
            if(targetComponent instanceof RadContainer)
            {
                final ComponentDropLocation dropLocation = ((RadContainer) targetComponent).getDropLocation(null);
                if(dcl != null)
                {
                    if(!FormEditingUtil.isDropOnChild(dcl, dropLocation))
                    {
                        RadComponent[] components = dcl.getComponents().toArray(new RadComponent[dcl.getComponents().size()]);
                        RadContainer[] originalParents = dcl.getOriginalParents();
                        final GridConstraints[] originalConstraints = dcl.getOriginalConstraints();
                        for(int i = 0; i < components.length; i++)
                        {
                            originalParents[i].removeComponent(components[i]);
                        }
                        dropLocation.processDrop(myEditor, components, null, dcl);
                        for(int i = 0; i < originalConstraints.length; i++)
                        {
                            if(originalParents[i].getLayoutManager().isGrid())
                            {
                                FormEditingUtil.deleteEmptyGridCells(originalParents[i], originalConstraints[i]);
                            }
                        }
                    }
                }
                else
                {
                    new InsertComponentProcessor(myEditor).processComponentInsert(componentItem, dropLocation);
                }
            }
            myEditor.refreshAndSave(true);
        }
        setDropTargetComponent(null);
    }
    catch(Exception e)
    {
        LOG.error(e);
    }
}