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);
    }
  }
  public void updateUI() {

    try {
      super.updateUI();
    } catch (Exception ex) {

      ApplicationContext.getDefaultMainFrame().getToolBarPanel().removeAll();
      ApplicationContext.getDefaultMainFrame().installToolBars();
    }
  }
 /*
  * retourne le nom à afficher
  */
 private String getDisplayName(DbObject dbo) throws DbException {
   String dboDisplayName = null;
   if (dbo.getName() != null) {
     if (dbo.getName().length() != 0) dboDisplayName = dbo.getName();
     else {
       dboDisplayName =
           ApplicationContext.getSemanticalModel().getDisplayText(dbo, Explorer.class);
     }
   } else {
     dboDisplayName = ApplicationContext.getSemanticalModel().getDisplayText(dbo, Explorer.class);
   }
   return dboDisplayName;
 } // end getDisplayName
 // 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);
   }
 }
  // this update is always safe
  public final void updateSelectionAction() throws DbException {
    ApplicationDiagram diag = ApplicationContext.getFocusManager().getActiveDiagram();
    Object[] objects = ApplicationContext.getFocusManager().getSelectedSemanticalObjects();
    if ((diag == null) || (objects.length != 1) || !(objects[0] instanceof DbORAssociationEnd)) {
      setSelectedIndex(-1);
      setEnabled(false);
      return;
    }

    // update values
    dbos.clear();

    DbORAssociationEnd end = (DbORAssociationEnd) objects[0];
    DbORPrimaryUnique selKey = end.getReferencedConstraint();

    DbORAbsTable tableSo = (DbORAbsTable) end.getOppositeEnd().getClassifier();
    DbEnumeration dbEnum = tableSo.getComponents().elements(DbORPrimaryUnique.metaClass);
    while (dbEnum.hasMoreElements()) {
      DbORPrimaryUnique key = (DbORPrimaryUnique) dbEnum.nextElement();
      dbos.add(key);
    }
    dbEnum.close();

    int sizeadjustment = (dbos.size() == 0) ? 1 : 2; // adding a separator
    // and an item for
    // removing the
    // referenced
    // constraint
    // if no keys, do not add a separator
    Object[] items = new Object[dbos.size() + sizeadjustment];

    items[0] = kNoReferencedConstraint;
    if (sizeadjustment == 2) {
      items[1] = null;
    }

    String tableName = tableSo.getName();
    for (int i = 0; i < dbos.size(); i++) {
      String name = ((DbORPrimaryUnique) dbos.get(i)).getName();
      items[i + sizeadjustment] =
          MessageFormat.format(kKeyNamePatern, new Object[] {tableName, name});
    }
    setDomainValues(items);

    if (selKey == null) setSelectedIndex(0);
    else setSelectedIndex(dbos.indexOf(selKey) + sizeadjustment);

    setEnabled(true);
  }
 public void propertyChange(PropertyChangeEvent evt) {
   try {
     Explorer.this.refresh();
   } catch (Exception e) {
     ExceptionHandler.processUncatchedException(ApplicationContext.getDefaultMainFrame(), e);
   }
 }
 // This method updates the explorer for changes in a relation N where all
 // children are secondary nodes.
 // IMPORTANT: a node whose children are secondary nodes cannot have grouping
 // nodes.
 protected final void updateSecondaryChildren(DbUpdateEvent evt) throws DbException {
   if (!ApplicationContext.getSemanticalModel()
       .isVisibleOnScreen(evt.dbo, evt.neighbor, Explorer.class)) return;
   DynamicNode parentNode = getDynamicNode(evt.dbo, false);
   if (parentNode == null || !parentNode.hasLoaded()) return;
   DynamicNode childNode = null;
   int nb = getChildCount(parentNode);
   for (int i = 0; i < nb; i++) {
     DynamicNode node = (DynamicNode) getChild(parentNode, i);
     if (((DynamicNode) node.getUserObject()).getUserObject() == evt.neighbor) {
       childNode = node;
       break;
     }
   }
   if (evt.op == Db.REMOVE_FROM_RELN) {
     if (childNode != null) removeNodeFromParent(childNode);
   } else if (evt.op == Db.ADD_TO_RELN) {
     if (childNode == null) {
       childNode = createSecondaryNode(evt.dbo, evt.neighbor);
       int index = getInsertionIndex(evt.dbo, evt.neighbor, parentNode, childNode);
       insertNodeInto(childNode, parentNode, index);
     }
   } else { // Db.REINSERT_IN_RELN
     if (!childrenAreSorted(evt.dbo) && childNode != null) {
       removeNodeFromParent(childNode);
       int index = getInsertionIndex(evt.dbo, evt.neighbor, parentNode, childNode);
       insertNodeInto(childNode, parentNode, index);
     }
   }
 }
 public void dbTerminated(Db db) {
   try {
     Explorer.this.refresh();
   } catch (Exception e) {
     ExceptionHandler.processUncatchedException(ApplicationContext.getDefaultMainFrame(), e);
   }
 }
 /**
  * If CS application, create a root node with 2 subnodes: RAM and repository; the RAM subnode
  * contains the list of RAM projects as subnodes. If RAM application, create a root node with the
  * list of projects as subnodes.
  */
 private DynamicNode createRootNode() {
   DynamicNode rootNode = null;
   DynamicNode RAMNode = null;
   try {
     RAMNode = new DynamicNode(DB_RAM);
     RAMNode.setDisplayText(DbRAM.DISPLAY_NAME);
     RAMNode.setIcon(kLocalIcon);
     loadChildren(RAMNode);
     Db[] dbs = Db.getDbs();
     for (int i = 0; i < dbs.length; i++) {
       if (dbs[i] instanceof DbRAM) continue;
       if (rootNode == null) {
         rootNode = new DynamicNode(ROOT);
         rootNode.setHasLoaded();
         rootNode.add(RAMNode);
       }
       DynamicNode dbNode = new DynamicNode(dbs[i]);
       dbNode.setDisplayText(dbs[i].getDBMSName());
       dbNode.setIcon(kRepositoryIcon);
       rootNode.add(dbNode);
       loadChildren(dbNode);
     }
   } catch (DbException ex) {
     org.modelsphere.jack.util.ExceptionHandler.processUncatchedException(
         ApplicationContext.getDefaultMainFrame(), ex);
   }
   return (rootNode != null ? rootNode : RAMNode);
 }
 protected final void doActionPerformed() {
   sqlShell = new SQLShell();
   ApplicationContext.getDefaultMainFrame()
       .getJDesktopPane()
       .add(sqlShell, DefaultMainFrame.PROPERTY_LAYER);
   sqlShell.setVisible(true);
   sqlShell.setSize(600, 400);
 }
  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;
  }
 protected final void doActionPerformed() {
   if (ABOUT == null) {
     ABOUT = new SMSSplash(ApplicationContext.getDefaultMainFrame(), false, false);
   } else if (ABOUT.isVisible()) {
     ABOUT.setVisible(false);
   } else {
     ABOUT.setVisible(true);
   }
 }
 protected final void doActionPerformed() {
   int selidx = getSelectedIndex();
   DbORPrimaryUnique key = null;
   if (selidx != 0) {
     key = (DbORPrimaryUnique) dbos.get(selidx - 2);
   }
   DbObject[] objects = ApplicationContext.getFocusManager().getSelectedSemanticalObjects();
   if (objects.length != 1) return;
   try {
     DbMultiTrans.beginTrans(Db.WRITE_TRANS, objects, kSetReferencedConstraint);
     for (int i = 0; i < objects.length; i++) {
       ((DbORAssociationEnd) objects[i]).setReferencedConstraint(key);
     }
     DbMultiTrans.commitTrans(objects);
   } catch (Exception e) {
     org.modelsphere.jack.util.ExceptionHandler.processUncatchedException(
         ApplicationContext.getDefaultMainFrame(), e);
   }
 }
 public final void updateSelectionAction() {
   if (isApplicationDiagramHaveFocus()) {
     setEnabled(true);
     putValue(
         Action.NAME,
         getItemName((ApplicationDiagram) ApplicationContext.getFocusManager().getFocusObject()));
   } else {
     setEnabled(false);
   }
 }
 public void dbCreated(Db db) {
   try {
     if (db instanceof DbRAM) {
       Explorer.this.refresh();
     } else {
       Explorer.this.reloadAll();
     }
   } catch (Exception e) {
     ExceptionHandler.processUncatchedException(ApplicationContext.getDefaultMainFrame(), e);
   }
 }
 private static NotationFrame getNotationFrame(DbSMSProject project) {
   NotationFrame frameFound = null;
   JInternalFrame[] frames = ApplicationContext.getDefaultMainFrame().getDataEntryInternalFrames();
   for (int i = 0; i < frames.length; i++) {
     if (frames[i] instanceof NotationFrame && ((NotationFrame) frames[i]).project == project) {
       frameFound = (NotationFrame) frames[i];
       break;
     }
   }
   return frameFound;
 }
 public final void updateSelectionAction() throws DbException {
   int state = STATE_NOT_APPLICABLE;
   Object[] semObjs = ApplicationContext.getFocusManager().getSelectedSemanticalObjects();
   for (int i = 0; i < semObjs.length; i++) {
     if (!(semObjs[i] instanceof DbOODataMember)) {
       state = STATE_NOT_APPLICABLE;
       break;
     }
     DbOOAssociationEnd assocEnd = ((DbOODataMember) semObjs[i]).getAssociationEnd();
     if (assocEnd != null) state = updateTriState(state, assocEnd.isNavigable());
   }
   setState(state);
 }
  // 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()
  @Override
  protected void runJob() throws Exception {

    Controller controller = getController();

    // is invoked head less?
    DefaultMainFrame mainFrame = ApplicationContext.getDefaultMainFrame();
    boolean headless = (mainFrame == null);
    Db db = null;

    try {
      if (!headless) {
        // create new project, if it was not specific by the user
        m_project = m_params.getOutputProject();
        if (m_project == null) {
          m_project = (DbSMSProject) mainFrame.createDefaultProject(db);
        }

        db = m_project.getDb();
        db.beginWriteTrans(LocaleMgr.misc.getString("ImportJavaBytecode"));

        // create class model
        m_classModel = new DbJVClassModel(m_project);
      }

      // import Java classes files (jobDone 0% to 80%)
      DbJVPackage topMostPackage = importFiles(controller, 0, 80);

      // show success/failure message
      if (controller.getErrorsCount() == 0) {
        controller.println(LocaleMgr.misc.getString("Success"));
      } else {
        controller.println(LocaleMgr.misc.getString("Failed"));
      } // end if

      // create and reveal diagram ((jobDone 80% to 100%)
      if (!headless) {
        if ((topMostPackage != null) && (m_params.createDiagrams)) {
          createAndRevealDiagram(mainFrame, topMostPackage, controller, 80, 100);
        }

        db.commitTrans();
      } // end if

      controller.checkPoint(100);

    } catch (DbException ex) {
      controller.println(ex.toString());
      controller.cancel();
    } // end try
  } // end runJob()
 public static void showNotationFrame(DbSMSProject project) {
   NotationFrame notationFrame = getNotationFrame(project);
   if (notationFrame == null) {
     notationFrame = new NotationFrame();
     ApplicationContext.getDefaultMainFrame()
         .getJDesktopPane()
         .add(notationFrame, DefaultMainFrame.PROPERTY_LAYER);
     notationFrame.setVisible(true);
     try {
       notationFrame.setProject(project);
     } catch (Exception ex) {
       notationFrame.close();
       org.modelsphere.jack.util.ExceptionHandler.processUncatchedException(
           ApplicationContext.getDefaultMainFrame(), ex);
       return;
     }
   }
   try {
     notationFrame.setIcon(false);
     notationFrame.setSelected(true);
   } catch (PropertyVetoException e) {
   }
 }
  // Stategy 2 : use a DirectoryChooser2
  // pro : cute GUI
  // con : slow
  private static File selectDirectory2(
      Component parent, String defaultDirectory, String title, String approve) {
    File file = new File(defaultDirectory);
    final DefaultMainFrame mainFrame = ApplicationContext.getDefaultMainFrame();

    /*
     * mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try {
     * Thread.sleep(2000); } catch (InterruptedException ex) { }
     *
     * mainFrame.setCursor(Cursor.getDefaultCursor());
     */

    File chosenDir = DirectoryChooser2.selectDirectory(parent, file, title);

    // mainFrame.setCursor(Cursor.getDefaultCursor());

    return chosenDir;
  } // end selectOutputDirectory2()
  // This method refreshes the display text of a node.
  protected final void updateNode(DbObject dbo) throws DbException {
    DynamicNode node = getDynamicNode(dbo, false);
    if (node == null) return;

    // backup selection and restore later
    Object focusObject = ApplicationContext.getFocusManager().getFocusObject();
    TreePath[] selPaths = null;
    if (focusObject instanceof ExplorerView) {
      selPaths = ((ExplorerView) focusObject).getSelectionPaths();
    }

    String displayText = getDisplayText(null, dbo);
    String editText = getEditText(null, dbo);
    String toolTipText = getToolTipsText(null, dbo);
    Icon icon = getIcon(dbo);

    node.setDisplayText(displayText, editText);
    node.setToolTips(toolTipText);
    node.setIcon(icon);
    nodeChanged(node);
    DynamicNode parentNode = (DynamicNode) node.getParent();
    Object parent = parentNode.getUserObject();
    if (!(parent instanceof DbObject) || childrenAreSorted((DbObject) parent)) {
      removeNodeFromParent(node);
      int index = getSortedIndex(parentNode, node);
      insertNodeInto(node, parentNode, index);
    }

    // Restore selection
    if (focusObject instanceof ExplorerView && selPaths != null) {
      ExplorerView explorerView = (ExplorerView) focusObject;
      try { // Should not occurs
        explorerView.setSelectionPaths(selPaths);
      } catch (Exception e) {
        explorerView.setSelectionPaths(new TreePath[] {});
      }
    }
  }
 ForwardDataModelAction() {
   super(kForwardDataModel);
   this.setMnemonic(LocaleMgr.action.getMnemonic("ForwardEngineer"));
   setEnabled(false);
   ApplicationContext.getFocusManager().addSelectionListener(this);
 }
  private void jbInit() {
    setSize(ApplicationContext.getDefaultMainFrame().getDefaultInternalFrameSize());

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    addPropertyChangeListener(this);
    addVetoableChangeListener(this);

    // main tabbed pane
    JTabbedPane intermediateTabbedPane = new JTabbedPane();
    getContentPane().add(intermediateTabbedPane, BorderLayout.CENTER);

    // data Model section...
    String[] orOptionTabs =
        getListOptionTabs(DbORNotation.class, "listOptionTabs"); // NOT LOCALIZABLE
    for (int i = 0; i < orOptionTabs.length; i = i + 4) {
      String[] optionsName =
          new String[] {
            orOptionTabs[i], orOptionTabs[i + 1], orOptionTabs[i + 2], orOptionTabs[i + 3]
          };
      orNotationComponent =
          new NotationComponent(this, DbORNotation.metaClass, DbORNotation.fBuiltIn, optionsName);
      orNotationbankComponent =
          new NotationBankComponent(this, DbORNotation.metaClass, optionsName, false);
      JSplitPane dataSP =
          new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, orNotationbankComponent, orNotationComponent);
      intermediateTabbedPane.addTab(DATA_MODEL, dataSP);
    }

    // Process model section...
    if (ScreenPerspective.isFullVersion()) {
      String[] beOptionTabs =
          getListOptionTabs(DbBENotation.class, "listOptionTabs"); // NOT LOCALIZABLE
      for (int i = 0; i < beOptionTabs.length; i = i + 4) {
        String[] optionsName =
            new String[] {
              beOptionTabs[i], beOptionTabs[i + 1], beOptionTabs[i + 2], beOptionTabs[i + 3]
            };
        beNotationComponent =
            new NotationComponent(this, DbBENotation.metaClass, DbBENotation.fBuiltIn, optionsName);
        beNotationbankComponent =
            new NotationBankComponent(this, DbBENotation.metaClass, optionsName, false);
        JSplitPane dataSP =
            new JSplitPane(
                JSplitPane.HORIZONTAL_SPLIT, beNotationbankComponent, beNotationComponent);
        intermediateTabbedPane.addTab(BUSINESS_PROCESS_MODEL, dataSP);
      }

      // UML model section...
      for (int i = 0; i < beOptionTabs.length; i = i + 4) {
        String[] optionsName =
            new String[] {
              beOptionTabs[i], beOptionTabs[i + 1], beOptionTabs[i + 2], beOptionTabs[i + 3]
            };
        umlNotationComponent =
            new NotationComponent(this, DbBENotation.metaClass, DbBENotation.fBuiltIn, optionsName);
        umlNotationbankComponent =
            new NotationBankComponent(this, DbBENotation.metaClass, optionsName, true);
        JSplitPane dataSP =
            new JSplitPane(
                JSplitPane.HORIZONTAL_SPLIT, umlNotationbankComponent, umlNotationComponent);
        intermediateTabbedPane.addTab(UML_MODEL, dataSP);
      }
    } // end if

    /** Control Button Panel */
    JPanel btnPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
    btnPanel.setBorder(BorderFactory.createEmptyBorder(12, 6, 6, 6));
    getContentPane().add(btnPanel, BorderLayout.SOUTH);
    btnPanel.add(applyBtn);
    btnPanel.add(closeCancelBtn);
    // HIDEHELPforV1//btnPanel.add(helpBtn);

    applyBtn.setEnabled(false);
    applyBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            applyChanges();
          }
        });

    closeCancelBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            close();
          }
        });

    helpBtn.setEnabled(ApplicationContext.getDefaultMainFrame().isHelpInstalled());
    helpBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            helpBtn_actionPerformed(e);
          }
        });

    AwtUtil.normalizeComponentDimension(jButtonList, jPossibleButtonList);

    intermediateTabbedPane.setSelectedIndex(_lastSelectedIndex);
    intermediateTabbedPane.addChangeListener(this);
  }
 // context
 private void helpBtn_actionPerformed(ActionEvent e) {
   ApplicationContext.getDefaultMainFrame().displayJavaHelp("preference"); // NOT
   // LOCALIZABLE
 }
 protected final void doActionPerformed() {
   ApplicationDiagram diag =
       (ApplicationDiagram) ApplicationContext.getFocusManager().getFocusObject();
   DiagramView view = diag.getMainView();
   view.setPageBreak(!view.hasPageBreak());
 }
  protected final void doActionPerformed() {
    DbObject[] selObjs = ORActionFactory.getActiveObjects();
    if (selObjs == null || selObjs.length > 1 || selObjs.length == 0) {
      throw new RuntimeException("Expecting selection of one database");
    }
    boolean userHasCancelled = false;
    DbORDatabase database = null;
    try {
      selObjs[0].getDb().beginTrans(Db.READ_TRANS);
      DbORModel model = null;

      if (selObjs[0] instanceof DbORDatabase) {
        database = (DbORDatabase) selObjs[0];
      } else {
        model =
            (selObjs[0] instanceof DbORModel)
                ? (DbORModel) selObjs[0]
                : (DbORModel) selObjs[0].getCompositeOfType(DbORModel.metaClass);
        if (model != null) {
          if (model instanceof DbORDataModel) {
            database = ((DbORDataModel) model).getDeploymentDatabase();
          } else if (model instanceof DbORDomainModel) {
            database = ((DbORDomainModel) model).getDeploymentDatabase();
          } else if (model instanceof DbOROperationLibrary) {
            database = ((DbOROperationLibrary) model).getDeploymentDatabase();
          } // end if
        } // end if
      } // end if
      selObjs[0].getDb().commitTrans();

      if ((model != null) && (database == null)) {
        String transName =
            MessageFormat.format(
                kCreation, new Object[] {DbORDataModel.fDeploymentDatabase.getGUIName()});
        selObjs[0].getDb().beginWriteTrans(transName);
        int option =
            JOptionPane.showConfirmDialog(
                ApplicationContext.getDefaultMainFrame(),
                kNoActiveDatabase,
                ApplicationContext.getApplicationName(),
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.INFORMATION_MESSAGE);
        if (option == 0) {
          DbObject composite = model.getProject();
          DbSMSTargetSystem ts = model.getTargetSystem();
          database = AnyORObject.createDatabase(composite, ts);
          if (model instanceof DbORDataModel) {
            DbORDataModel dm = (DbORDataModel) model;
            dm.setDeploymentDatabase(database);
          } else if (model instanceof DbOROperationLibrary) {
            DbOROperationLibrary ol = (DbOROperationLibrary) model;
            ol.setDeploymentDatabase(database);
          } else if (model instanceof DbORDomainModel) {
            DbORDomainModel dm = (DbORDomainModel) model;
            dm.setDeploymentDatabase(database);
          } // end if
        } else if (option == 1) {
          userHasCancelled = true;
        } // end if

        selObjs[0].getDb().commitTrans();
      } // end if
    } catch (DbException e) {
      ExceptionHandler.processUncatchedException(ApplicationContext.getDefaultMainFrame(), e);
    } // end try

    if (userHasCancelled) {
      return;
    }

    DbSMSTargetSystem target = null;
    try {
      Db db = database.getDb();
      db.beginTrans(Db.READ_TRANS);
      target = database.getTargetSystem();
      DBMSDefaultForwardWizardModel model =
          new DBMSDefaultForwardWizardModel(target.getID().intValue());
      model.setAbstractPackage(database);
      model.setDatabaseName(database.getName());
      db.commitTrans();
      Wizard wizard = new Wizard(model);
      wizard.setVisible(true);
    } catch (InstantiationException e) {
      Component parent = ApplicationContext.getDefaultMainFrame();
      Db.abortAllTrans();
      ExceptionHandler.showErrorMessage(parent, e.getMessage());
    } catch (DbException e) {
      ExceptionHandler.processUncatchedException(ApplicationContext.getDefaultMainFrame(), e);
    } catch (RuntimeException e) {
      Component parent = ApplicationContext.getDefaultMainFrame();
      String pattern = kPattern;
      String targetName = kUnknown;

      try {
        Db db = target.getDb();
        db.beginReadTrans();
        targetName = target.getName() + " " + target.getVersion();
        db.commitTrans();
      } catch (DbException ex) {
        // leave targetName's value to unknown
      }

      String msg = MessageFormat.format(pattern, new Object[] {targetName});
      Db.abortAllTrans();
      ExceptionHandler.showErrorMessage(parent, msg);
    }
  }
  protected final void refresh(DynamicNode parentNode) throws DbException {
    if (ApplicationContext.getFocusManager().isGuiLocked()) return;

    if (parentNode == null) return;
    if (!parentNode.hasLoaded() || parentNode.isLeaf()) {
      if (parentNode.getUserObject() instanceof DbObject)
        updateNode((DbObject) parentNode.getUserObject());
      return;
    }
    Object userObject = parentNode.getUserObject();
    if (userObject == ROOT) {
      int count = getChildCount(parentNode);
      for (int i = 0; i < count; i++) {
        DynamicNode node = (DynamicNode) getChild(parentNode, i);
        userObject = node.getUserObject();
        if (userObject == DB_RAM) refresh(node);
        else {
          if (((Db) userObject).isValid()) {
            ((Db) userObject).beginTrans(Db.READ_TRANS);
            refresh(node);
            ((Db) userObject).commitTrans();
          } else {
            removeNode(node);
          }
        }
      }
      return;
    }
    if (userObject == DB_RAM) {
      int count = getChildCount(parentNode);
      for (int i = count - 1; i >= 0; i--) {
        DynamicNode node = (DynamicNode) getChild(parentNode, i);
        Db db = ((DbObject) node.getUserObject()).getDb();
        if (!db.isValid()) {
          removeNode(node);
          continue;
        }
        db.beginTrans(Db.READ_TRANS);
        refresh(node);
        // refresh the display text for the projects - we do not want to
        // apply a full update
        // using update(dbo) because we want to preserve the expanded
        // state for projects.
        node.setDisplayText(getDisplayText(null, (DbObject) node.getUserObject()));
        db.commitTrans();
      }
      // check for missing Db
      Db[] dbs = Db.getDbs();
      for (int i = 0; i < dbs.length; i++) {
        if (!dbs[i].isValid() || !(dbs[i] instanceof DbRAM)) continue;
        DynamicNode dbNode = getDynamicNode(parentNode, dbs[i], 0);
        if (dbNode != null) continue;
        dbs[i].beginTrans(Db.READ_TRANS);
        DbEnumeration dbEnum = dbs[i].getRoot().getComponents().elements(DbProject.metaClass);
        if (dbEnum.hasMoreElements()) {
          getDynamicNode(dbEnum.nextElement(), false);
        }
        dbEnum.close();
        dbs[i].commitTrans();
      }
      return;
    }

    SrVector children = new SrVector(10);
    if (userObject instanceof Db) {
      insertProjects(children, (Db) userObject);
      children.sort();
    } else if (((DbObject) userObject).isAlive()) {
      insertComponents(children, (DbObject) userObject);
      if (childrenAreSorted((DbObject) userObject))
        children.sort(getComparator((DbObject) userObject));
    }

    DynamicNode groupNode = null;
    int index = 0;
    int iGroup = 0;
    for (int i = 0; i < children.size(); i++) {
      DynamicNode srcNode = (DynamicNode) children.elementAt(i);
      GroupParams group = srcNode.getGroupParams();
      if (group.name == null) {
        refreshNode(srcNode, parentNode, index);
        index++;
      } else {
        if (groupNode == null || !groupNode.toString().equals(group.name)) {
          if (groupNode != null) deleteNodes(groupNode, iGroup);
          groupNode = getGroupNode(parentNode, group, index);
          if (groupNode == null) {
            groupNode = createGroupNode(group);
            insertNodeInto(groupNode, parentNode, index);
          } else if (groupNode != getChild(parentNode, index)) {
            removeNodeFromParent(groupNode);
            insertNodeInto(groupNode, parentNode, index);
          }
          index++;
          iGroup = 0;
        }
        refreshNode(srcNode, groupNode, iGroup);
        iGroup++;
      }
    }
    if (groupNode != null) deleteNodes(groupNode, iGroup);
    deleteNodes(parentNode, index);

    // Refresh subnodes in a separate pass to avoid interference from
    // automatic
    // adding of a primary node when adding a secondary node.
    refreshChildren(parentNode);
  }
 protected String getDisplayText(DbObject dbParent, DbObject dbo) throws DbException {
   return ApplicationContext.getSemanticalModel().getDisplayText(dbo, Explorer.class);
 }
  public final void updateSelectionAction() throws DbException {

    // Disable action not exactly one object is selected
    DbObject[] selObjs = ORActionFactory.getActiveObjects();
    if (selObjs == null || selObjs.length > 1 || selObjs.length == 0) {
      setEnabled(false);
      return;
    }

    // Get db
    boolean forwardEnabled = true;
    DbORDatabase db = null;
    if (selObjs[0] instanceof DbORDatabase) {
      db = (DbORDatabase) selObjs[0];
    } else {
      selObjs[0].getDb().beginReadTrans();
      DbORModel model =
          (selObjs[0] instanceof DbORModel)
              ? (DbORModel) selObjs[0]
              : (DbORModel) selObjs[0].getCompositeOfType(DbORModel.metaClass);
      selObjs[0].getDb().commitTrans();
      if (model == null) {
        forwardEnabled = false;
      } else {
        model.getDb().beginReadTrans();
        if (model instanceof DbORDataModel) {
          db = ((DbORDataModel) model).getDeploymentDatabase();
        } else if (model instanceof DbORDomainModel) {
          db = ((DbORDomainModel) model).getDeploymentDatabase();
        } else if (model instanceof DbOROperationLibrary) {
          db = ((DbOROperationLibrary) model).getDeploymentDatabase();
        } else {
          forwardEnabled = false;
        } // end if
        model.getDb().commitTrans();
      } // end if
    } // end if

    if (db == null) {
      setEnabled(
          forwardEnabled); // let it enable to allow doActionPerformed() to inform user of why the
      // operation cannot be archieved
    } else {
      db.getDb().beginReadTrans();
      ForwardToolkitPlugin.setActiveDiagramTarget(db.getTargetSystem().getID().intValue());
      forwardEnabled = ForwardToolkitPlugin.getToolkit().forwardEnabled();
      setEnabled(forwardEnabled);
      db.getDb().commitTrans();
    } // end if

    // Disable for ER module
    if (true == forwardEnabled) {
      TerminologyUtil terminologyUtil = TerminologyUtil.getInstance();
      Object obj = ApplicationContext.getFocusManager().getFocusObject();
      if (obj instanceof ApplicationDiagram) {
        if (obj != null) {
          DbObject semObj = ((ApplicationDiagram) obj).getSemanticalObject();
          if (semObj != null) {
            if (semObj instanceof DbORDataModel) {
              DbORDataModel model = (DbORDataModel) semObj;
              model.getDb().beginReadTrans();
              if (terminologyUtil.getModelLogicalMode(model)
                  == TerminologyUtil.LOGICAL_MODE_ENTITY_RELATIONSHIP) setEnabled(false);
              model.getDb().commitTrans();
            }
          } else setEnabled(false);
        }
      } else if (terminologyUtil.validateSelectionModel()
          == TerminologyUtil.LOGICAL_MODE_ENTITY_RELATIONSHIP) setEnabled(false);
    }
  } // end updateSelectionAction()