private void checkForEmptyAndDuplicatedNames(
      MyNode rootNode,
      String prefix,
      String title,
      Class<? extends NamedConfigurable> configurableClass,
      boolean recursively)
      throws ConfigurationException {
    final Set<String> names = new HashSet<String>();
    for (int i = 0; i < rootNode.getChildCount(); i++) {
      final MyNode node = (MyNode) rootNode.getChildAt(i);
      final NamedConfigurable scopeConfigurable = node.getConfigurable();

      if (configurableClass.isInstance(scopeConfigurable)) {
        final String name = scopeConfigurable.getDisplayName();
        if (name.trim().length() == 0) {
          selectNodeInTree(node);
          throw new ConfigurationException("Name should contain non-space characters");
        }
        if (names.contains(name)) {
          final NamedConfigurable selectedConfigurable = getSelectedConfigurable();
          if (selectedConfigurable == null
              || !Comparing.strEqual(selectedConfigurable.getDisplayName(), name)) {
            selectNodeInTree(node);
          }
          throw new ConfigurationException(
              CommonBundle.message("smth.already.exist.error.message", prefix, name), title);
        }
        names.add(name);
      }

      if (recursively) {
        checkForEmptyAndDuplicatedNames(node, prefix, title, configurableClass, true);
      }
    }
  }
示例#2
0
 @Nullable
 public <T> T findChildByClass(Class<T> aClass) {
   for (PsiElement child : getChildren()) {
     if (aClass.isInstance(child)) return (T) child;
   }
   return null;
 }
示例#3
0
  /**
   * Set the object to be edited.
   *
   * @param value The object to be edited.
   */
  public void setObject(Object value) {
    if (!(_type.isInstance(value))) {
      throw new IllegalArgumentException(value.getClass() + " is not of type " + _type);
    }
    _value = value;

    // Disable event generation.
    _squelchChangeEvents = true;

    // Iterate over each property, doing a lookup on the associated editor
    // and setting the editor's value to the value of the property.
    Iterator it = _prop2Editor.keySet().iterator();
    while (it.hasNext()) {
      PropertyDescriptor desc = (PropertyDescriptor) it.next();
      PropertyEditor editor = (PropertyEditor) _prop2Editor.get(desc);
      Method reader = desc.getReadMethod();
      if (reader != null) {
        try {
          Object val = reader.invoke(_value, null);
          editor.setValue(val);
        } catch (IllegalAccessException ex) {
          ex.printStackTrace();
        } catch (InvocationTargetException ex) {
          ex.getTargetException().printStackTrace();
        }
      }
    }

    // Enable event generation.
    _squelchChangeEvents = false;
  }
示例#4
0
 // todo eliminate code duplication in BaseLogicalViewProjectPane
 private <T extends TreeNode> T getSelectedTreeNode(Class<T> nodeClass) {
   TreePath selectionPath = getTree().getSelectionPath();
   if (selectionPath == null) return null;
   Object selectedNode = selectionPath.getLastPathComponent();
   if (!(nodeClass.isInstance(selectedNode))) return null;
   return (T) selectedNode;
 }
示例#5
0
  @SuppressWarnings("unchecked")
  @Nullable
  public static <T> T getToolWindowElement(
      @NotNull Class<T> clazz,
      @NotNull Project project,
      @NotNull DataKey<T> key,
      @NotNull ProjectSystemId externalSystemId) {
    if (project.isDisposed() || !project.isOpen()) {
      return null;
    }
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    if (toolWindowManager == null) {
      return null;
    }
    final ToolWindow toolWindow = ensureToolWindowContentInitialized(project, externalSystemId);
    if (toolWindow == null) {
      return null;
    }

    final ContentManager contentManager = toolWindow.getContentManager();
    if (contentManager == null) {
      return null;
    }

    for (Content content : contentManager.getContents()) {
      final JComponent component = content.getComponent();
      if (component instanceof DataProvider) {
        final Object data = ((DataProvider) component).getData(key.getName());
        if (data != null && clazz.isInstance(data)) {
          return (T) data;
        }
      }
    }
    return null;
  }
