コード例 #1
0
 protected String getEditText(DbObject dbParent, DbObject dbo) throws DbException {
   MetaField editableMetafield = getEditableMetaField(dbo);
   String editText = null;
   if (editableMetafield == null) editText = dbo.getName();
   else editText = (String) dbo.get(editableMetafield);
   return editText == null ? "" : editText;
 }
コード例 #2
0
  protected final void loadChildren(DynamicNode node) throws DbException {
    if (node.hasLoaded() || node.isLeaf()) return;
    node.setHasLoaded();
    Object userObject = node.getUserObject();
    if (userObject == ROOT) return;
    SrVector children = new SrVector(10);
    boolean isSorted = true;
    DbObject dbParent = null;
    if (userObject == DB_RAM) {
      Db[] dbs = Db.getDbs();
      for (int i = 0; i < dbs.length; i++) {
        if (dbs[i] instanceof DbRAM) insertProjects(children, dbs[i]);
      }
    } else if (userObject instanceof Db) {
      insertProjects(children, (Db) userObject);
    } else {
      dbParent = (DbObject) userObject;
      dbParent.getDb().beginTrans(Db.READ_TRANS);
      insertComponents(children, dbParent);
      isSorted = childrenAreSorted(dbParent);
      dbParent.getDb().commitTrans();
    }

    if (isSorted) {
      children.sort(getComparator(dbParent));
    }

    ArrayList groupNodeList = new ArrayList();
    DynamicNode groupNode = null;
    Enumeration enumeration = children.elements();
    while (enumeration.hasMoreElements()) {
      DynamicNode childNode = (DynamicNode) enumeration.nextElement();
      GroupParams group = childNode.getGroupParams();
      if (group.name == null) {
        node.add(childNode);
      } else {
        if (groupNode == null) {
          groupNode = createGroupNode(group);
          node.add(groupNode);
          groupNodeList.add(groupNode);
        } else if (!groupNode.toString().equals(group.name)) {
          boolean groupFound = false;
          for (int i = 0; i < groupNodeList.size(); i++) {
            groupNode = (DynamicNode) groupNodeList.get(i);
            if (groupNode.toString().equals(group.name)) {
              groupFound = true;
              break;
            }
          }
          if (!groupFound) {
            groupNode = createGroupNode(group);
            node.add(groupNode);
            groupNodeList.add(groupNode);
          }
        }
        groupNode.add(childNode);
      }
    }
    groupNodeList.clear();
  }
コード例 #3
0
ファイル: Schema.java プロジェクト: spycos/gigfork
  @Override
  public void accept(DbObjectVisitor visitor) {
    visitor.visit(this);

    for (DbObject child : objects) {
      child.accept(visitor);
    }
  }
コード例 #4
0
 private void insertProjects(SrVector children, Db db) throws DbException {
   db.beginTrans(Db.READ_TRANS);
   DbObject parent = db.getRoot();
   DbEnumeration dbEnum = parent.getComponents().elements(DbProject.metaClass);
   while (dbEnum.hasMoreElements())
     children.addElement(createPrimaryNode(parent, dbEnum.nextElement()));
   dbEnum.close();
   db.commitTrans();
 }
