Java 类com.intellij.uiDesigner.FormEditingUtil 实例源码

项目:intellij-ce-playground    文件:ComponentItemDialog.java   
@Override
public void actionPerformed(ActionEvent e) {
  final TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(myProject);
  PsiFile formFile = null;
  if (myTextField.getText().length() > 0) {
    VirtualFile formVFile = ResourceFileUtil.findResourceFileInScope(myTextField.getText(), myProject, ProjectScope.getAllScope(myProject));
    if (formVFile != null) {
      formFile = PsiManager.getInstance(myProject).findFile(formVFile);
    }
  }
  TreeFileChooser fileChooser = factory.createFileChooser(myTitle, formFile, null, myFilter, true, true);
  fileChooser.showDialog();
  PsiFile file = fileChooser.getSelectedFile();
  if (file != null) {
    myTextField.setText(FormEditingUtil.buildResourceName(file));
  }
}
项目:intellij-ce-playground    文件:BindingProperty.java   
public static void checkCreateBindingFromText(final RadComponent component, final String text) {
  if (!component.isDefaultBinding()) {
    return;
  }
  RadRootContainer root = (RadRootContainer)FormEditingUtil.getRoot(component);
  PsiField boundField = findBoundField(root, component.getBinding());
  if (boundField == null || !isFieldUnreferenced(boundField)) {
    return;
  }

  String binding = suggestBindingFromText(component, text);
  if (binding != null) {
    new BindingProperty(component.getProject()).setValueEx(component, binding);
    // keep the binding marked as default
    component.setDefaultBinding(true);
  }
}
项目:intellij-ce-playground    文件:IntroComponentProperty.java   
void updateLabelForBinding(final RadComponent component) {
  String value = getValue(component);
  String text = FormInspectionUtil.getText(component.getModule(), component);
  if (text != null && value != null) {
    RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component);
    if (root != null) {
      RadComponent valueComponent = (RadComponent)FormEditingUtil.findComponent(root, value);
      if (valueComponent != null) {
        if (valueComponent instanceof RadScrollPane && ((RadScrollPane) valueComponent).getComponentCount() == 1) {
          valueComponent = ((RadScrollPane) valueComponent).getComponent(0);
        }
        BindingProperty.checkCreateBindingFromText(valueComponent, text);
      }
    }
  }
}
项目:intellij-ce-playground    文件:MorphAction.java   
private static void retargetComponentProperties(final GuiEditor editor, final RadComponent c, final RadComponent newComponent) {
  FormEditingUtil.iterate(editor.getRootContainer(), new FormEditingUtil.ComponentVisitor() {
    public boolean visit(final IComponent component) {
      RadComponent rc = (RadComponent) component;
      for(IProperty p: component.getModifiedProperties()) {
        if (p instanceof IntroComponentProperty) {
          IntroComponentProperty icp = (IntroComponentProperty) p;
          final String value = icp.getValue(rc);
          if (value.equals(c.getId())) {
            try {
              icp.setValue((RadComponent)component, newComponent.getId());
            }
            catch (Exception e) {
              // ignore
            }
          }
        }
      }
      return true;
    }
  });
}
项目:intellij-ce-playground    文件:AbstractGuiEditorAction.java   
public final void actionPerformed(final AnActionEvent e) {
  final GuiEditor editor = FormEditingUtil.getEditorFromContext(e.getDataContext());
  if (editor != null) {
    final ArrayList<RadComponent> selection = FormEditingUtil.getSelectedComponents(editor);
    if (myModifying) {
      if (!editor.ensureEditable()) return;
    }
    Runnable runnable = new Runnable() {
      public void run() {
        actionPerformed(editor, selection, e);
        if (myModifying) {
          editor.refreshAndSave(true);
        }
      }
    };
    if (getCommandName() != null) {
      CommandProcessor.getInstance().executeCommand(editor.getProject(), runnable, getCommandName(), null);
    }
    else {
      runnable.run();
    }
  }
}
项目:intellij-ce-playground    文件:PreviewFormAction.java   
public static void setPreviewBindings(final LwRootContainer rootContainer, final String classToBindName) {
  // 1. Prepare form to preview. We have to change container so that it has only one binding.
  rootContainer.setClassToBind(classToBindName);
  FormEditingUtil.iterate(
    rootContainer,
    new FormEditingUtil.ComponentVisitor<LwComponent>() {
      public boolean visit(final LwComponent iComponent) {
        iComponent.setBinding(null);
        return true;
      }
    }
  );
  if (rootContainer.getComponentCount() == 1) {
    //noinspection HardCodedStringLiteral
    ((LwComponent)rootContainer.getComponent(0)).setBinding(PREVIEW_BINDING_FIELD);
  }
}
项目:intellij-ce-playground    文件:ChooseLocaleAction.java   
@NotNull
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
  DefaultActionGroup group = new DefaultActionGroup();
  GuiEditor editor = myLastEditor;
  if (editor != null) {
    Locale[] locales = FormEditingUtil.collectUsedLocales(editor.getModule(), editor.getRootContainer());
    if (locales.length > 1 || (locales.length == 1 && locales [0].getDisplayName().length() > 0)) {
      Arrays.sort(locales, new Comparator<Locale>() {
        public int compare(final Locale o1, final Locale o2) {
          return o1.getDisplayName().compareTo(o2.getDisplayName());
        }
      });
      for(Locale locale: locales) {
        group.add(new SetLocaleAction(editor, locale, true));
      }
    }
    else {
      group.add(new SetLocaleAction(editor, new Locale(""), false));
    }
  }
  return group;
}
项目:intellij-ce-playground    文件:ReloadCustomComponentsAction.java   
private static boolean haveCustomComponents(final GuiEditor editor) {
  // quick & dirty check
  if (editor.isFormInvalid()) {
    return true;
  }
  final Ref<Boolean> result = new Ref<Boolean>();
  FormEditingUtil.iterate(editor.getRootContainer(), new FormEditingUtil.ComponentVisitor() {
    public boolean visit(final IComponent component) {
      if (component instanceof RadErrorComponent || !component.getComponentClassName().startsWith("javax.swing")) {
        result.set(Boolean.TRUE);
        return false;
      }
      return true;
    }
  });
  return !result.isNull();
}
项目:intellij-ce-playground    文件:CreateComponentAction.java   
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
  Processor<ComponentItem> processor = new Processor<ComponentItem>() {
    public boolean process(final ComponentItem selectedValue) {
      if (selectedValue != null) {
        myLastCreatedComponent = selectedValue;
        editor.getMainProcessor().startInsertProcessor(selectedValue, getCreateLocation(editor, selection));
      }
      return true;
    }
  };

  PaletteListPopupStep step = new PaletteListPopupStep(editor, myLastCreatedComponent, processor,
                                                       UIDesignerBundle.message("create.component.title"));
  final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(step);

  if (selection.size() > 0) {
    FormEditingUtil.showPopupUnderComponent(listPopup, selection.get(0));
  }
  else {
    listPopup.showInCenterOf(editor.getRootContainer().getDelegee());
  }
}
项目:intellij-ce-playground    文件:FlattenAction.java   
private static void flattenSimple(final RadContainer container) {
  RadContainer parent = container.getParent();
  RadComponent child = null;
  Object childLayoutConstraints = null;
  if (container.getComponentCount() == 1) {
    child = container.getComponent(0);
    childLayoutConstraints = container.getCustomLayoutConstraints();
    child.getConstraints().restore(container.getConstraints());
    container.removeComponent(child);
  }
  int childIndex = parent.indexOfComponent(container);
  FormEditingUtil.deleteComponents(Collections.singletonList(container), false);
  if (child != null) {
    if (childLayoutConstraints != null) {
      child.setCustomLayoutConstraints(childLayoutConstraints);
    }
    parent.addComponent(child, childIndex);
    child.revalidate();
  }
}
项目:intellij-ce-playground    文件:PasteProcessor.java   
private void doPaste(final ComponentDropLocation location) {
  if (location.canDrop(myPastedComponentList) && myEditor.ensureEditable()) {
    final RadComponent[] componentsToPaste = myComponentsToPaste.toArray(new RadComponent[myComponentsToPaste.size()]);
    CommandProcessor.getInstance().executeCommand(
      myEditor.getProject(),
      new Runnable() {
        public void run() {
          location.processDrop(myEditor, componentsToPaste, null, myPastedComponentList);
          for(RadComponent c: componentsToPaste) {
            FormEditingUtil.iterate(c, new FormEditingUtil.ComponentVisitor() {
              public boolean visit(final IComponent component) {
                if (component.getBinding() != null) {
                  InsertComponentProcessor.createBindingField(myEditor, (RadComponent) component);
                }
                return true;
              }
            });
          }
          FormEditingUtil.selectComponents(myEditor, myComponentsToPaste);
          myEditor.refreshAndSave(true);
        }
      }, UIDesignerBundle.message("command.paste"), null);
    endPaste();
  }
}
项目:intellij-ce-playground    文件:NoButtonGroupInspection.java   
private static boolean areCellsAdjacent(final IContainer parent, final GridConstraints c1, final GridConstraints c2) {
  if (parent instanceof RadContainer) {
    final RadContainer container = (RadContainer)parent;
    if (!container.getLayoutManager().isGrid()) return false;
    if (c1.getRow() == c2.getRow()) {
      return FormEditingUtil.prevCol(container, c1.getColumn()) == c2.getColumn() ||
             FormEditingUtil.nextCol(container, c1.getColumn()) == c2.getColumn();
    }
    if (c1.getColumn() == c2.getColumn()) {
      return FormEditingUtil.prevRow(container, c1.getRow()) == c2.getRow() ||
             FormEditingUtil.nextRow(container, c1.getRow()) == c2.getRow();
    }
  }
  return (c1.getRow() == c2.getRow() && Math.abs(c1.getColumn() - c2.getColumn()) == 1) ||
      (c1.getColumn() == c2.getColumn() && Math.abs(c1.getRow() - c2.getRow()) == 1);
}
项目:intellij-ce-playground    文件:Form2SourceCompiler.java   
private static VirtualFile findSourceFile(final CompileContext context, final VirtualFile formFile, final String className) {
  final Module module = context.getModuleByFile(formFile);
  if (module == null) {
    return null;
  }
  final PsiClass aClass = FormEditingUtil.findClassToBind(module, className);
  if (aClass == null) {
    return null;
  }

  final PsiFile containingFile = aClass.getContainingFile();
  if (containingFile == null){
    return null;
  }

  return containingFile.getVirtualFile();
}
项目:intellij-ce-playground    文件:CreateClassToBindFix.java   
private void createBoundFields(final PsiClass formClass) throws IncorrectOperationException {
  final Module module = myEditor.getRootContainer().getModule();
  final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
  final PsiManager psiManager = PsiManager.getInstance(myEditor.getProject());

  final Ref<IncorrectOperationException> exception = new Ref<IncorrectOperationException>();
  FormEditingUtil.iterate(myEditor.getRootContainer(), new FormEditingUtil.ComponentVisitor() {
    public boolean visit(final IComponent component) {
      if (component.getBinding() != null) {
        final PsiClass fieldClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(component.getComponentClassName(), scope);
        if (fieldClass != null) {
          PsiType fieldType = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory().createType(fieldClass);
          try {
            PsiField field = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory().createField(component.getBinding(), fieldType);
            formClass.add(field);
          }
          catch (IncorrectOperationException e) {
            exception.set(e);
            return false;
          }
        }
      }
      return true;
    }
  });

  if (!exception.isNull()) {
    throw exception.get();
  }
}
项目:intellij-ce-playground    文件:ResourceFileReference.java   
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
  if (!(element instanceof PsiFile)) { //should be icon file or nested form
    throw new IncorrectOperationException();
  }

  updateRangeText(FormEditingUtil.buildResourceName((PsiFile)element));
  return myFile;
}
项目:intellij-ce-playground    文件:BindingProperty.java   
protected void setValueImpl(final RadComponent component, final String value) throws Exception {
  if (Comparing.strEqual(value, component.getBinding(), true)) {
    return;
  }

  if (value.length() > 0 && !PsiNameHelper.getInstance(component.getProject()).isIdentifier(value)) {
    throw new Exception("Value '" + value + "' is not a valid identifier");
  }

  final RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component);
  final String oldBinding = getValue(component);

  // Check that binding remains unique

  if (value.length() > 0) {
    if (!FormEditingUtil.isBindingUnique(component, value, root)) {
      throw new Exception(UIDesignerBundle.message("error.binding.not.unique"));
    }

    component.setBinding(value);
    component.setDefaultBinding(false);
  }
  else {
    if (component.isCustomCreateRequired()) {
      throw new Exception(UIDesignerBundle.message("error.custom.create.binding.required"));
    }
    component.setBinding(null);
    component.setCustomCreate(false);
  }

  // Set new value or rename old one. It means that previous binding exists
  // and the new one doesn't exist we need to ask user to create new field
  // or rename old one.

  updateBoundFieldName(root, oldBinding, value, component.getComponentClassName());
}
项目: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    文件:CustomCreateProperty.java   
protected void setValueImpl(final RadComponent component, final Boolean value) throws Exception {
  if (value.booleanValue() && component.getBinding() == null) {
    String initialBinding = BindingProperty.getDefaultBinding(component);
    String binding = Messages.showInputDialog(
      component.getProject(),
      UIDesignerBundle.message("custom.create.field.name.prompt"),
      UIDesignerBundle.message("custom.create.title"), Messages.getQuestionIcon(),
      initialBinding, new IdentifierValidator(component.getProject()));
    if (binding == null) {
      return;
    }
    try {
      new BindingProperty(component.getProject()).setValue(component, binding);
    }
    catch (Exception e1) {
      LOG.error(e1);
    }
  }
  component.setCustomCreate(value.booleanValue());
  if (value.booleanValue()) {
    final IRootContainer root = FormEditingUtil.getRoot(component);
    if (root.getClassToBind() != null && Utils.getCustomCreateComponentCount(root) == 1) {
      final PsiClass aClass = FormEditingUtil.findClassToBind(component.getModule(), root.getClassToBind());
      if (aClass != null && FormEditingUtil.findCreateComponentsMethod(aClass) == null) {
        generateCreateComponentsMethod(aClass);
      }
    }
  }
}
项目:intellij-ce-playground    文件:ButtonGroupProperty.java   
private void updateModel() {
  RadButtonGroup[] groups = myRootContainer.getButtonGroups();
  RadButtonGroup[] allGroups = new RadButtonGroup[groups.length+2];
  System.arraycopy(groups, 0, allGroups, 1, groups.length);
  allGroups [allGroups.length-1] = RadButtonGroup.NEW_GROUP;
  myCbx.setModel(new DefaultComboBoxModel(allGroups));
  myCbx.setSelectedItem(FormEditingUtil.findGroupForComponent(myRootContainer, myComponent));
}
项目:intellij-ce-playground    文件:ComponentRenderer.java   
public JComponent getComponent(final RadRootContainer rootContainer, String value, boolean selected, boolean hasFocus) {
  clear();
  setBackground(selected ? UIUtil.getTableSelectionBackground() : UIUtil.getTableBackground());
  if (value != null && value.length() > 0) {
    RadComponent target = (RadComponent)FormEditingUtil.findComponent(rootContainer, value);
    if (target != null) {
      renderComponent(target, selected);
    }
    else {
      append(UIDesignerBundle.message("component.not.found"), SimpleTextAttributes.ERROR_ATTRIBUTES);
    }
  }

  return this;
}
项目:intellij-ce-playground    文件:IconEditor.java   
public IconEditor() {
  myTextField.getTextField().setBorder(null);
  myTextField.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      final TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(getModule().getProject());
      PsiFile iconFile = null;
      if (myValue != null) {
        VirtualFile iconVFile = ResourceFileUtil.findResourceFileInScope(myValue.getIconPath(), getModule().getProject(),
                                                                         getModule()
                                                                           .getModuleWithDependenciesAndLibrariesScope(true));
        if (iconVFile != null) {
          iconFile = PsiManager.getInstance(getModule().getProject()).findFile(iconVFile);
        }
      }
      TreeFileChooser fileChooser = factory.createFileChooser(UIDesignerBundle.message("title.choose.icon.file"), iconFile,
                                                              null, new ImageFileFilter(getModule()), false, true);
      fileChooser.showDialog();
      PsiFile file = fileChooser.getSelectedFile();
      if (file != null) {
        String resourceName = FormEditingUtil.buildResourceName(file);
        if (resourceName != null) {
          IconDescriptor descriptor = new IconDescriptor(resourceName);
          IntroIconProperty.loadIconFromFile(file.getVirtualFile(), descriptor);
          myValue = descriptor;
          myTextField.setText(descriptor.getIconPath());
        }
      }
    }
  });
}
项目:intellij-ce-playground    文件:SurroundPopupAction.java   
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
  final ListPopup groupPopup = JBPopupFactory.getInstance()
    .createActionGroupPopup(UIDesignerBundle.message("surround.with.popup.title"), myActionGroup, e.getDataContext(),
                            JBPopupFactory.ActionSelectionAid.ALPHA_NUMBERING, true);

  final JComponent component = (JComponent)e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
  if (component instanceof ComponentTree) {
    groupPopup.show(JBPopupFactory.getInstance().guessBestPopupLocation(component));
  }
  else {
    RadComponent selComponent = selection.get(0);
    FormEditingUtil.showPopupUnderComponent(groupPopup, selComponent);
  }
}
项目:intellij-ce-playground    文件:CreateListenerAction.java   
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
  final DefaultActionGroup actionGroup = prepareActionGroup(selection);
  final JComponent selectedComponent = selection.get(0).getDelegee();
  final DataContext context = DataManager.getInstance().getDataContext(selectedComponent);
  final JBPopupFactory factory = JBPopupFactory.getInstance();
  final ListPopup popup = factory.createActionGroupPopup(UIDesignerBundle.message("create.listener.title"), actionGroup, context,
                                                         JBPopupFactory.ActionSelectionAid.NUMBERING, true);

  FormEditingUtil.showPopupUnderComponent(popup, selection.get(0));
}
项目:intellij-ce-playground    文件:CreateListenerAction.java   
private static boolean canCreateListener(final ArrayList<RadComponent> selection) {
  if (selection.size() == 0) return false;
  final RadRootContainer root = (RadRootContainer)FormEditingUtil.getRoot(selection.get(0));
  if (root.getClassToBind() == null) return false;
  String componentClass = selection.get(0).getComponentClassName();
  for(RadComponent c: selection) {
    if (!c.getComponentClassName().equals(componentClass) || c.getBinding() == null) return false;
    if (BindingProperty.findBoundField(root, c.getBinding()) == null) return false;
  }
  return true;
}
项目:intellij-ce-playground    文件:ExpandSelectionAction.java   
public void update(final AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  final GuiEditor editor = FormEditingUtil.getEditorFromContext(e.getDataContext());

  if(editor == null){
    presentation.setEnabled(false);
    return;
  }

  final SelectionState selectionState = editor.getSelectionState();
  selectionState.setInsideChange(true);
  final Stack<ComponentPtr[]> history = selectionState.getSelectionHistory();

  presentation.setEnabled(!history.isEmpty());
}
项目:intellij-ce-playground    文件:MorphAction.java   
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
  Processor<ComponentItem> processor = new Processor<ComponentItem>() {
    public boolean process(final ComponentItem selectedValue) {
      SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          Runnable runnable = new Runnable() {
            public void run() {
              for(RadComponent c: selection) {
                if (!morphComponent(editor, c, selectedValue)) break;
              }
              editor.refreshAndSave(true);
            }
          };
          CommandProcessor.getInstance().executeCommand(editor.getProject(), runnable, UIDesignerBundle.message("morph.component.command"), null);
          editor.getGlassLayer().requestFocus();
        }
      });
      return true;
    }
  };

  PaletteListPopupStep step = new PaletteListPopupStep(editor, myLastMorphComponent, processor,
                                                       UIDesignerBundle.message("morph.component.title"));
  step.hideNonAtomic();
  if (selection.size() == 1) {
    step.hideComponentClass(selection.get(0).getComponentClassName());
  }
  final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(step);
  FormEditingUtil.showPopupUnderComponent(listPopup, selection.get(0));
}
项目:intellij-ce-playground    文件:StartInplaceEditingAction.java   
public void actionPerformed(final AnActionEvent e) {
  final ArrayList<RadComponent> selection = FormEditingUtil.getAllSelectedComponents(myEditor);
  final RadComponent component = selection.get(0);
  final Property defaultInplaceProperty = component.getDefaultInplaceProperty();
  myEditor.getInplaceEditingLayer().startInplaceEditing(component, defaultInplaceProperty,
                                                        component.getDefaultInplaceEditorBounds(), new InplaceContext(true));
}
项目:intellij-ce-playground    文件:StartInplaceEditingAction.java   
public void update(final AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  final ArrayList<RadComponent> selection = FormEditingUtil.getAllSelectedComponents(myEditor);

  // Inplace editing can be started only if single component is selected
  if(selection.size() != 1){
    presentation.setEnabled(false);
    return;
  }

  // Selected component should have "inplace" property
  final RadComponent component = selection.get(0);
  presentation.setEnabled(component.getDefaultInplaceProperty() != null);
}
项目:intellij-ce-playground    文件:AbstractGuiEditorAction.java   
public final void update(AnActionEvent e) {
  GuiEditor editor = FormEditingUtil.getEditorFromContext(e.getDataContext());
  if (editor == null) {
    e.getPresentation().setVisible(false);
    e.getPresentation().setEnabled(false);
  }
  else {
    e.getPresentation().setVisible(true);
    e.getPresentation().setEnabled(true);
    final ArrayList<RadComponent> selection = FormEditingUtil.getSelectedComponents(editor);
    update(editor, selection, e);
  }
}
项目:intellij-ce-playground    文件:SelectAllComponentsAction.java   
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
  final ComponentTreeBuilder builder = DesignerToolWindowManager.getInstance(editor).getComponentTreeBuilder();
  builder.beginUpdateSelection();
  try {
    FormEditingUtil.iterate(editor.getRootContainer(), new FormEditingUtil.ComponentVisitor() {
      public boolean visit(final IComponent component) {
        ((RadComponent) component).setSelected(true);
        return true;
      }
    });
  }
  finally {
    builder.endUpdateSelection();
  }
}
项目:intellij-ce-playground    文件:PreviewFormAction.java   
public void update(final AnActionEvent e) {
  final GuiEditor editor = FormEditingUtil.getActiveEditor(e.getDataContext());

  if(editor == null){
    e.getPresentation().setVisible(false);
    return;
  }

  final VirtualFile file = editor.getFile();
  e.getPresentation().setVisible(
    FileDocumentManager.getInstance().getDocument(file) != null &&
    file.getFileType() == StdFileTypes.GUI_DESIGNER_FORM
  );
}
项目:intellij-ce-playground    文件:SurroundAction.java   
protected void update(@NotNull final GuiEditor editor, final ArrayList<RadComponent> selection, final AnActionEvent e) {
  FormEditingUtil.remapToActionTargets(selection);
  RadContainer selectionParent = FormEditingUtil.getSelectionParent(selection);
  e.getPresentation().setEnabled(selectionParent != null &&
                                 ((!selectionParent.getLayoutManager().isGrid() && selection.size() == 1) ||
                                   isSelectionContiguous(selectionParent, selection)) &&
                                 canWrapSelection(selection));
}
项目:intellij-ce-playground    文件:SurroundAction.java   
private static boolean isSelectionContiguous(RadContainer selectionParent,
                                             ArrayList<RadComponent> selection) {
  if (!selectionParent.getLayoutManager().isGrid()) {
    return false;
  }
  Rectangle rc = FormEditingUtil.getSelectionBounds(selection);
  for(RadComponent c: selectionParent.getComponents()) {
    if (!selection.contains(c) &&
        constraintsIntersect(true, c.getConstraints(), rc) &&
        constraintsIntersect(false, c.getConstraints(), rc)) {
      return false;
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:RowColumnAction.java   
public void actionPerformed(final AnActionEvent e) {
  GuiEditor editor = FormEditingUtil.getEditorFromContext(e.getDataContext());
  CaptionSelection selection = CaptionSelection.DATA_KEY.getData(e.getDataContext());
  if (editor == null || selection == null || !editor.ensureEditable()) {
    return;
  }
  actionPerformed(selection);
  selection.getContainer().revalidate();
  editor.refreshAndSave(true);
}
项目:intellij-ce-playground    文件:UngroupButtonsAction.java   
public static boolean isSameGroup(final GuiEditor editor, final ArrayList<RadComponent> selectedComponents) {
  final RadRootContainer rootContainer = editor.getRootContainer();
  IButtonGroup group = FormEditingUtil.findGroupForComponent(rootContainer, selectedComponents.get(0));
  if (group == null) {
    return false;
  }
  for(int i=1; i<selectedComponents.size(); i++) {
    if (FormEditingUtil.findGroupForComponent(rootContainer, selectedComponents.get(i)) != group) {
      return false;
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:DuplicateComponentsAction.java   
protected void update(@NotNull GuiEditor editor, final ArrayList<RadComponent> selection, final AnActionEvent e) {
  FormEditingUtil.remapToActionTargets(selection);
  final RadContainer parent = FormEditingUtil.getSelectionParent(selection);
  e.getPresentation().setEnabled(parent != null && (parent.getLayoutManager().isGrid() || parent.getLayoutManager().isIndexed()));
  // The action is enabled in any of the following cases:
  // 1) a single component is selected;
  // 2) all selected components have rowspan=1
  // 3) all selected components have the same row and rowspan
  if (selection.size() > 1 && parent != null && parent.getLayoutManager().isGrid()) {
    e.getPresentation().setEnabled(canDuplicate(selection, true) || canDuplicate(selection, false));
  }
}
项目:intellij-ce-playground    文件:AbstractMoveSelectionAction.java   
private void selectOrExtend(final RadComponent component) {
  if (myExtend) {
    FormEditingUtil.selectComponent(myEditor, component);
  }
  else {
    FormEditingUtil.selectSingleComponent(myEditor, component);
  }
}
项目:intellij-ce-playground    文件:AbstractMoveSelectionAction.java   
private void moveToFirstComponent(final JComponent rootContainerDelegee) {
  final int[] minX = new int[]{Integer.MAX_VALUE};
  final int[] minY = new int[]{Integer.MAX_VALUE};
  final Ref<RadComponent> componentToBeSelected = new Ref<RadComponent>();
  FormEditingUtil.iterate(
    myEditor.getRootContainer(),
    new FormEditingUtil.ComponentVisitor<RadComponent>() {
      public boolean visit(final RadComponent component) {
        if (component instanceof RadAtomicComponent) {
          final JComponent _delegee = component.getDelegee();
          final Point p = SwingUtilities.convertPoint(
            _delegee,
            new Point(0, 0),
            rootContainerDelegee
          );
          if(minX[0] > p.x || minY[0] > p.y){
            minX[0] = p.x;
            minY[0] = p.y;
            componentToBeSelected.set(component);
          }
        }
        return true;
      }
    }
  );
  if(!componentToBeSelected.isNull()){
    FormEditingUtil.selectComponent(myEditor, componentToBeSelected.get());
  }
}
项目:intellij-ce-playground    文件:FlattenAction.java   
private static void flattenGrid(final RadContainer container) {
  RadContainer parent = container.getParent();
  GridConstraints containerConstraints = (GridConstraints) container.getConstraints().clone();
  // ensure there will be enough rows and columns to fit the container contents
  for(int i=containerConstraints.getRowSpan(); i<container.getGridRowCount(); i++) {
    GridChangeUtil.splitRow(parent, containerConstraints.getRow());
  }
  for(int i=containerConstraints.getColSpan(); i<container.getGridColumnCount(); i++) {
    GridChangeUtil.splitColumn(parent, containerConstraints.getColumn());
  }

  ArrayList<RadComponent> contents = new ArrayList<RadComponent>();
  for(int i=container.getComponentCount()-1; i >= 0; i--) {
    contents.add(0, container.getComponent(i));
    container.removeComponent(container.getComponent(i));
  }

  if (contents.size() == 1) {
    contents.get(0).setCustomLayoutConstraints(container.getCustomLayoutConstraints());
  }

  FormEditingUtil.deleteComponents(Collections.singletonList(container), false);
  for(RadComponent child: contents) {
    final GridConstraints childConstraints = child.getConstraints();
    childConstraints.setRow(childConstraints.getRow() + containerConstraints.getRow());
    childConstraints.setColumn(childConstraints.getColumn() + containerConstraints.getColumn());
    parent.addComponent(child);
    child.revalidate();
  }
}