示例#6
0
 @NotNull
 public <T> T[] findChildrenByClass(Class<T> aClass) {
   List<T> result = new ArrayList<T>();
   for (PsiElement child : getChildren()) {
     if (aClass.isInstance(child)) result.add((T) child);
   }
   return result.toArray((T[]) Array.newInstance(aClass, result.size()));
 }
 private static boolean shouldIgnoreAction(@NotNull AnAction action) {
   for (Class<?> actionType : IGNORED_CONSOLE_ACTION_TYPES) {
     if (actionType.isInstance(action)) {
       return true;
     }
   }
   return false;
 }
示例#8
0
 private boolean isValidType(final Class<?>[] validTypes, final Object type) {
   for (final Class<?> t : validTypes) {
     if (t.isInstance(type)) {
       return true;
     }
   }
   return false;
 }
 private Set<Object> doFilter(Set<Object> elements) {
   Set<Object> result = new LinkedHashSet<Object>();
   for (Object o : elements) {
     if (myElementClass.isInstance(o) && getFilter().isAccepted((T) o)) {
       result.add(o);
     }
   }
   return result;
 }
示例#10
0
  private List<String> collectModuleDepsNames(String moduleName, Class clazz) {
    List<String> actual = new ArrayList<String>();

    for (OrderEntry e : getRootManager(moduleName).getOrderEntries()) {
      if (clazz.isInstance(e)) {
        actual.add(e.getPresentableName());
      }
    }
    return actual;
  }
示例#11
0
 public static PsiElement findParentOfType(PsiElement element, Class className) {
   if (className.isInstance(element)) {
     return element;
   } else {
     try {
       return findParentOfType(element.getParent(), className);
     } catch (Exception e) {
       return null;
     }
   }
 }
 public <T> T getUserData(final Class<T> userDataClass) {
   if (myUserData != null) {
     for (Object o : myUserData) {
       if (userDataClass.isInstance(o)) {
         //noinspection unchecked
         return (T) o;
       }
     }
   }
   return null;
 }
  public static Component findFirstComponentOfType(Component component, Class nowClass) {
    if (nowClass.isInstance(component)) return component;

    if (component instanceof Container) {
      Container container = (Container) component;
      for (int i = 0; i < container.getComponentCount(); i++) {
        Component firstComponent = findFirstComponentOfType(container.getComponent(i), nowClass);
        if (firstComponent != null) return firstComponent;
      }
    }
    return null;
  }
 @Nullable
 public InnerSearchableConfigurable findSubConfigurable(@NotNull final Class pageClass) {
   if (mySubPanelFactories == null) {
     buildConfigurables();
   }
   for (Map.Entry<ColorAndFontPanelFactory, InnerSearchableConfigurable> entry :
       mySubPanelFactories.entrySet()) {
     if (pageClass.isInstance(entry.getValue().createPanel().getSettingsPage())) {
       return entry.getValue();
     }
   }
   return null;
 }
示例#15
0
  /**
   * Convenience method for searching above the given component in the component hierarchy and
   * returns the first object of the given type it finds, or <code>null</code> if no such parent was
   * found.
   *
   * <p>The reason this method exists is for tidyness of the calling code, as no longer a explicit
   * cast is needed.
   *
   * @param aType the type of the parent to find, cannot be <code>null</code>;
   * @param aComponent the component to search in the hierarchy, cannot be <code>null</code>.
   * @return the requested ancestor, or <code>null</code> if not found.
   * @see SwingUtilities#getAncestorOfClass(Class, Component)
   */
  @SuppressWarnings("unchecked")
  public static <T> T getAncestorOfClass(final Class<T> aType, final Component aComponent) {
    if ((aComponent == null) || (aType == null)) {
      return null;
    }

    Container parent = aComponent.getParent();
    while ((parent != null) && !(aType.isInstance(parent))) {
      parent = parent.getParent();
    }

    return (T) parent;
  }
