Java 类com.intellij.uiDesigner.compiler.Utils 实例源码

项目:intellij-ce-playground    文件:FormLayoutSerializer.java   
void readChildConstraints(final Element constraintsElement, final LwComponent component) {
  super.readChildConstraints(constraintsElement, component);
  CellConstraints cc = new CellConstraints();
  final Element formsElement = LwXmlReader.getChild(constraintsElement, UIFormXmlConstants.ELEMENT_FORMS);
  if (formsElement != null) {
    if (formsElement.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_TOP) != null) {
      cc.insets = LwXmlReader.readInsets(formsElement);
    }
    if (!LwXmlReader.getOptionalBoolean(formsElement, UIFormXmlConstants.ATTRIBUTE_DEFAULTALIGN_HORZ, true)) {
      cc.hAlign = ourHorizontalAlignments [Utils.alignFromConstraints(component.getConstraints(), true)];
    }
    if (!LwXmlReader.getOptionalBoolean(formsElement, UIFormXmlConstants.ATTRIBUTE_DEFAULTALIGN_VERT, true)) {
      cc.vAlign = ourVerticalAlignments [Utils.alignFromConstraints(component.getConstraints(), false)];
    }
  }
  component.setCustomLayoutConstraints(cc);
}
项目:intellij-ce-playground    文件:RadNestedForm.java   
public RadNestedForm(final ModuleProvider module, final String formFileName, final String id) throws Exception {
  super(module, JPanel.class, id);
  myFormFileName = formFileName;
  LOG.debug("Loading nested form " + formFileName);
  VirtualFile formFile = ResourceFileUtil.findResourceFileInDependents(getModule(), formFileName);
  if (formFile == null) {
    throw new IllegalArgumentException("Couldn't find virtual file for nested form " + formFileName);
  }
  Document doc = FileDocumentManager.getInstance().getDocument(formFile);
  final ClassLoader classLoader = LoaderFactory.getInstance(getProject()).getLoader(formFile);
  final LwRootContainer rootContainer = Utils.getRootContainer(doc.getText(), new CompiledClassPropertiesProvider(classLoader));
  myRootContainer = XmlReader.createRoot(module, rootContainer, classLoader, null);
  if (myRootContainer.getComponentCount() > 0) {
    getDelegee().setLayout(new BorderLayout());
    JComponent nestedFormDelegee = myRootContainer.getComponent(0).getDelegee();
    getDelegee().add(nestedFormDelegee, BorderLayout.CENTER);

    setRadComponentRecursive(nestedFormDelegee);
  }

  if (isCustomCreateRequired()) {
    setCustomCreate(true);
  }
}
项目:intellij-ce-playground    文件:RadFormLayoutManager.java   
public int getAlignment(RadComponent component, boolean horizontal) {
  CellConstraints cc = (CellConstraints) component.getCustomLayoutConstraints();
  CellConstraints.Alignment al = horizontal ? cc.hAlign : cc.vAlign;
  if (al == CellConstraints.DEFAULT) {
    FormLayout formLayout = (FormLayout) component.getParent().getLayout();
    FormSpec formSpec = horizontal
                        ? formLayout.getColumnSpec(component.getConstraints().getColumn()+1)
                        : formLayout.getRowSpec(component.getConstraints().getRow()+1);
    final FormSpec.DefaultAlignment defaultAlignment = formSpec.getDefaultAlignment();
    if (defaultAlignment.equals(RowSpec.FILL)) {
      return GridConstraints.ALIGN_FILL;
    }
    if (defaultAlignment.equals(RowSpec.TOP) || defaultAlignment.equals(ColumnSpec.LEFT)) {
      return GridConstraints.ALIGN_LEFT;
    }
    if (defaultAlignment.equals(RowSpec.CENTER)) {
      return GridConstraints.ALIGN_CENTER;
    }
    return GridConstraints.ALIGN_RIGHT;
  }
  return Utils.alignFromConstraints(component.getConstraints(), horizontal);
}
项目:intellij-ce-playground    文件:RadRootContainer.java   
public void write(final XmlWriter writer) {
  writer.startElement("form", Utils.FORM_NAMESPACE);
  try{
    writer.addAttribute("version", 1);
    final String classToBind = getClassToBind();
    if (classToBind != null){
      writer.addAttribute("bind-to-class", classToBind);
    }
    final String mainComponentBinding = getMainComponentBinding();
    if (mainComponentBinding != null) {
      writer.addAttribute("stored-main-component-binding", mainComponentBinding);
    }
    writeChildrenImpl(writer);
    if (myButtonGroups.size() > 0) {
      writer.startElement(UIFormXmlConstants.ELEMENT_BUTTON_GROUPS);
      for(RadButtonGroup group: myButtonGroups) {
        group.write(writer);
      }
      writer.endElement();
    }
    writeInspectionSuppressions(writer);
  }
  finally{
    writer.endElement(); // form
  }
}
项目:tools-idea    文件:FormLayoutSerializer.java   
void readChildConstraints(final Element constraintsElement, final LwComponent component) {
  super.readChildConstraints(constraintsElement, component);
  CellConstraints cc = new CellConstraints();
  final Element formsElement = LwXmlReader.getChild(constraintsElement, UIFormXmlConstants.ELEMENT_FORMS);
  if (formsElement != null) {
    if (formsElement.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_TOP) != null) {
      cc.insets = LwXmlReader.readInsets(formsElement);
    }
    if (!LwXmlReader.getOptionalBoolean(formsElement, UIFormXmlConstants.ATTRIBUTE_DEFAULTALIGN_HORZ, true)) {
      cc.hAlign = ourHorizontalAlignments [Utils.alignFromConstraints(component.getConstraints(), true)];
    }
    if (!LwXmlReader.getOptionalBoolean(formsElement, UIFormXmlConstants.ATTRIBUTE_DEFAULTALIGN_VERT, true)) {
      cc.vAlign = ourVerticalAlignments [Utils.alignFromConstraints(component.getConstraints(), false)];
    }
  }
  component.setCustomLayoutConstraints(cc);
}
项目:tools-idea    文件:RadNestedForm.java   
public RadNestedForm(final ModuleProvider module, final String formFileName, final String id) throws Exception {
  super(module, JPanel.class, id);
  myFormFileName = formFileName;
  LOG.debug("Loading nested form " + formFileName);
  VirtualFile formFile = ResourceFileUtil.findResourceFileInDependents(getModule(), formFileName);
  if (formFile == null) {
    throw new IllegalArgumentException("Couldn't find virtual file for nested form " + formFileName);
  }
  Document doc = FileDocumentManager.getInstance().getDocument(formFile);
  final ClassLoader classLoader = LoaderFactory.getInstance(getProject()).getLoader(formFile);
  final LwRootContainer rootContainer = Utils.getRootContainer(doc.getText(), new CompiledClassPropertiesProvider(classLoader));
  myRootContainer = XmlReader.createRoot(module, rootContainer, classLoader, null);
  if (myRootContainer.getComponentCount() > 0) {
    getDelegee().setLayout(new BorderLayout());
    JComponent nestedFormDelegee = myRootContainer.getComponent(0).getDelegee();
    getDelegee().add(nestedFormDelegee, BorderLayout.CENTER);

    setRadComponentRecursive(nestedFormDelegee);
  }

  if (isCustomCreateRequired()) {
    setCustomCreate(true);
  }
}
项目:tools-idea    文件:RadFormLayoutManager.java   
public int getAlignment(RadComponent component, boolean horizontal) {
  CellConstraints cc = (CellConstraints) component.getCustomLayoutConstraints();
  CellConstraints.Alignment al = horizontal ? cc.hAlign : cc.vAlign;
  if (al == CellConstraints.DEFAULT) {
    FormLayout formLayout = (FormLayout) component.getParent().getLayout();
    FormSpec formSpec = horizontal
                        ? formLayout.getColumnSpec(component.getConstraints().getColumn()+1)
                        : formLayout.getRowSpec(component.getConstraints().getRow()+1);
    final FormSpec.DefaultAlignment defaultAlignment = formSpec.getDefaultAlignment();
    if (defaultAlignment.equals(RowSpec.FILL)) {
      return GridConstraints.ALIGN_FILL;
    }
    if (defaultAlignment.equals(RowSpec.TOP) || defaultAlignment.equals(ColumnSpec.LEFT)) {
      return GridConstraints.ALIGN_LEFT;
    }
    if (defaultAlignment.equals(RowSpec.CENTER)) {
      return GridConstraints.ALIGN_CENTER;
    }
    return GridConstraints.ALIGN_RIGHT;
  }
  return Utils.alignFromConstraints(component.getConstraints(), horizontal);
}
项目:tools-idea    文件:RadRootContainer.java   
public void write(final XmlWriter writer) {
  writer.startElement("form", Utils.FORM_NAMESPACE);
  try{
    writer.addAttribute("version", 1);
    final String classToBind = getClassToBind();
    if (classToBind != null){
      writer.addAttribute("bind-to-class", classToBind);
    }
    final String mainComponentBinding = getMainComponentBinding();
    if (mainComponentBinding != null) {
      writer.addAttribute("stored-main-component-binding", mainComponentBinding);
    }
    writeChildrenImpl(writer);
    if (myButtonGroups.size() > 0) {
      writer.startElement(UIFormXmlConstants.ELEMENT_BUTTON_GROUPS);
      for(RadButtonGroup group: myButtonGroups) {
        group.write(writer);
      }
      writer.endElement();
    }
    writeInspectionSuppressions(writer);
  }
  finally{
    writer.endElement(); // form
  }
}
项目:consulo-ui-designer    文件:InsertComponentProcessor.java   
private boolean validateNestedFormInsert(final ComponentItem item)
{
    PsiFile boundForm = item.getBoundForm();
    if(boundForm != null)
    {
        try
        {
            final String formName = FormEditingUtil.buildResourceName(boundForm);
            final String targetForm = FormEditingUtil.buildResourceName(myEditor.getPsiFile());
            Utils.validateNestedFormLoop(formName, new PsiNestedFormLoader(myEditor.getModule()), targetForm);
        }
        catch(Exception ex)
        {
            Messages.showErrorDialog(myEditor, ex.getMessage(), CommonBundle.getErrorTitle());
            return false;
        }
    }
    return true;
}
项目:consulo-ui-designer    文件:BindingsCache.java   
public String getBoundClassName(final VirtualFile formFile) throws Exception
{
    File file = VfsUtil.virtualToIoFile(formFile);
    String classToBind = getSavedBinding(file);
    if(classToBind == null)
    {
        final Document doc = FileDocumentManager.getInstance().getDocument(formFile);
        final LwRootContainer rootContainer = Utils.getRootContainer(doc.getText(), null);
        classToBind = rootContainer.getClassToBind();
    }
    if(classToBind != null)
    {
        updateCache(file, classToBind);
    }
    return classToBind;
}
项目:consulo-ui-designer    文件:RadNestedForm.java   
public RadNestedForm(final ModuleProvider module, final String formFileName, final String id) throws Exception {
  super(module, JPanel.class, id);
  myFormFileName = formFileName;
  LOG.debug("Loading nested form " + formFileName);
  VirtualFile formFile = ResourceFileUtil.findResourceFileInDependents(getModule(), formFileName);
  if (formFile == null) {
    throw new IllegalArgumentException("Couldn't find virtual file for nested form " + formFileName);
  }
  Document doc = FileDocumentManager.getInstance().getDocument(formFile);
  final ClassLoader classLoader = LoaderFactory.getInstance(getProject()).getLoader(formFile);
  final LwRootContainer rootContainer = Utils.getRootContainer(doc.getText(), new CompiledClassPropertiesProvider(classLoader));
  myRootContainer = XmlReader.createRoot(module, rootContainer, classLoader, null);
  if (myRootContainer.getComponentCount() > 0) {
    getDelegee().setLayout(new BorderLayout());
    JComponent nestedFormDelegee = myRootContainer.getComponent(0).getDelegee();
    getDelegee().add(nestedFormDelegee, BorderLayout.CENTER);

    setRadComponentRecursive(nestedFormDelegee);
  }

  if (isCustomCreateRequired()) {
    setCustomCreate(true);
  }
}
项目:consulo-ui-designer    文件:RadFormLayoutManager.java   
public int getAlignment(RadComponent component, boolean horizontal) {
  CellConstraints cc = (CellConstraints) component.getCustomLayoutConstraints();
  CellConstraints.Alignment al = horizontal ? cc.hAlign : cc.vAlign;
  if (al == CellConstraints.DEFAULT) {
    FormLayout formLayout = (FormLayout) component.getParent().getLayout();
    FormSpec formSpec = horizontal
                        ? formLayout.getColumnSpec(component.getConstraints().getColumn()+1)
                        : formLayout.getRowSpec(component.getConstraints().getRow()+1);
    final FormSpec.DefaultAlignment defaultAlignment = formSpec.getDefaultAlignment();
    if (defaultAlignment.equals(RowSpec.FILL)) {
      return GridConstraints.ALIGN_FILL;
    }
    if (defaultAlignment.equals(RowSpec.TOP) || defaultAlignment.equals(ColumnSpec.LEFT)) {
      return GridConstraints.ALIGN_LEFT;
    }
    if (defaultAlignment.equals(RowSpec.CENTER)) {
      return GridConstraints.ALIGN_CENTER;
    }
    return GridConstraints.ALIGN_RIGHT;
  }
  return Utils.alignFromConstraints(component.getConstraints(), horizontal);
}
项目:consulo-ui-designer    文件:RadRootContainer.java   
public void write(final XmlWriter writer) {
  writer.startElement("form", Utils.FORM_NAMESPACE);
  try{
    writer.addAttribute("version", 1);
    final String classToBind = getClassToBind();
    if (classToBind != null){
      writer.addAttribute("bind-to-class", classToBind);
    }
    final String mainComponentBinding = getMainComponentBinding();
    if (mainComponentBinding != null) {
      writer.addAttribute("stored-main-component-binding", mainComponentBinding);
    }
    writeChildrenImpl(writer);
    if (myButtonGroups.size() > 0) {
      writer.startElement(UIFormXmlConstants.ELEMENT_BUTTON_GROUPS);
      for(RadButtonGroup group: myButtonGroups) {
        group.write(writer);
      }
      writer.endElement();
    }
    writeInspectionSuppressions(writer);
  }
  finally{
    writer.endElement(); // form
  }
}
项目:intellij-ce-playground    文件:LwRootContainer.java   
public void read(final Element element, final PropertiesProvider provider) throws Exception {
  if (element == null) {
    throw new IllegalArgumentException("element cannot be null");
  }
  if (!Utils.FORM_NAMESPACE.equals(element.getNamespace().getURI())) {
    throw new AlienFormFileException();
  }
  if(!"form".equals(element.getName())){
    throw new UnexpectedFormElementException("unexpected element: "+element);
  }

  setId("root");

  myClassToBind = element.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_BIND_TO_CLASS);

  // Constraints and properties
  for(Iterator i=element.getChildren().iterator(); i.hasNext();){
    final Element child = (Element)i.next();
    if (child.getName().equals(UIFormXmlConstants.ELEMENT_BUTTON_GROUPS)) {
      readButtonGroups(child);
    }
    else if (child.getName().equals(UIFormXmlConstants.ELEMENT_INSPECTION_SUPPRESSIONS)) {
      readInspectionSuppressions(child);
    }
    else {
      final LwComponent component = createComponentFromTag(child);
      addComponent(component);
      component.read(child, provider);
    }
  }

  myMainComponentBinding = element.getAttributeValue("stored-main-component-binding");
}
项目:intellij-ce-playground    文件:XmlReader.java   
private static RadErrorComponent createErrorComponent(final ModuleProvider module, final String id, final LwComponent lwComponent, final ClassLoader loader) {
  final String componentClassName = lwComponent.getComponentClassName();
  final String errorDescription = Utils.validateJComponentClass(loader, componentClassName, true);
  return RadErrorComponent.create(
    module,
    id,
    lwComponent.getComponentClassName(),
    lwComponent.getErrorComponentProperties(),
    errorDescription != null? errorDescription : UIDesignerBundle.message("error.cannot.load.class", componentClassName)
  );
}
项目:intellij-ce-playground    文件:ComponentItemDialog.java   
private boolean saveNestedForm() {
  VirtualFile formFile = ResourceFileUtil.findResourceFileInProject(myProject, myTfNestedForm.getText());
  if (formFile == null) {
    Messages.showErrorDialog(getWindow(), UIDesignerBundle.message("add.component.cannot.load.form", myTfNestedForm.getText()), CommonBundle.getErrorTitle());
    return false;
  }
  LwRootContainer lwRootContainer;
  try {
    lwRootContainer = Utils.getRootContainer(formFile.getInputStream(), null);
  }
  catch (Exception e) {
    Messages.showErrorDialog(getWindow(), e.getMessage(), CommonBundle.getErrorTitle());
    return false;
  }
  if (lwRootContainer.getClassToBind() == null) {
    Messages.showErrorDialog(getWindow(), UIDesignerBundle.message("add.component.form.not.bound"), CommonBundle.getErrorTitle());
    return false;
  }
  if (lwRootContainer.getComponent(0).getBinding() == null) {
    Messages.showErrorDialog(getWindow(), UIDesignerBundle.message("add.component.root.not.bound"),
                             CommonBundle.getErrorTitle());
    return false;
  }
  PsiClass psiClass =
    JavaPsiFacade.getInstance(myProject).findClass(lwRootContainer.getClassToBind(), GlobalSearchScope.projectScope(myProject));
  if (psiClass != null) {
    myItemToBeEdited.setClassName(getClassOrInnerName(psiClass));
  }
  else {
    myItemToBeEdited.setClassName(lwRootContainer.getClassToBind());
  }
  return true;
}
项目:intellij-ce-playground    文件:FormRelatedFilesProvider.java   
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull PsiElement context) {
  PsiClass psiClass = PsiTreeUtil.getParentOfType(context, PsiClass.class, false);
  if (psiClass != null) {
    while (psiClass != null) {
      List<PsiFile> forms = FormClassIndex.findFormsBoundToClass(psiClass.getProject(), psiClass);
      if (!forms.isEmpty()) {
        return GotoRelatedItem.createItems(forms, "UI Forms");
      }
      psiClass = PsiTreeUtil.getParentOfType(psiClass, PsiClass.class);
    }
  }
  else {
    PsiFile file = context.getContainingFile();
    if (file != null && file.getFileType() == GuiFormFileType.INSTANCE) {
      try {
        String className = Utils.getBoundClassName(file.getText());
        if (className != null) {
          Project project = file.getProject();
          PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project));
          if (aClass != null) {
            return Collections.singletonList(new GotoRelatedItem(aClass, "Java"));
          }
        }
      }
      catch (Exception ignore) {

      }
    }
  }
  return Collections.emptyList();
}
项目:intellij-ce-playground    文件:FormClassIndex.java   
@Override
@NotNull
public Map<String, Void> map(@NotNull final FileContent inputData) {
  String className = null;
  try {
    className = Utils.getBoundClassName(inputData.getContentAsText().toString());
  }
  catch (Exception e) {
    // ignore
  }
  if (className != null) {
    return Collections.singletonMap(className, null);
  }
  return Collections.emptyMap();
}
项目: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    文件:AlignProperty.java   
public Integer getValue(final RadComponent component) {
  AlignPropertyProvider provider = getAlignPropertyProvider(component);
  if (provider != null) {
    return provider.getAlignment(component, myHorizontal);
  }
  return Utils.alignFromConstraints(component.getConstraints(), myHorizontal);
}
项目:intellij-ce-playground    文件:AlignProperty.java   
@Override
public boolean isModified(final RadComponent component) {
  AlignPropertyProvider provider = getAlignPropertyProvider(component);
  if (provider != null) {
    return provider.isAlignmentModified(component, myHorizontal);
  }
  final ComponentItem item = component.getPalette().getItem(component.getComponentClassName());
  if (item == null) return false;
  return Utils.alignFromConstraints(component.getConstraints(), myHorizontal) !=
         Utils.alignFromConstraints(item.getDefaultConstraints(), myHorizontal);
}
项目:intellij-ce-playground    文件:AlignProperty.java   
@Override
public void resetValue(final RadComponent component) throws Exception {
  AlignPropertyProvider provider = getAlignPropertyProvider(component);
  if (provider != null) {
    provider.resetAlignment(component, myHorizontal);
  }
  else {
    final ComponentItem item = component.getPalette().getItem(component.getComponentClassName());
    if (item != null) {
      setValueEx(component, Utils.alignFromConstraints(item.getDefaultConstraints(), myHorizontal));
    }
  }
}
项目:intellij-ce-playground    文件:InsertComponentProcessor.java   
private boolean validateNestedFormInsert(final ComponentItem item) {
  PsiFile boundForm = item.getBoundForm();
  if (boundForm != null) {
    try {
      final String formName = FormEditingUtil.buildResourceName(boundForm);
      final String targetForm = FormEditingUtil.buildResourceName(myEditor.getPsiFile());
      Utils.validateNestedFormLoop(formName, new PsiNestedFormLoader(myEditor.getModule()), targetForm);
    }
    catch (Exception ex) {
      Messages.showErrorDialog(myEditor, ex.getMessage(), CommonBundle.getErrorTitle());
      return false;
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:BaseFormInspection.java   
@Nullable public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
  if (file.getFileType().equals(StdFileTypes.GUI_DESIGNER_FORM)) {
    final VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null) {
      return null;
    }
    final Module module = ModuleUtil.findModuleForFile(virtualFile, file.getProject());
    if (module == null) {
      return null;
    }

    final LwRootContainer rootContainer;
    try {
      rootContainer = Utils.getRootContainer(file.getText(), new PsiPropertiesProvider(module));
    }
    catch (Exception e) {
      return null;
    }

    if (rootContainer.isInspectionSuppressed(getShortName(), null)) {
      return null;
    }
    final FormFileErrorCollector collector = new FormFileErrorCollector(file, manager, isOnTheFly);
    startCheckForm(rootContainer);
    FormEditingUtil.iterate(rootContainer, new FormEditingUtil.ComponentVisitor() {
      public boolean visit(final IComponent component) {
        if (!rootContainer.isInspectionSuppressed(getShortName(), component.getId())) {
          checkComponentProperties(module, component, collector);
        }
        return true;
      }
    });
    doneCheckForm(rootContainer);
    return collector.result();
  }
  return null;
}
项目:intellij-ce-playground    文件:LayoutSourceGenerator.java   
protected void generateLayoutWithGaps(final LwContainer component,
                                      final FormSourceCodeGenerator generator,
                                      final String variable,
                                      final Class<? extends LayoutManager> layoutClass) {
  generator.startMethodCall(variable, "setLayout");

  generator.startConstructor(layoutClass.getName());
  generator.push(Utils.getHGap(component.getLayout()));
  generator.push(Utils.getVGap(component.getLayout()));
  generator.endConstructor();

  generator.endMethod();
}
项目:intellij-ce-playground    文件:PsiNestedFormLoader.java   
public LwRootContainer loadForm(String formFileName) throws Exception {
  if (myFormCache.containsKey(formFileName)) {
    return myFormCache.get(formFileName);
  }
  VirtualFile formFile = ResourceFileUtil.findResourceFileInDependents(myModule, formFileName);
  if (formFile == null) {
    throw new Exception("Could not find nested form file " + formFileName);
  }
  final LwRootContainer container = Utils.getRootContainer(formFile.getInputStream(), new PsiPropertiesProvider(myModule));
  myFormCache.put(formFileName, container);
  return container;
}
项目:intellij-ce-playground    文件:BindingsCache.java   
public String getBoundClassName(final VirtualFile formFile) throws Exception {
  String classToBind = getSavedBinding(formFile);
  if (classToBind == null) {
    final Document doc = FileDocumentManager.getInstance().getDocument(formFile);
    final LwRootContainer rootContainer = Utils.getRootContainer(doc.getText(), null);
    classToBind = rootContainer.getClassToBind();
  }
  if (classToBind != null) {
    updateCache(formFile, classToBind);
  }
  return classToBind;
}
项目:intellij-ce-playground    文件:CutCopyPasteSupport.java   
private static String serializeForCopy(final GuiEditor editor, final List<RadComponent> components) {
  final XmlWriter writer = new XmlWriter();

  writer.startElement(ELEMENT_SERIALIZED, Utils.FORM_NAMESPACE);

  for (final RadComponent component : components) {
    final Point shift;
    if (component.getParent() != null) {
      shift = SwingUtilities.convertPoint(
        component.getParent().getDelegee(),
        component.getX(),
        component.getY(),
        editor.getRootContainer().getDelegee()
      );
    }
    else {
      shift = new Point(0, 0);
    }

    component.getX();

    writer.startElement("item");
    writer.addAttribute(ATTRIBUTE_X, shift.x);
    writer.addAttribute(ATTRIBUTE_Y, shift.y);
    if (component.getParent() != null) {
      final String parentLayout = component.getParent().getLayoutManager().getName();
      if (parentLayout != null) {
        writer.addAttribute(ATTRIBUTE_PARENT_LAYOUT, parentLayout);
      }
    }
    component.write(writer);

    writer.endElement();
  }

  writer.endElement();

  return writer.getText();
}
项目:tools-idea    文件:LwRootContainer.java   
public void read(final Element element, final PropertiesProvider provider) throws Exception {
  if (element == null) {
    throw new IllegalArgumentException("element cannot be null");
  }
  if (!Utils.FORM_NAMESPACE.equals(element.getNamespace().getURI())) {
    throw new AlienFormFileException();
  }
  if(!"form".equals(element.getName())){
    throw new UnexpectedFormElementException("unexpected element: "+element);
  }

  setId("root");

  myClassToBind = element.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_BIND_TO_CLASS);

  // Constraints and properties
  for(Iterator i=element.getChildren().iterator(); i.hasNext();){
    final Element child = (Element)i.next();
    if (child.getName().equals(UIFormXmlConstants.ELEMENT_BUTTON_GROUPS)) {
      readButtonGroups(child);
    }
    else if (child.getName().equals(UIFormXmlConstants.ELEMENT_INSPECTION_SUPPRESSIONS)) {
      readInspectionSuppressions(child);
    }
    else {
      final LwComponent component = createComponentFromTag(child);
      addComponent(component);
      component.read(child, provider);
    }
  }

  myMainComponentBinding = element.getAttributeValue("stored-main-component-binding");
}
项目:tools-idea    文件:XmlReader.java   
private static RadErrorComponent createErrorComponent(final ModuleProvider module, final String id, final LwComponent lwComponent, final ClassLoader loader) {
  final String componentClassName = lwComponent.getComponentClassName();
  final String errorDescription = Utils.validateJComponentClass(loader, componentClassName, true);
  return RadErrorComponent.create(
    module,
    id,
    lwComponent.getComponentClassName(),
    lwComponent.getErrorComponentProperties(),
    errorDescription != null? errorDescription : UIDesignerBundle.message("error.cannot.load.class", componentClassName)
  );
}
项目:tools-idea    文件:ComponentItemDialog.java   
private boolean saveNestedForm() {
  VirtualFile formFile = ResourceFileUtil.findResourceFileInProject(myProject, myTfNestedForm.getText());
  if (formFile == null) {
    Messages.showErrorDialog(getWindow(), UIDesignerBundle.message("add.component.cannot.load.form", myTfNestedForm.getText()), CommonBundle.getErrorTitle());
    return false;
  }
  LwRootContainer lwRootContainer;
  try {
    lwRootContainer = Utils.getRootContainer(formFile.getInputStream(), null);
  }
  catch (Exception e) {
    Messages.showErrorDialog(getWindow(), e.getMessage(), CommonBundle.getErrorTitle());
    return false;
  }
  if (lwRootContainer.getClassToBind() == null) {
    Messages.showErrorDialog(getWindow(), UIDesignerBundle.message("add.component.form.not.bound"), CommonBundle.getErrorTitle());
    return false;
  }
  if (lwRootContainer.getComponent(0).getBinding() == null) {
    Messages.showErrorDialog(getWindow(), UIDesignerBundle.message("add.component.root.not.bound"),
                             CommonBundle.getErrorTitle());
    return false;
  }
  PsiClass psiClass =
    JavaPsiFacade.getInstance(myProject).findClass(lwRootContainer.getClassToBind(), GlobalSearchScope.projectScope(myProject));
  if (psiClass != null) {
    myItemToBeEdited.setClassName(getClassOrInnerName(psiClass));
  }
  else {
    myItemToBeEdited.setClassName(lwRootContainer.getClassToBind());
  }
  return true;
}
项目:tools-idea    文件:FormRelatedFilesProvider.java   
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull PsiElement context) {
  PsiClass psiClass = PsiTreeUtil.getParentOfType(context, PsiClass.class, false);
  if (psiClass != null) {
    while (psiClass != null) {
      List<PsiFile> forms = FormClassIndex.findFormsBoundToClass(psiClass);
      if (!forms.isEmpty()) {
        return GotoRelatedItem.createItems(forms, "UI Forms");
      }
      psiClass = PsiTreeUtil.getParentOfType(psiClass, PsiClass.class);
    }
  }
  else {
    PsiFile file = context.getContainingFile();
    if (file.getFileType() == GuiFormFileType.INSTANCE) {
      try {
        String className = Utils.getBoundClassName(file.getText());
        if (className != null) {
          Project project = file.getProject();
          PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project));
          if (aClass != null) {
            return Collections.singletonList(new GotoRelatedItem(aClass, "Java"));
          }
        }
      }
      catch (Exception ignore) {

      }
    }
  }
  return Collections.emptyList();
}
项目:tools-idea    文件:FormClassIndex.java   
@Override
@NotNull
public Map<String, Void> map(final FileContent inputData) {
  String className = null;
  try {
    className = Utils.getBoundClassName(inputData.getContentAsText().toString());
  }
  catch (Exception e) {
    // ignore
  }
  if (className != null) {
    return Collections.singletonMap(className, null);
  }
  return Collections.emptyMap();
}
项目:tools-idea    文件: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);
      }
    }
  }
}
项目:tools-idea    文件:AlignProperty.java   
public Integer getValue(final RadComponent component) {
  AlignPropertyProvider provider = getAlignPropertyProvider(component);
  if (provider != null) {
    return provider.getAlignment(component, myHorizontal);
  }
  return Utils.alignFromConstraints(component.getConstraints(), myHorizontal);
}
项目:tools-idea    文件:AlignProperty.java   
@Override
public boolean isModified(final RadComponent component) {
  AlignPropertyProvider provider = getAlignPropertyProvider(component);
  if (provider != null) {
    return provider.isAlignmentModified(component, myHorizontal);
  }
  final ComponentItem item = component.getPalette().getItem(component.getComponentClassName());
  if (item == null) return false;
  return Utils.alignFromConstraints(component.getConstraints(), myHorizontal) !=
         Utils.alignFromConstraints(item.getDefaultConstraints(), myHorizontal);
}
项目:tools-idea    文件:AlignProperty.java   
@Override
public void resetValue(final RadComponent component) throws Exception {
  AlignPropertyProvider provider = getAlignPropertyProvider(component);
  if (provider != null) {
    provider.resetAlignment(component, myHorizontal);
  }
  else {
    final ComponentItem item = component.getPalette().getItem(component.getComponentClassName());
    if (item != null) {
      setValueEx(component, Utils.alignFromConstraints(item.getDefaultConstraints(), myHorizontal));
    }
  }
}
项目:tools-idea    文件:InsertComponentProcessor.java   
private boolean validateNestedFormInsert(final ComponentItem item) {
  PsiFile boundForm = item.getBoundForm();
  if (boundForm != null) {
    try {
      final String formName = FormEditingUtil.buildResourceName(boundForm);
      final String targetForm = FormEditingUtil.buildResourceName(myEditor.getPsiFile());
      Utils.validateNestedFormLoop(formName, new PsiNestedFormLoader(myEditor.getModule()), targetForm);
    }
    catch (Exception ex) {
      Messages.showErrorDialog(myEditor, ex.getMessage(), CommonBundle.getErrorTitle());
      return false;
    }
  }
  return true;
}
项目:tools-idea    文件:BaseFormInspection.java   
@Nullable public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
  if (file.getFileType().equals(StdFileTypes.GUI_DESIGNER_FORM)) {
    final VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null) {
      return null;
    }
    final Module module = ModuleUtil.findModuleForFile(virtualFile, file.getProject());
    if (module == null) {
      return null;
    }

    final LwRootContainer rootContainer;
    try {
      rootContainer = Utils.getRootContainer(file.getText(), new PsiPropertiesProvider(module));
    }
    catch (Exception e) {
      return null;
    }

    if (rootContainer.isInspectionSuppressed(getShortName(), null)) {
      return null;
    }
    final FormFileErrorCollector collector = new FormFileErrorCollector(file, manager, isOnTheFly);
    startCheckForm(rootContainer);
    FormEditingUtil.iterate(rootContainer, new FormEditingUtil.ComponentVisitor() {
      public boolean visit(final IComponent component) {
        if (!rootContainer.isInspectionSuppressed(getShortName(), component.getId())) {
          checkComponentProperties(module, component, collector);
        }
        return true;
      }
    });
    doneCheckForm(rootContainer);
    return collector.result();
  }
  return null;
}
项目:tools-idea    文件:LayoutSourceGenerator.java   
protected void generateLayoutWithGaps(final LwContainer component,
                                      final FormSourceCodeGenerator generator,
                                      final String variable,
                                      final Class<? extends LayoutManager> layoutClass) {
  generator.startMethodCall(variable, "setLayout");

  generator.startConstructor(layoutClass.getName());
  generator.push(Utils.getHGap(component.getLayout()));
  generator.push(Utils.getVGap(component.getLayout()));
  generator.endConstructor();

  generator.endMethod();
}