コード例 #5
0
  public boolean expand(Writer output, Serializable object, RuleOptions options)
      throws IOException, RuleException {
    boolean expanded = false;
    boolean prefixPrinted = false;
    boolean atLeastOneChildPrinted = false;

    if (object == null) {
      if (Debug.isDebug()) {
        throw new NullPointerException(); // disclose programming error
        // in debug..
      } else {
        return false;
      }
    } // end if

    if (!(object instanceof DbObject)) {
      return false;
    } // end if

    DbObject dbObject = (DbObject) object;
    MetaRelationship metaRelation = getMetaRelation(dbObject);
    MetaClass childrenMetaClass = getChildrenMetaClass();

    try {
      // get metaRelation from its string representation
      if (metaRelation == null)
        metaRelation = (MetaRelationship) getMetaField(dbObject, sConnector);

      boolean state[] = {prefixPrinted, atLeastOneChildPrinted};

      if (metaRelation instanceof MetaRelation1) {
        MetaRelation1 metaRelation1 = (MetaRelation1) metaRelation;
        expanded |=
            expandMetaRelation1(output, dbObject, metaRelation1, state, childrenMetaClass, options);
      } else if (metaRelation instanceof MetaRelationN) {
        expanded |=
            expandMetaRelationN(output, dbObject, metaRelation, state, childrenMetaClass, options);
      } else if (metaRelation instanceof MetaChoice) {
        MetaChoice choice = (MetaChoice) metaRelation;
        expanded |= expandMetaChoice(output, dbObject, choice, state, childrenMetaClass, options);
      } else {
        // TODO: throw 'meta-relationship not supported'
      }

      super.terminate(output, options);
    } catch (DbException ex) {
      String msg = ex.getMessage();
      throw new RuleException(msg);
    } catch (RuntimeException ex) {
      String conn = m_connector.getGUIName();
      String objectKind = dbObject.getMetaClass().getGUIName();
      String msg = InvalidConnectorRuleException.buildMessage(m_ruleName, conn, objectKind);
      throw new InvalidConnectorRuleException(msg);
    }

    return expanded;
  }
コード例 #6
0
 protected final void updateInsertIndexInChildrenOfNode(DynamicNode parentNode)
     throws DbException {
   Enumeration childrenEnum = parentNode.children();
   while (childrenEnum.hasMoreElements()) {
     DynamicNode node = (DynamicNode) childrenEnum.nextElement();
     DbObject dbo = (DbObject) node.getRealObject();
     DbObject dbParent = dbo.getComposite();
     node.insertIndex = getSequence(dbParent, dbo);
   }
 }
コード例 #7
0
ファイル: Schema.java プロジェクト: spycos/gigfork
 @Override
 public boolean sameAs(DbObject other) {
   if (other == null || (!other.getClass().equals(getClass()))) {
     return false;
   }
   return true;
 }
コード例 #8
0
  public final DynamicNode getDynamicNode(DbObject dbo, int which, boolean load)
      throws DbException {
    SrVector path = new SrVector(10);
    Db db = dbo.getDb();
    db.beginTrans(Db.READ_TRANS);
    while (dbo != null && !(dbo instanceof DbRoot)) {
      path.addElement(dbo);
      dbo = getDbParent(dbo, which);
    }
    if (db instanceof DbRAM) {
      if (DB_RAM != ((DynamicNode) getRoot()).getUserObject()) path.addElement(DB_RAM);
    } else path.addElement(db);

    DynamicNode nodeFound = (DynamicNode) getRoot();
    for (int i = path.size(); --i >= 0; ) {
      if (load) loadChildren(nodeFound);
      Object userObj = path.elementAt(i);
      dbo = null;
      DbObject dbParent = null;
      GroupParams group = GroupParams.defaultGroupParams;
      DynamicNode groupNode = null;
      DynamicNode node = null;
      if (userObj instanceof DbObject) {
        dbo = (DbObject) userObj;
        dbParent = getDbParent(dbo, which);
        group = getGroupParams(dbParent, dbo);
      }
      if (group.name == null) {
        node = getDynamicNode(nodeFound, userObj, 0);
      } else {
        groupNode = getGroupNode(nodeFound, group, 0);
        if (groupNode != null) node = getDynamicNode(groupNode, userObj, 0);
      }
      if (node == null && nodeFound.hasLoaded() && !nodeFound.isLeaf() && which == Db.NEW_VALUE) {

        SemanticalModel model = ApplicationContext.getSemanticalModel();
        boolean visible = model.isVisibleOnScreen(dbParent, dbo, Explorer.class);

        if (visible) {
          node = createPrimaryNode(dbParent, dbo);
          if (group.name == null) {
            insertNodeInto(node, nodeFound, getInsertionIndex(dbParent, dbo, nodeFound, node));
          } else {
            if (groupNode == null) {
              groupNode = createGroupNode(group);
              insertNodeInto(groupNode, nodeFound, getSortedIndex(nodeFound, groupNode));
            }
            insertNodeInto(node, groupNode, getInsertionIndex(dbParent, dbo, groupNode, node));
          }
        }
      }
      nodeFound = node;
      if (nodeFound == null) break;
    }
    db.commitTrans();
    return nodeFound;
  }