示例#16
0
 private static boolean isWindows(LookAndFeel laf) {
   if (laf.getID() == "Windows") {
     return true;
   }
   if (!checkedForWindows) {
     try {
       WINDOWS_CLASS = Class.forName("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
     } catch (ClassNotFoundException e) {
     }
     checkedForWindows = true;
   }
   return (WINDOWS_CLASS != null && WINDOWS_CLASS.isInstance(laf));
 }
  public <T extends TreeNode> List<T> getSelectedTreeNodes(Class<T> nodeClass) {
    TreePath[] selectionPaths = getTree().getSelectionPaths();
    if (selectionPaths == null) return new ArrayList<T>();

    List<T> selectedTreeNodes = new ArrayList<T>(selectionPaths.length);

    for (TreePath selectionPath : selectionPaths) {
      if (selectionPath == null) continue;
      Object selectedNode = selectionPath.getLastPathComponent();
      if (!(nodeClass.isInstance(selectedNode))) continue;
      selectedTreeNodes.add((T) selectedNode);
    }
    return selectedTreeNodes;
  }
示例#18
0
  private <T> T getModuleDep(String moduleName, String depName, Class<T> clazz) {
    T dep = null;

    for (OrderEntry e : getRootManager(moduleName).getOrderEntries()) {
      if (clazz.isInstance(e) && e.getPresentableName().equals(depName)) {
        dep = (T) e;
      }
    }
    assertNotNull(
        "Dependency not found: "
            + depName
            + "\namong: "
            + collectModuleDepsNames(moduleName, clazz),
        dep);
    return dep;
  }
示例#19
0
文件: TreeUtil.java 项目: jexp/idea2
 @NotNull
 public static <T> List<T> collectSelectedObjectsOfType(JTree tree, Class<T> clazz) {
   final TreePath[] selections = tree.getSelectionPaths();
   if (selections != null) {
     final ArrayList<T> result = new ArrayList<T>();
     for (TreePath selection : selections) {
       final DefaultMutableTreeNode node =
           (DefaultMutableTreeNode) selection.getLastPathComponent();
       final Object userObject = node.getUserObject();
       if (clazz.isInstance(userObject)) {
         //noinspection unchecked
         result.add((T) userObject);
       }
     }
     return result;
   }
   return Collections.emptyList();
 }
示例#20
0
 private static boolean isXP() {
   if (!checkedForClassic) {
     try {
       CLASSIC_WINDOWS =
           Class.forName("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
     } catch (ClassNotFoundException e) {
     }
     checkedForClassic = true;
   }
   if (CLASSIC_WINDOWS != null && CLASSIC_WINDOWS.isInstance(UIManager.getLookAndFeel())) {
     return false;
   }
   Toolkit toolkit = Toolkit.getDefaultToolkit();
   Boolean themeActive = (Boolean) toolkit.getDesktopProperty("win.xpstyle.themeActive");
   if (themeActive == null) {
     themeActive = Boolean.FALSE;
   }
   return themeActive.booleanValue();
 }
 @Nullable
 public static <T> T cast(@NotNull Class<T> type, UnnamedConfigurable configurable) {
   if (configurable instanceof ConfigurableWrapper) {
     ConfigurableWrapper wrapper = (ConfigurableWrapper) configurable;
     if (wrapper.myConfigurable == null) {
       Class<?> configurableType = wrapper.getExtensionPoint().getConfigurableType();
       if (configurableType != null) {
         if (!type.isAssignableFrom(configurableType)) {
           return null; // do not create configurable that cannot be cast to the specified type
         }
       } else if (type == Configurable.Assistant.class || type == OptionalConfigurable.class) {
         return null; // do not create configurable from ConfigurableProvider which replaces
                      // OptionalConfigurable
       }
     }
     configurable = wrapper.getConfigurable();
   }
   return type.isInstance(configurable) ? type.cast(configurable) : null;
 }