Java 类com.intellij.uiDesigner.propertyInspector.properties.BindingProperty 实例源码

项目:intellij-ce-playground    文件:DuplicateComponentsAction.java   
private static void adjustDuplicates(final Map<RadComponent, RadComponent> duplicates) {
  for(RadComponent c: duplicates.keySet()) {
    RadComponent copy = duplicates.get(c);
    if (c.getBinding() != null) {
      String binding = BindingProperty.getDefaultBinding(copy);
      new BindingProperty(c.getProject()).setValueEx(copy, binding);
      copy.setDefaultBinding(true);
    }
    for(IProperty prop: copy.getModifiedProperties()) {
      if (prop instanceof IntroComponentProperty) {
        final IntroComponentProperty componentProperty = (IntroComponentProperty)prop;
        String copyValue = componentProperty.getValue(copy);
        for(RadComponent original: duplicates.keySet()) {
          if (original.getId().equals(copyValue)) {
            componentProperty.setValueEx(copy, duplicates.get(original).getId());
          }
        }
      }
    }
  }
}
项目:tools-idea    文件:DuplicateComponentsAction.java   
private static void adjustDuplicates(final Map<RadComponent, RadComponent> duplicates) {
  for(RadComponent c: duplicates.keySet()) {
    RadComponent copy = duplicates.get(c);
    if (c.getBinding() != null) {
      String binding = BindingProperty.getDefaultBinding(copy);
      new BindingProperty(c.getProject()).setValueEx(copy, binding);
      copy.setDefaultBinding(true);
    }
    for(IProperty prop: copy.getModifiedProperties()) {
      if (prop instanceof IntroComponentProperty) {
        final IntroComponentProperty componentProperty = (IntroComponentProperty)prop;
        String copyValue = componentProperty.getValue(copy);
        for(RadComponent original: duplicates.keySet()) {
          if (original.getId().equals(copyValue)) {
            componentProperty.setValueEx(copy, duplicates.get(original).getId());
          }
        }
      }
    }
  }
}
项目:consulo-ui-designer    文件:DuplicateComponentsAction.java   
private static void adjustDuplicates(final Map<RadComponent, RadComponent> duplicates) {
  for(RadComponent c: duplicates.keySet()) {
    RadComponent copy = duplicates.get(c);
    if (c.getBinding() != null) {
      String binding = BindingProperty.getDefaultBinding(copy);
      new BindingProperty(c.getProject()).setValueEx(copy, binding);
      copy.setDefaultBinding(true);
    }
    for(IProperty prop: copy.getModifiedProperties()) {
      if (prop instanceof IntroComponentProperty) {
        final IntroComponentProperty componentProperty = (IntroComponentProperty)prop;
        String copyValue = componentProperty.getValue(copy);
        for(RadComponent original: duplicates.keySet()) {
          if (original.getId().equals(copyValue)) {
            componentProperty.setValueEx(copy, duplicates.get(original).getId());
          }
        }
      }
    }
  }
}
项目: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    文件:MorphAction.java   
private static void updateBoundFieldType(final GuiEditor editor, final RadComponent oldComponent, final ComponentItem targetItem) {
  PsiField oldBoundField = BindingProperty.findBoundField(editor.getRootContainer(), oldComponent.getBinding());
  if (oldBoundField != null) {
    final PsiElementFactory factory = JavaPsiFacade.getInstance(editor.getProject()).getElementFactory();
    try {
      PsiType componentType = factory.createTypeFromText(targetItem.getClassName().replace('$', '.'), null);
      new ChangeFieldTypeFix(editor, oldBoundField, componentType).run();
    }
    catch (IncorrectOperationException e) {
      LOG.error(e);
    }
  }
}
项目:intellij-ce-playground    文件:ButtonGroupPropertiesPanel.java   
private void saveButtonGroupIsBound() {
  if (myGroup.isBound() != myBindToFieldCheckBox.isSelected()) {
    myGroup.setBound(myBindToFieldCheckBox.isSelected());
    notifyListeners(new ChangeEvent(myGroup));
    if (myGroup.isBound()) {
      BindingProperty.updateBoundFieldName(myRootContainer, null, myGroup.getName(), ButtonGroup.class.getName());
    }
    else {
      BindingProperty.checkRemoveUnusedField(myRootContainer, myGroup.getName(),
                                             FormEditingUtil.getNextSaveUndoGroupId(myRootContainer.getProject()));
    }
  }
}
项目:intellij-ce-playground    文件:ButtonGroupPropertiesPanel.java   
private void saveButtonGroupName() {
  String oldName = myGroup.getName();
  String newName = myNameTextField.getText();
  if (!oldName.equals(newName)) {
    myGroup.setName(newName);
    notifyListeners(new ChangeEvent(myGroup));
    if (myGroup.isBound()) {
      BindingProperty.updateBoundFieldName(myRootContainer, oldName, newName, ButtonGroup.class.getName());
    }
  }
}
项目:tools-idea    文件: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;
}
项目:tools-idea    文件:MorphAction.java   
private static void updateBoundFieldType(final GuiEditor editor, final RadComponent oldComponent, final ComponentItem targetItem) {
  PsiField oldBoundField = BindingProperty.findBoundField(editor.getRootContainer(), oldComponent.getBinding());
  if (oldBoundField != null) {
    final PsiElementFactory factory = JavaPsiFacade.getInstance(editor.getProject()).getElementFactory();
    try {
      PsiType componentType = factory.createTypeFromText(targetItem.getClassName().replace('$', '.'), null);
      new ChangeFieldTypeFix(editor, oldBoundField, componentType).run();
    }
    catch (IncorrectOperationException e) {
      LOG.error(e);
    }
  }
}
项目:tools-idea    文件:ButtonGroupPropertiesPanel.java   
private void saveButtonGroupIsBound() {
  if (myGroup.isBound() != myBindToFieldCheckBox.isSelected()) {
    myGroup.setBound(myBindToFieldCheckBox.isSelected());
    notifyListeners(new ChangeEvent(myGroup));
    if (myGroup.isBound()) {
      BindingProperty.updateBoundFieldName(myRootContainer, null, myGroup.getName(), ButtonGroup.class.getName());
    }
    else {
      BindingProperty.checkRemoveUnusedField(myRootContainer, myGroup.getName(),
                                             FormEditingUtil.getNextSaveUndoGroupId(myRootContainer.getProject()));
    }
  }
}
项目:tools-idea    文件:ButtonGroupPropertiesPanel.java   
private void saveButtonGroupName() {
  String oldName = myGroup.getName();
  String newName = myNameTextField.getText();
  if (!oldName.equals(newName)) {
    myGroup.setName(newName);
    notifyListeners(new ChangeEvent(myGroup));
    if (myGroup.isBound()) {
      BindingProperty.updateBoundFieldName(myRootContainer, oldName, newName, ButtonGroup.class.getName());
    }
  }
}
项目:consulo-ui-designer    文件: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;
}
项目:consulo-ui-designer    文件:MorphAction.java   
private static void updateBoundFieldType(final GuiEditor editor, final RadComponent oldComponent, final ComponentItem targetItem) {
  PsiField oldBoundField = BindingProperty.findBoundField(editor.getRootContainer(), oldComponent.getBinding());
  if (oldBoundField != null) {
    final PsiElementFactory factory = JavaPsiFacade.getInstance(editor.getProject()).getElementFactory();
    try {
      PsiType componentType = factory.createTypeFromText(targetItem.getClassName().replace('$', '.'), null);
      new ChangeFieldTypeFix(editor, oldBoundField, componentType).run();
    }
    catch (IncorrectOperationException e) {
      LOG.error(e);
    }
  }
}
项目:consulo-ui-designer    文件:ButtonGroupPropertiesPanel.java   
private void saveButtonGroupIsBound() {
  if (myGroup.isBound() != myBindToFieldCheckBox.isSelected()) {
    myGroup.setBound(myBindToFieldCheckBox.isSelected());
    notifyListeners(new ChangeEvent(myGroup));
    if (myGroup.isBound()) {
      BindingProperty.updateBoundFieldName(myRootContainer, null, myGroup.getName(), ButtonGroup.class.getName());
    }
    else {
      BindingProperty.checkRemoveUnusedField(myRootContainer, myGroup.getName(),
                                             FormEditingUtil.getNextSaveUndoGroupId(myRootContainer.getProject()));
    }
  }
}
项目:consulo-ui-designer    文件:ButtonGroupPropertiesPanel.java   
private void saveButtonGroupName() {
  String oldName = myGroup.getName();
  String newName = myNameTextField.getText();
  if (!oldName.equals(newName)) {
    myGroup.setName(newName);
    notifyListeners(new ChangeEvent(myGroup));
    if (myGroup.isBound()) {
      BindingProperty.updateBoundFieldName(myRootContainer, oldName, newName, ButtonGroup.class.getName());
    }
  }
}
项目:intellij-ce-playground    文件:BindingEditor.java   
private static String[] getFieldNames(final RadComponent component, final String currentName) {
  final ArrayList<String> result = new ArrayList<String>();
  if (currentName != null){
    result.add(currentName);
  }

  final IRootContainer root = FormEditingUtil.getRoot(component);
  final String className = root.getClassToBind();
  if (className == null) {
    return ArrayUtil.toStringArray(result);
  }

  final PsiClass aClass = FormEditingUtil.findClassToBind(component.getModule(), className);
  if (aClass == null) {
    return ArrayUtil.toStringArray(result);
  }

  final PsiField[] fields = aClass.getFields();

  for (final PsiField field : fields) {
    if (field.hasModifierProperty(PsiModifier.STATIC)) {
      continue;
    }

    final String fieldName = field.getName();

    if (Comparing.equal(currentName, fieldName)) {
      continue;
    }

    if (!FormEditingUtil.isBindingUnique(component, fieldName, root)) {
      continue;
    }

    final String componentClassName;
    if (component instanceof RadErrorComponent) {
      componentClassName = component.getComponentClassName();
    }
    else if (component instanceof RadHSpacer || component instanceof RadVSpacer) {
      componentClassName = Spacer.class.getName();
    }
    else {
      componentClassName = component.getComponentClass().getName();
    }

    final PsiType componentType;
    try {
      componentType =
        JavaPsiFacade.getInstance(component.getProject()).getElementFactory().createTypeFromText(componentClassName, null);
    }
    catch (IncorrectOperationException e) {
      continue;
    }

    final PsiType fieldType = field.getType();
    if (!fieldType.isAssignableFrom(componentType)) {
      continue;
    }

    result.add(fieldName);
  }

  String text = FormInspectionUtil.getText(component.getModule(), component);
  if (text != null) {
    String binding = BindingProperty.suggestBindingFromText(component, text);
    if (binding != null && !result.contains(binding)) {
      result.add(binding);        
    }
  }

  final String[] names = ArrayUtil.toStringArray(result);
  Arrays.sort(names);
  return names;
}
项目: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    文件:BindingEditor.java   
private static String[] getFieldNames(final RadComponent component, final String currentName) {
  final ArrayList<String> result = new ArrayList<String>();
  if (currentName != null){
    result.add(currentName);
  }

  final IRootContainer root = FormEditingUtil.getRoot(component);
  final String className = root.getClassToBind();
  if (className == null) {
    return ArrayUtil.toStringArray(result);
  }

  final PsiClass aClass = FormEditingUtil.findClassToBind(component.getModule(), className);
  if (aClass == null) {
    return ArrayUtil.toStringArray(result);
  }

  final PsiField[] fields = aClass.getFields();

  for (final PsiField field : fields) {
    if (field.hasModifierProperty(PsiModifier.STATIC)) {
      continue;
    }

    final String fieldName = field.getName();

    if (Comparing.equal(currentName, fieldName)) {
      continue;
    }

    if (!FormEditingUtil.isBindingUnique(component, fieldName, root)) {
      continue;
    }

    final String componentClassName;
    if (component instanceof RadErrorComponent) {
      componentClassName = component.getComponentClassName();
    }
    else if (component instanceof RadHSpacer || component instanceof RadVSpacer) {
      componentClassName = Spacer.class.getName();
    }
    else {
      componentClassName = component.getComponentClass().getName();
    }

    final PsiType componentType;
    try {
      componentType =
        JavaPsiFacade.getInstance(component.getProject()).getElementFactory().createTypeFromText(componentClassName, null);
    }
    catch (IncorrectOperationException e) {
      continue;
    }

    final PsiType fieldType = field.getType();
    if (!fieldType.isAssignableFrom(componentType)) {
      continue;
    }

    result.add(fieldName);
  }

  String text = FormInspectionUtil.getText(component.getModule(), component);
  if (text != null) {
    String binding = BindingProperty.suggestBindingFromText(component, text);
    if (binding != null && !result.contains(binding)) {
      result.add(binding);        
    }
  }

  final String[] names = ArrayUtil.toStringArray(result);
  Arrays.sort(names);
  return names;
}
项目: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;
}