コード例 #9
0
  private boolean expandMetaChoice(
      Writer output,
      DbObject object,
      MetaChoice choice,
      boolean state[],
      MetaClass childrenMetaClass,
      RuleOptions options)
      throws DbException, IOException, RuleException {

    boolean expanded = false;
    Object child = object.get(choice);

    if (child instanceof DbObject) {
      DbObject dbChild = (DbObject) child;
      MetaClass metaClass = dbChild.getMetaClass();
      String className = metaClass.getGUIName();
      boolean excluded = false;

      // check if child's class is excluded
      if (options != null) {
        excluded = options.isExcluded(className);

        // if not, check if parent's connection is excluded
        if (!excluded) {
          MetaClass metaClass2 = object.getMetaClass();
          String parentClassName = metaClass2.getGUIName();
          String connectionName = parentClassName + "." + choice.getGUIName();
          excluded = options.isExcluded(connectionName);
        } // end if
      } // end if

      if (!excluded) {
        if (childrenMetaClass.isAssignableFrom(metaClass)) {
          expanded |= expandChild(output, object, dbChild, 1, state, options);
        } // end if
      } // end if
    } // end if

    if ((!expanded) && (nullModifier != null)) {
      expanded |= nullModifier.expand(output, object, options);
    } // end if

    return expanded;
  } // end expandMetaChoice
コード例 #10
0
  protected final void doActionPerformed(ActionEvent evt) {
    try {
      ApplicationDiagram diag =
          (ApplicationDiagram) (ApplicationContext.getFocusManager().getFocusObject());
      Point clickPosition = getDiagramLocation(evt);
      if (clickPosition == null)
        clickPosition = GraphicUtil.rectangleGetCenter(diag.getMainView().getViewRect());
      java.awt.Image image = SRSystemClipboard.getClipboardImage();
      if (image == null) return;
      DbObject diagGo = diag.getDiagramGO();
      Db db = diagGo.getDb();

      ImageIcon icon = new ImageIcon(image);
      int imageHeigth = icon.getIconHeight();
      int imageWidth = icon.getIconWidth();

      db.beginTrans(Db.WRITE_TRANS, LocaleMgr.action.getString("pasteDiagramImage"));

      DbObject imageGo = diagGo.createComponent(DbGraphic.fImageGoDiagramImage.getMetaClass());
      imageGo.set(DbGraphic.fImageGoDiagramImage, image);
      imageGo.set(
          DbGraphic.fGraphicalObjectRectangle,
          new Rectangle(
              clickPosition.x - (imageWidth / 2),
              clickPosition.y - (imageHeigth / 2),
              imageWidth,
              imageHeigth));
      db.commitTrans();
    } catch (Exception e) {
      org.modelsphere.jack.util.ExceptionHandler.processUncatchedException(
          ApplicationContext.getDefaultMainFrame(), e);
    }
  }
コード例 #11
0
  // Overridden
  protected void insertComponents(SrVector children, DbObject dbParent) throws DbException {
    SemanticalModel model = ApplicationContext.getSemanticalModel();

    DbEnumeration dbEnum = dbParent.getComponents().elements();
    while (dbEnum.hasMoreElements()) {
      DbObject dbo = dbEnum.nextElement();
      boolean isVisible = model.isVisibleOnScreen(dbParent, dbo, Explorer.class);
      if (isVisible) {
        children.addElement(createPrimaryNode(dbParent, dbo));
      } // end if
    } // end while
    dbEnum.close();
  } // end insertComponents()
