Exemplo n.º 1
0
 /**
  * Restore opened settings node if still there.
  *
  * @param oldProps properties inserted in the old model
  * @param selPath path to the node selected in the old model
  */
 private void restoreInsertedProperties(HashMap<String, Property[]> oldProps, TreePath selPath) {
   DefaultTreeModel newModel = levelTrees.get(permissionLvl);
   // Create properties panel for every properties panel existing in the old model
   updateUsedPanels(oldProps, newModel);
   final JPanel holderPropertiesPanel = (JPanel) splitPane.getRightComponent();
   holderPropertiesPanel.removeAll();
   if (selPath != null) {
     // returns node from previous model
     DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) selPath.getLastPathComponent();
     if (selectedNode.getUserObject() instanceof ClassPropertiesInfo) {
       // find selected class by name
       ClassPropertiesInfo selectedClassInfo = (ClassPropertiesInfo) selectedNode.getUserObject();
       String selectedClassInfoName = selectedClassInfo.getName();
       // see if it's still visible
       DefaultMutableTreeNode classNode;
       ClassPropertiesInfo classInfo;
       DefaultMutableTreeNode root = (DefaultMutableTreeNode) newModel.getRoot();
       int classCount = newModel.getChildCount(root);
       for (int c = 0; c < classCount; c++) {
         classNode = (DefaultMutableTreeNode) newModel.getChild(root, c);
         classInfo = (ClassPropertiesInfo) classNode.getUserObject();
         if (classInfo.getName().equalsIgnoreCase(selectedClassInfoName)) {
           tree.setSelectionPath(new TreePath(classNode.getPath()));
           c = classCount;
         }
       }
     }
   }
   holderPropertiesPanel.repaint();
 }
Exemplo n.º 2
0
 /**
  * Set all properties panels to null to mark for refresh.
  *
  * @param level for which the model will be reset
  */
 private void resetPropertiesPanels(LEVEL level) {
   TreeModel model = levelTrees.get(level);
   int functionalityCount = model.getChildCount(model.getRoot());
   ClassPropertiesInfo funcInfo;
   DefaultMutableTreeNode node;
   for (int i = 0; i < functionalityCount; i++) {
     node = (DefaultMutableTreeNode) model.getChild(model.getRoot(), i);
     funcInfo = (ClassPropertiesInfo) node.getUserObject();
     funcInfo.setPropertiesPanel(null);
   }
 }
Exemplo n.º 3
0
 private void setProperties(ClassPropertiesInfo classInfo) {
   DefaultProperty[] beforeProps;
   PropertiesProvider provider;
   String[] errors;
   beforeProps = convertPropertyType(classInfo.getPropertiesPanel().getProperties());
   provider = classInfo.getClassInstance();
   errors = provider.getPropertiesErrors(beforeProps);
   if (errors != null && errors.length > 0) {
     printErrors(errors);
   } else {
     provider.setProperties(beforeProps);
   }
 }
Exemplo n.º 4
0
 /**
  * Cycle through the nodes in the new model.<br>
  * For each node in the old model that also had a panel, create (for the new permission level) and
  * transfer all the properties in the old one that are still present. <br>
  * As panel is only created if is visualized, this guarantees that all previously modified
  * properties keep modifications.
  *
  * @param oldProps properties inserted in the old model
  * @param newModel set the old properties in the new model
  */
 private void updateUsedPanels(HashMap<String, Property[]> oldProps, DefaultTreeModel newModel) {
   DefaultMutableTreeNode root = (DefaultMutableTreeNode) newModel.getRoot();
   int childCount = newModel.getChildCount(root);
   DefaultMutableTreeNode node;
   ClassPropertiesInfo funcInfo;
   Property[] storedProps;
   for (int i = 0; i < childCount; i++) {
     node = (DefaultMutableTreeNode) newModel.getChild(root, i);
     funcInfo = (ClassPropertiesInfo) node.getUserObject();
     storedProps = oldProps.get(funcInfo.getName());
     // If this functionality was viewed it might contain changes
     if (storedProps != null) {
       // Create panel for it
       PropertySheetPanel propertyPanel =
           createPropertiesPanelForClass(funcInfo.getClassInstance());
       Property newProps[] = propertyPanel.getProperties();
       // go through properties
       int newPropsLength = newProps.length;
       int storedPropsLength = storedProps.length;
       // find who has more properties
       if (newPropsLength < storedPropsLength) {
         // lowering the permission
         int pStored = 0;
         int pNew = 0;
         while (pNew < newPropsLength && pStored < storedPropsLength) {
           if (storedProps[pStored].getName().equals(newProps[pNew].getName())) {
             newProps[pNew].setValue(storedProps[pStored].getValue());
             pNew++;
           }
           pStored++;
         }
       } else {
         // going to higher permission
         int pStored = 0;
         int pNew = 0;
         while (pNew < newPropsLength && pStored < storedPropsLength) {
           if (storedProps[pStored].getName().equals(newProps[pNew].getName())) {
             newProps[pNew].setValue(storedProps[pStored].getValue());
             pStored++;
           }
           pNew++;
         }
       }
       // set the updated properties panel
       funcInfo.setPropertiesPanel(propertyPanel);
     }
   }
 }
Exemplo n.º 5
0
 public void saveChanges() {
   TreeModel model = tree.getModel();
   Object root = model.getRoot();
   ClassPropertiesInfo classInfo;
   int classCount = model.getChildCount(root);
   for (int c = 0; c < classCount; c++) {
     classInfo =
         (ClassPropertiesInfo) ((DefaultMutableTreeNode) model.getChild(root, c)).getUserObject();
     PropertySheetPanel propertiesPanel = classInfo.getPropertiesPanel();
     if (propertiesPanel != null) {
       // to exit edit mode and retrieve the value
       propertiesPanel.getTable().commitEditing();
       setProperties(classInfo);
     }
   }
   GeneralPreferences.saveProperties();
 }
Exemplo n.º 6
0
 private HashMap<String, Property[]> extractProperties(TreeModel model) {
   HashMap<String, Property[]> props = new HashMap<>();
   DefaultMutableTreeNode classNode;
   Object root = model.getRoot();
   ClassPropertiesInfo classInfo;
   int classCount = model.getChildCount(root);
   Property[] classProperties;
   for (int c = 0; c < classCount; c++) {
     classNode = (DefaultMutableTreeNode) model.getChild(root, c);
     classInfo = (ClassPropertiesInfo) classNode.getUserObject();
     PropertySheetPanel propertiesPanel = classInfo.getPropertiesPanel();
     if (propertiesPanel != null) {
       // force out of edit mode
       propertiesPanel.getTable().commitEditing();
       classProperties = propertiesPanel.getProperties();
       props.put(classInfo.getName(), classProperties.clone());
     }
   }
   return props;
 }