Search in sources :

Example 1 with DisconnectAction

use of easik.ui.menu.popup.DisconnectAction in project fql by CategoricalData.

the class SketchFrame method buildMenu.

/**
 * Builds the menu
 */
private void buildMenu() {
    final JMenuBar mainMenu;
    final JMenu menuFile;
    final JMenu menuHelp;
    mainMenu = new JMenuBar();
    // Make the File Menu
    menuFile = new JMenu("File");
    mainMenu.add(menuFile);
    menuFile.setMnemonic(KeyEvent.VK_F);
    final JMenu exportMenu = new JMenu("Export to");
    menuFile.add(exportMenu);
    // Export to server:
    addMenuItem(exportMenu, new JMenuItem(new ExportDatabaseAction(this, _ourSketch)), KeyEvent.VK_D);
    // Export to SQL text dump:
    addMenuItem(exportMenu, new JMenuItem(new ExportFileAction(this, _ourSketch)), KeyEvent.VK_F);
    addMenuItem(exportMenu, new JMenuItem(new ExportImageAction<>(this)), null);
    addMenuItem(exportMenu, new JMenuItem(new SketchExportAction(this)), null);
    menuFile.addSeparator();
    addMenuItem(menuFile, new JMenuItem(new DocumentInfoAction(this)), KeyEvent.VK_I);
    menuFile.addSeparator();
    addMenuItem(menuFile, new JMenuItem(new FileQuitAction(this)), KeyEvent.VK_W);
    // Make the Edit menu for "edit mode"
    menuEditEdit = new JMenu("Edit");
    mainMenu.add(menuEditEdit);
    addMenuItem(menuEditEdit, _UndoItem = new JMenuItem(new UndoAction(_ourSketch)), KeyEvent.VK_Z);
    addMenuItem(menuEditEdit, _RedoItem = new JMenuItem(new RedoAction(_ourSketch)), KeyEvent.VK_Y);
    menuEditEdit.addSeparator();
    menuEditEdit.add(menuEditAdd = new JMenu("Add"));
    addMenuItem(menuEditAdd, _AddEntityItem = new JMenuItem(new NewEntityAction<>(null, this)), null);
    menuEditAdd.add(menuEditAddEdge = new JMenu("Add edge"));
    addMenuItem(menuEditAddEdge, addEdge = new JMenuItem(new NewSketchEdgeAction(this, Edge.NORMAL)), null);
    addMenuItem(menuEditAddEdge, addInjEdge = new JMenuItem(new NewSketchEdgeAction(this, Edge.INJECTIVE)), null);
    addMenuItem(menuEditAddEdge, addParEdge = new JMenuItem(new NewSketchEdgeAction(this, Edge.PARTIAL)), null);
    addMenuItem(menuEditAddEdge, addSelfParEdge = new JMenuItem(new NewSketchEdgeAction(this, Edge.SELF)), null);
    addMenuItem(menuEditAdd, addAtt = new JMenuItem(new AddAttributeAction<>(this)), null);
    addMenuItem(menuEditAdd, addUK = new JMenuItem(new AddUniqueKeyAction<>(this)), null);
    addMenuItem(menuEditEdit, del = new JMenuItem(new DeleteFromSketchAction(this)), null);
    addMenuItem(menuEditEdit, rename = new JMenuItem(new RenameInSketchAction(this)), KeyEvent.VK_R);
    menuEditEdit.add(new JSeparator());
    addMenuItem(menuEditEdit, editEdge = new JMenuItem(new EditSketchEdgeAction(this)), KeyEvent.VK_E);
    menuEditEdit.add(new JSeparator());
    // If
    addMenuItem(menuEditEdit, _ProgramSettingsItem = new JMenuItem("Preferences"), KeyEvent.VK_P);
    // you
    // change
    // this
    // title,
    // update
    // OSX.java
    _ProgramSettingsItem.setToolTipText("Set global EASIK preferences");
    _ProgramSettingsItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e1) {
            final ProgramSettingsUI myUI = new ProgramSettingsUI(SketchFrame.this);
            myUI.showDialog();
        }
    });
    // add listener to enable appropriate menu items
    menuEditEdit.addMenuListener(new MenuListener() {

        @Override
        public void menuCanceled(final MenuEvent e) {
        }

        @Override
        public void menuDeselected(final MenuEvent e) {
        }

        @Override
        public void menuSelected(final MenuEvent e) {
            final Object[] selection = _ourSketch.getSelectionCells();
            final SketchGraphModel model = _ourSketch.getGraphModel();
            final boolean undoable = model.canUndo() && !_ourSketch.getDatabase().hasConnection() && !_ourSketch.isSynced();
            final boolean redoable = model.canRedo() && !_ourSketch.getDatabase().hasConnection() && !_ourSketch.isSynced();
            _UndoItem.setEnabled(undoable);
            _RedoItem.setEnabled(redoable);
            menuEditAdd.setEnabled(true);
            menuEditAddEdge.setEnabled(true);
            _AddEntityItem.setEnabled(false);
            addEdge.setEnabled(false);
            addInjEdge.setEnabled(false);
            addParEdge.setEnabled(false);
            addSelfParEdge.setEnabled(false);
            addAtt.setEnabled(false);
            addUK.setEnabled(false);
            rename.setEnabled(false);
            del.setEnabled(false);
            editEdge.setEnabled(false);
            if (selection.length == 0) {
                _AddEntityItem.setEnabled(true);
                menuEditAddEdge.setEnabled(false);
            }
            if (selection.length >= 1) {
                del.setEnabled(true);
                if (selection.length == 1) {
                    if (selection[0] instanceof EntityNode) {
                        rename.setEnabled(true);
                    }
                    if (selection[0] instanceof EntityNode) {
                        addSelfParEdge.setEnabled(true);
                        addAtt.setEnabled(true);
                        addUK.setEnabled(true);
                    } else if (selection[0] instanceof SketchEdge) {
                        editEdge.setEnabled(true);
                    }
                }
                // if selection contains an edge, dissable edit|add...
                for (int i = 0; i < selection.length; i++) {
                    if (selection[i] instanceof SketchEdge) {
                        menuEditAdd.setEnabled(false);
                    }
                }
                if (selection.length >= 3) {
                    menuEditAdd.setEnabled(false);
                }
            }
            if ((selection.length == 2) && (selection[0] instanceof EntityNode) && (selection[1] instanceof EntityNode)) {
                addEdge.setEnabled(true);
                addInjEdge.setEnabled(true);
                addParEdge.setEnabled(true);
            }
        }
    });
    // Make the Edit menu for "manipulate mode"
    @SuppressWarnings("unused") final JMenuItem updateRowMenuItem;
    @SuppressWarnings("unused") final JMenuItem viewDataMenuItem;
    menuEditManip = new JMenu("Edit");
    mainMenu.add(menuEditManip);
    menuEditManip.add(addRowMenuItem = new JMenuItem(new AddRowAction(_ourSketch)));
    menuEditManip.add(insertQueryMenuItem = new JMenuItem(new ExecPreparedInsertAction(_ourSketch)));
    menuEditManip.addSeparator();
    menuEditManip.add(updateRowMenuItem = new JMenuItem(new UpdateRowAction(_ourSketch)));
    menuEditManip.addSeparator();
    menuEditManip.add(deleteRowMenuItem = new JMenuItem(new DeleteRowAction(_ourSketch)));
    menuEditManip.add(deleteQueryMenuItem = new JMenuItem(new ExecPreparedDeleteAction(_ourSketch)));
    menuEditManip.addSeparator();
    menuEditManip.add(viewDataMenuItem = new JMenuItem(new ViewDataAction(_ourSketch)));
    menuEditManip.addMenuListener(new MenuListener() {

        @Override
        public void menuCanceled(final MenuEvent e) {
        }

        @Override
        public void menuDeselected(final MenuEvent e) {
        }

        @Override
        public void menuSelected(final MenuEvent e) {
            final Object[] selection = _ourSketch.getSelectionCells();
            final boolean enable = (selection.length == 1) && (selection[0] instanceof EntityNode);
            for (final Component c : menuEditManip.getMenuComponents()) {
                c.setEnabled(enable);
            }
            if (!enable) {
                return;
            }
            if (!_ourSketch.editable((EntityNode) selection[0])) {
                addRowMenuItem.setEnabled(false);
                insertQueryMenuItem.setEnabled(false);
                deleteRowMenuItem.setEnabled(false);
                deleteQueryMenuItem.setEnabled(false);
            }
        }
    });
    menuView = new JMenu("View");
    mainMenu.add(menuView);
    menuView.add(_ShowAttributesToggle = new JCheckBoxMenuItem("Attributes/keys visible"));
    _ShowAttributesToggle.setToolTipText("Toggle display of attributes and unique keys");
    _ShowAttributesToggle.setState("show".equals(Easik.getInstance().getSettings().getProperty("attrib_display", "show")));
    _ShowAttributesToggle.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e1) {
            _ourSketch.refresh();
        }
    });
    menuView.add(_ShowConstraintToggle = new JCheckBoxMenuItem("Constraints visible"));
    _ShowConstraintToggle.setToolTipText("Toggle display of constraints");
    _ShowConstraintToggle.setState(true);
    _ShowConstraintToggle.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e1) {
            ModelConstraint.setAllConstraintsVisible(_ourSketch.getConstraints(), _ShowConstraintToggle.getState());
        }
    });
    // Create constraints menu
    menuConstraint = new JMenu("Constraints");
    menuConstraint.setMnemonic(KeyEvent.VK_C);
    mainMenu.add(menuConstraint);
    addMenuItem(menuConstraint, _AddCommutativeDiagramMenuItem = new JMenuItem(new AddCommutativeDiagramAction<>(this)), null);
    addMenuItem(menuConstraint, _AddSumMenuItem = new JMenuItem(new AddSumConstraintAction<>(this)), null);
    addMenuItem(menuConstraint, _AddProductMenuItem = new JMenuItem(new AddProductConstraintAction<>(this)), null);
    addMenuItem(menuConstraint, _AddPullbackMenuItem = new JMenuItem(new AddPullbackConstraintAction<>(this)), null);
    addMenuItem(menuConstraint, _AddEqualizerMenuItem = new JMenuItem(new AddEqualizerConstraintAction(this)), null);
    // addMenuItem(menuConstraint, _AddLimMenuItem = new JMenuItem(new
    // AddLimitConstraintAction<SketchFrame,
    // SketchGraphModel,Sketch,EntityNode, SketchEdge>(this)), null);
    // Make SQL connection menu
    menuSQL = new JMenu("SQL Connection");
    menuSQL.setMnemonic(KeyEvent.VK_S);
    mainMenu.add(menuSQL);
    addMenuItem(menuSQL, new JMenuItem(new DisconnectAction(_ourSketch)), null);
    // DTRIG
    addMenuItem(menuSQL, new JMenuItem(new OverrideConstraintAction(_ourSketch)), null);
    // CF2012
    // Create help menu
    menuHelp = new JMenu("Help");
    mainMenu.add(menuHelp);
    menuHelp.setMnemonic(KeyEvent.VK_H);
    menuHelp.add(new HelpAction());
    menuHelp.add(new AboutAction());
    setJMenuBar(mainMenu);
}
Also used : HelpAction(easik.ui.menu.HelpAction) ActionEvent(java.awt.event.ActionEvent) MenuListener(javax.swing.event.MenuListener) ExecPreparedDeleteAction(easik.ui.datamanip.jdbc.ExecPreparedDeleteAction) ExportFileAction(easik.ui.menu.ExportFileAction) ViewDataAction(easik.ui.menu.popup.ViewDataAction) NewSketchEdgeAction(easik.ui.menu.popup.NewSketchEdgeAction) DeleteRowAction(easik.ui.menu.popup.DeleteRowAction) JSeparator(javax.swing.JSeparator) EntityNode(easik.sketch.vertex.EntityNode) DeleteFromSketchAction(easik.ui.menu.popup.DeleteFromSketchAction) ExecPreparedInsertAction(easik.ui.datamanip.jdbc.ExecPreparedInsertAction) RedoAction(easik.ui.menu.RedoAction) JMenuItem(javax.swing.JMenuItem) Component(java.awt.Component) MenuEvent(javax.swing.event.MenuEvent) SketchExportAction(easik.ui.menu.SketchExportAction) UpdateRowAction(easik.ui.menu.popup.UpdateRowAction) AddRowAction(easik.ui.menu.popup.AddRowAction) AboutAction(easik.ui.menu.AboutAction) EditSketchEdgeAction(easik.ui.menu.popup.EditSketchEdgeAction) RenameInSketchAction(easik.ui.menu.popup.RenameInSketchAction) ExportImageAction(easik.ui.menu.ExportImageAction) ExportDatabaseAction(easik.ui.menu.ExportDatabaseAction) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) DisconnectAction(easik.ui.menu.popup.DisconnectAction) FileQuitAction(easik.ui.menu.FileQuitAction) ActionListener(java.awt.event.ActionListener) SketchEdge(easik.sketch.edge.SketchEdge) OverrideConstraintAction(easik.ui.menu.popup.OverrideConstraintAction) DocumentInfoAction(easik.ui.menu.DocumentInfoAction) AddEqualizerConstraintAction(easik.ui.menu.AddEqualizerConstraintAction) UndoAction(easik.ui.menu.UndoAction) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Aggregations

