Java 类com.intellij.uiDesigner.lw.IContainer 实例源码

项目: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);
}
项目:tools-idea    文件: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);
}
项目:consulo-ui-designer    文件:FormEditingUtil.java   
/**
 * Finds component with the specified <code>id</code> starting from the
 * <code>container</code>. The method goes recursively through the hierarchy
 * of components. Note, that if <code>container</code> itself has <code>id</code>
 * then the method immediately retuns it.
 *
 * @return the found component.
 */
@Nullable
public static IComponent findComponent(@NotNull final IComponent component, @NotNull final String id)
{
    if(id.equals(component.getId()))
    {
        return component;
    }
    if(!(component instanceof IContainer))
    {
        return null;
    }

    final IContainer uiContainer = (IContainer) component;
    for(int i = 0; i < uiContainer.getComponentCount(); i++)
    {
        final IComponent found = findComponent(uiContainer.getComponent(i), id);
        if(found != null)
        {
            return found;
        }
    }
    return null;
}
项目:consulo-ui-designer    文件: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    文件:NoButtonGroupInspection.java   
protected void checkComponentProperties(Module module, IComponent component, FormErrorCollector collector) {
  if (FormInspectionUtil.isComponentClass(module, component, JRadioButton.class)) {
    final IRootContainer root = FormEditingUtil.getRoot(component);
    if (root == null) return;
    if (root.getButtonGroupName(component) == null) {
      EditorQuickFixProvider quickFixProvider = null;
      IContainer parent = component.getParentContainer();
      for(int i=0; i<parent.getComponentCount(); i++) {
        IComponent child = parent.getComponent(i);
        if (child != component &&
            FormInspectionUtil.isComponentClass(module, child, JRadioButton.class)) {
          final GridConstraints c1 = component.getConstraints();
          final GridConstraints c2 = child.getConstraints();
          if (areCellsAdjacent(parent, c1, c2)) {
            final String groupName = root.getButtonGroupName(child);
            if (groupName == null) {
              quickFixProvider = new EditorQuickFixProvider() {
                 public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                   return new CreateGroupQuickFix(editor, component, c1.getColumn() == c2.getColumn());
                 }
               };
              break;
            }
            else {
              quickFixProvider = new EditorQuickFixProvider() {
                public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                  return new AddToGroupQuickFix(editor, component, groupName);
                }
              };
            }
          }
        }
      }
      collector.addError(getID(), component, null, UIDesignerBundle.message("inspection.no.button.group.error"), quickFixProvider);
    }
  }
}
项目:tools-idea    文件:NoButtonGroupInspection.java   
protected void checkComponentProperties(Module module, IComponent component, FormErrorCollector collector) {
  if (FormInspectionUtil.isComponentClass(module, component, JRadioButton.class)) {
    final IRootContainer root = FormEditingUtil.getRoot(component);
    if (root == null) return;
    if (root.getButtonGroupName(component) == null) {
      EditorQuickFixProvider quickFixProvider = null;
      IContainer parent = component.getParentContainer();
      for(int i=0; i<parent.getComponentCount(); i++) {
        IComponent child = parent.getComponent(i);
        if (child != component &&
            FormInspectionUtil.isComponentClass(module, child, JRadioButton.class)) {
          final GridConstraints c1 = component.getConstraints();
          final GridConstraints c2 = child.getConstraints();
          if (areCellsAdjacent(parent, c1, c2)) {
            final String groupName = root.getButtonGroupName(child);
            if (groupName == null) {
              quickFixProvider = new EditorQuickFixProvider() {
                 public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                   return new CreateGroupQuickFix(editor, component, c1.getColumn() == c2.getColumn());
                 }
               };
              break;
            }
            else {
              quickFixProvider = new EditorQuickFixProvider() {
                public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                  return new AddToGroupQuickFix(editor, component, groupName);
                }
              };
            }
          }
        }
      }
      collector.addError(getID(), component, null, UIDesignerBundle.message("inspection.no.button.group.error"), quickFixProvider);
    }
  }
}
项目:consulo-ui-designer    文件:FormEditingUtil.java   
private static boolean iterateImpl(final IComponent component, final ComponentVisitor visitor)
{
    final boolean shouldContinue;
    try
    {
        shouldContinue = visitor.visit(component);
    }
    catch(ProcessCanceledException ex)
    {
        return false;
    }
    if(!shouldContinue)
    {
        return false;
    }

    if(!(component instanceof IContainer))
    {
        return true;
    }

    final IContainer container = (IContainer) component;

    for(int i = 0; i < container.getComponentCount(); i++)
    {
        final IComponent c = container.getComponent(i);
        if(!iterateImpl(c, visitor))
        {
            return false;
        }
    }

    return true;
}
项目:consulo-ui-designer    文件:NoButtonGroupInspection.java   
protected void checkComponentProperties(Module module, IComponent component, FormErrorCollector collector) {
  if (FormInspectionUtil.isComponentClass(module, component, JRadioButton.class)) {
    final IRootContainer root = FormEditingUtil.getRoot(component);
    if (root == null) return;
    if (root.getButtonGroupName(component) == null) {
      EditorQuickFixProvider quickFixProvider = null;
      IContainer parent = component.getParentContainer();
      for(int i=0; i<parent.getComponentCount(); i++) {
        IComponent child = parent.getComponent(i);
        if (child != component &&
            FormInspectionUtil.isComponentClass(module, child, JRadioButton.class)) {
          final GridConstraints c1 = component.getConstraints();
          final GridConstraints c2 = child.getConstraints();
          if (areCellsAdjacent(parent, c1, c2)) {
            final String groupName = root.getButtonGroupName(child);
            if (groupName == null) {
              quickFixProvider = new EditorQuickFixProvider() {
                 public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                   return new CreateGroupQuickFix(editor, component, c1.getColumn() == c2.getColumn());
                 }
               };
              break;
            }
            else {
              quickFixProvider = new EditorQuickFixProvider() {
                public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                  return new AddToGroupQuickFix(editor, component, groupName);
                }
              };
            }
          }
        }
      }
      collector.addError(getID(), component, null, UIDesignerBundle.message("inspection.no.button.group.error"), quickFixProvider);
    }
  }
}
项目:intellij-ce-playground    文件:CreateFieldFix.java   
private static void createField(final Project project,
                                final PsiClass fieldClass,
                                final String fieldName,
                                final PsiClass boundClass,
                                final boolean showErrors,
                                final IContainer rootContainer) {
  // 1. Create field
  final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
  final PsiType type = factory.createType(fieldClass);
  try {
    final PsiField field = factory.createField(fieldName, type);
    final String accessibility = GuiDesignerConfiguration.getInstance(project).DEFAULT_FIELD_ACCESSIBILITY;
    final PsiModifierList modifierList = field.getModifierList();
    assert modifierList != null;
    String[] modifiers = {PsiModifier.PRIVATE, PsiModifier.PROTECTED, PsiModifier.PUBLIC};
    for(@PsiModifier.ModifierConstant String modifier: modifiers) {
      modifierList.setModifierProperty(modifier, accessibility.equals(modifier));
    }
    PsiField lastUiField = null;
    for(PsiField uiField: boundClass.getFields()) {
      if (FormEditingUtil.findComponentWithBinding(rootContainer, uiField.getName()) != null) {
        lastUiField = uiField;
      }
    }
    if (lastUiField != null) {
      boundClass.addAfter(field, lastUiField);
    }
    else {
      boundClass.add(field);
    }
  }
  catch (final IncorrectOperationException exc) {
    if (showErrors) {
      ApplicationManager.getApplication().invokeLater(
        new Runnable() {
          public void run() {
            Messages.showErrorDialog(
              project,
              UIDesignerBundle.message("error.cannot.create.field.reason", fieldName, exc.getMessage()),
              CommonBundle.getErrorTitle()
            );
          }
        }
      );
    }
  }
}
项目:tools-idea    文件:CreateFieldFix.java   
private static void createField(final Project project,
                                final PsiClass fieldClass,
                                final String fieldName,
                                final PsiClass boundClass,
                                final boolean showErrors,
                                final IContainer rootContainer) {
  // 1. Create field
  final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
  final PsiType type = factory.createType(fieldClass);
  try {
    final PsiField field = factory.createField(fieldName, type);
    final String accessibility = GuiDesignerConfiguration.getInstance(project).DEFAULT_FIELD_ACCESSIBILITY;
    final PsiModifierList modifierList = field.getModifierList();
    assert modifierList != null;
    String[] modifiers = {PsiModifier.PRIVATE, PsiModifier.PROTECTED, PsiModifier.PUBLIC};
    for(@PsiModifier.ModifierConstant String modifier: modifiers) {
      modifierList.setModifierProperty(modifier, accessibility.equals(modifier));
    }
    PsiField lastUiField = null;
    for(PsiField uiField: boundClass.getFields()) {
      if (FormEditingUtil.findComponentWithBinding(rootContainer, uiField.getName()) != null) {
        lastUiField = uiField;
      }
    }
    if (lastUiField != null) {
      boundClass.addAfter(field, lastUiField);
    }
    else {
      boundClass.add(field);
    }
  }
  catch (final IncorrectOperationException exc) {
    if (showErrors) {
      ApplicationManager.getApplication().invokeLater(
        new Runnable() {
          public void run() {
            Messages.showErrorDialog(
              project,
              UIDesignerBundle.message("error.cannot.create.field.reason", fieldName, exc.getMessage()),
              CommonBundle.getErrorTitle()
            );
          }
        }
      );
    }
  }
}
项目:consulo-ui-designer    文件:CreateFieldFix.java   
private static void createField(final Project project,
                                final PsiClass fieldClass,
                                final String fieldName,
                                final PsiClass boundClass,
                                final boolean showErrors,
                                final IContainer rootContainer) {
  // 1. Create field
  final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
  final PsiType type = factory.createType(fieldClass);
  try {
    final PsiField field = factory.createField(fieldName, type);
    final String accessibility = GuiDesignerConfiguration.getInstance(project).DEFAULT_FIELD_ACCESSIBILITY;
    final PsiModifierList modifierList = field.getModifierList();
    assert modifierList != null;
    String[] modifiers = {PsiModifier.PRIVATE, PsiModifier.PROTECTED, PsiModifier.PUBLIC};
    for(@PsiModifier.ModifierConstant String modifier: modifiers) {
      modifierList.setModifierProperty(modifier, accessibility.equals(modifier));
    }
    PsiField lastUiField = null;
    for(PsiField uiField: boundClass.getFields()) {
      if (FormEditingUtil.findComponentWithBinding(rootContainer, uiField.getName()) != null) {
        lastUiField = uiField;
      }
    }
    if (lastUiField != null) {
      boundClass.addAfter(field, lastUiField);
    }
    else {
      boundClass.add(field);
    }
  }
  catch (final IncorrectOperationException exc) {
    if (showErrors) {
      ApplicationManager.getApplication().invokeLater(
        new Runnable() {
          public void run() {
            Messages.showErrorDialog(
              project,
              UIDesignerBundle.message("error.cannot.create.field.reason", fieldName, exc.getMessage()),
              CommonBundle.getErrorTitle()
            );
          }
        }
      );
    }
  }
}