コード例 #12
0
 // Called at the end of a cell edition, to process the edition result.
 public final void valueForPathChanged(TreePath path, Object newValue) {
   DynamicNode node = (DynamicNode) path.getLastPathComponent();
   Object obj = node.getRealObject();
   if (obj instanceof DbObject) {
     boolean editable = false;
     try {
       Db db = ((DbObject) obj).getDb();
       if (db.isValid()) {
         db.beginReadTrans();
         MetaField editableMetaField = getEditableMetaField((DbObject) obj);
         if (editableMetaField == null)
           editable =
               ApplicationContext.getSemanticalModel()
                   .isNameEditable((DbObject) obj, Explorer.class);
         else
           editable =
               ApplicationContext.getSemanticalModel()
                   .isEditable(editableMetaField, (DbObject) obj, Explorer.class);
         db.commitTrans();
       }
     } catch (DbException ex) {
       org.modelsphere.jack.util.ExceptionHandler.processUncatchedException(
           ApplicationContext.getDefaultMainFrame(), ex);
       editable = false;
     }
     if (!editable) return;
   } else {
     return;
   }
   DbObject semObj = (DbObject) obj;
   try {
     MetaField editableMetaField = getEditableMetaField(semObj);
     String transName =
         (editableMetaField == null
             ? LocaleMgr.action.getString("rename")
             : MessageFormat.format(kUpdate0, new Object[] {editableMetaField.getGUIName()}));
     semObj.getDb().beginTrans(Db.WRITE_TRANS, transName);
     if (editableMetaField == null) {
       if (semObj.getTransStatus() == Db.OBJ_REMOVED) return;
       semObj.setName((String) newValue);
     } else semObj.set(editableMetaField, (String) newValue);
     semObj.getDb().commitTrans();
     nodeChanged(node); // in case it is a secondary node (only the
     // primary node is updated by the refresh
     // listener).
   } catch (Exception ex) {
     org.modelsphere.jack.util.ExceptionHandler.processUncatchedException(
         ApplicationContext.getDefaultMainFrame(), ex);
   }
 }
コード例 #13
0
  // add childrenMetaClass to filter only children of that class
  // if null, scan each child
  protected boolean expandMetaRelationN(
      Writer output,
      DbObject object,
      MetaRelationship metaRelation,
      boolean state[],
      MetaClass childrenMetaClass,
      RuleOptions options)
      throws DbException, IOException, RuleException {

    boolean expanded = false;
    DbEnumeration dbEnumChildren = null;
    DbRelationN relationN = (DbRelationN) object.get(metaRelation);
    if (childrenMetaClass == null) {
      dbEnumChildren = relationN.elements();
    } else {
      dbEnumChildren = relationN.elements(childrenMetaClass);
    }

    // a first pass to find out the number of children
    int nbChildren = 0;
    try {
      while (dbEnumChildren.hasMoreElements()) {
        dbEnumChildren.nextElement();
        nbChildren++;

        // Cancel everything if the user has decided to stop the
        // operation
        if (options != null) {
          Controller controller = options.m_controller;
          if (controller != null) {
            boolean can_continue = controller.checkPoint();
            if (!can_continue) {
              throw new RuleException(controller.getAbortedString());
            }
          }
        } // end if
      } // end while
    } finally {
      dbEnumChildren.close();
    }

    // cannot rollback to the first element, so recreate the enumeration
    if (childrenMetaClass == null) {
      dbEnumChildren = relationN.elements();
    } else {
      dbEnumChildren = relationN.elements(childrenMetaClass);
    }

    try {
      while (dbEnumChildren.hasMoreElements()) {
        DbObject child = (DbObject) dbEnumChildren.nextElement();
        MetaClass metaClass = child.getMetaClass();
        String className = metaClass.getGUIName();
        boolean excluded = false;

        // check if child's class is excluded
        if (options != null) {
          excluded = options.isExcluded(className);

          // if not, check if parent's connection is excluded
          if (!excluded) {
            metaClass = object.getMetaClass();
            String parentClassName = metaClass.getGUIName();
            String connectionName = parentClassName + "." + metaRelation.getGUIName();
            excluded = options.isExcluded(connectionName);
          } // end if
        } // end if

        if (!excluded) {
          expanded |= expandChild(output, object, child, nbChildren, state, options);
        } // end if
      } // end while
    } finally {
      dbEnumChildren.close();
    }

    boolean atLeastOneChildPrinted = state[1];

    if ((atLeastOneChildPrinted) && (suffixModifier != null)) {
      expanded |= suffixModifier.expand(output, object, options);
    } else if ((!atLeastOneChildPrinted) && (nullModifier != null)) {
      expanded |= nullModifier.expand(output, object, options);
    }

    return expanded;
  } // end expandMetaRelationN