SketchEdge (easik.sketch.edge.SketchEdge)1 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)1 EntityNode (easik.sketch.vertex.EntityNode)1 ExecPreparedDeleteAction (easik.ui.datamanip.jdbc.ExecPreparedDeleteAction)1 ExecPreparedInsertAction (easik.ui.datamanip.jdbc.ExecPreparedInsertAction)1 AboutAction (easik.ui.menu.AboutAction)1 AddEqualizerConstraintAction (easik.ui.menu.AddEqualizerConstraintAction)1 DocumentInfoAction (easik.ui.menu.DocumentInfoAction)1 ExportDatabaseAction (easik.ui.menu.ExportDatabaseAction)1 ExportFileAction (easik.ui.menu.ExportFileAction)1 ExportImageAction (easik.ui.menu.ExportImageAction)1 FileQuitAction (easik.ui.menu.FileQuitAction)1 HelpAction (easik.ui.menu.HelpAction)1 RedoAction (easik.ui.menu.RedoAction)1 SketchExportAction (easik.ui.menu.SketchExportAction)1 UndoAction (easik.ui.menu.UndoAction)1 AddRowAction (easik.ui.menu.popup.AddRowAction)1 DeleteFromSketchAction (easik.ui.menu.popup.DeleteFromSketchAction)1 DeleteRowAction (easik.ui.menu.popup.DeleteRowAction)1 DisconnectAction (easik.ui.menu.popup.DisconnectAction)1