コード例 #14
0
 // Must return the index in the children list if childrenAreSorted(dbParent)
 // returns false.
 // Overridden
 protected int getIndex(DbObject dbParent, DbObject dbo) throws DbException {
   return dbParent.getComponents().indexOf(dbo);
 }
コード例 #15
0
ファイル: DbSpec.java プロジェクト: jahlborn/sqlbuilder
 /**
  * @param name name of the schema to find
  * @return the schema previously added to this spec with the given name, or {@code null} if none.
  */
 public DbSchema findSchema(String name) {
   return DbObject.findObject(_schemas, name);
 }
コード例 #16
0
 protected Icon getIcon(DbObject dbo) throws DbException {
   return dbo.getSemanticalIcon(DbObject.SHORT_FORM);
 }
コード例 #17
0
ファイル: Schema.java プロジェクト: spycos/gigfork
 /**
  * Add an object to this schema - this method will set this schema as the object's parent.
  *
  * @param dbObject
  */
 public void add(DbObject dbObject) {
   dbObject.setParent(this);
   objects.add(dbObject);
 }
コード例 #18
0
 // Overridden
 protected DbObject getDbParent(DbObject dbo, int which) throws DbException {
   return (DbObject) dbo.get(DbObject.fComposite, which);
 }
コード例 #19
0
  private boolean expandMetaRelation1(
      Writer output,
      DbObject object,
      MetaRelation1 metaRelation1,
      boolean state[],
      MetaClass childrenMetaClass,
      RuleOptions options)
      throws DbException, IOException, RuleException {

    boolean expanded = false;
    Object child;
    if (childrenMetaClass != null) {
      if (metaRelation1 == DbObject.fComposite) {
        child = object.getCompositeOfType(childrenMetaClass);
      } else {
        child = object.get(metaRelation1);
        if (child instanceof DbObject) {
          DbObject dbChild = (DbObject) child;
          MetaClass mc = dbChild.getMetaClass();
          if (mc != childrenMetaClass) {
            child = null;
          }
        }
      }
    } else {
      child = object.get(metaRelation1);
    } // end if

    if (child != null) {
      if (child instanceof DbObject) {
        DbObject dbChild = (DbObject) child;
        MetaClass metaClass = dbChild.getMetaClass();
        String className = metaClass.getGUIName();
        boolean excluded = false;

        // check if child's class is excluded
        if (options != null) {
          excluded = options.isExcluded(className);

          // if not, check if parent's connection is excluded
          if (!excluded) {
            metaClass = object.getMetaClass();
            String parentClassName = metaClass.getGUIName();
            String connectionName = parentClassName + "." + metaRelation1.getGUIName();
            excluded = options.isExcluded(connectionName);
          } // end if
        } // end if

        if (!excluded) {
          expanded |= expandChild(output, object, dbChild, 1, state, options);
        } // end if
      } // end if
    } // end if

    // if a SUF modifier has to be expanded
    if ((expanded) && (suffixModifier != null)) {
      suffixModifier.expand(output, object, options);
    }

    // if a NULL modifier has to be expanded
    if ((!expanded) && (nullModifier != null)) {
      expanded |= nullModifier.expand(output, object, options);
    }

    return expanded;
  } // end expandMetaRelation1