Search in sources :

Example 6 with IUndoHandler

use of org.freeplane.core.undo.IUndoHandler in project freeplane by freeplane.

the class EditStylesAction method init.

private void init() {
    this.mainController = Controller.getCurrentController();
    if (dialog != null) {
        Controller.setCurrentController((Controller) dialog.getRootPane().getClientProperty(Controller.class));
        return;
    }
    dialog = new JDialog(UITools.getCurrentFrame());
    final WindowConfigurationStorage windowConfigurationStorage = new WindowConfigurationStorage(getKey() + ".dialog");
    windowConfigurationStorage.restoreDialogPositions(dialog);
    dialog.setModal(true);
    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(final WindowEvent e) {
            getModeController().tryToCloseDialog();
        }
    });
    Controller styleDialogController = SModeControllerFactory.getInstance().createController(dialog);
    modeController = (SModeController) styleDialogController.getModeController();
    final ViewController viewController = styleDialogController.getViewController();
    viewController.init(styleDialogController);
    dialog.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentHidden(final ComponentEvent e) {
            final WindowConfigurationStorage windowConfigurationStorage = new WindowConfigurationStorage(getKey() + ".dialog");
            windowConfigurationStorage.storeDialogPositions(dialog);
            final IMapViewManager mapViewManager = modeController.getController().getMapViewManager();
            final MapModel map = mapViewManager.getModel();
            final IUndoHandler undoHandler = (IUndoHandler) map.getExtension(IUndoHandler.class);
            modeController.getMapController().closeWithoutSaving(map);
            Controller.setCurrentController(mainController);
            super.componentHidden(e);
            mainController.getMapViewManager().changeToMapView(currentMapView);
            currentMapView = null;
            switch(modeController.getStatus()) {
                case JOptionPane.OK_OPTION:
                    if (undoHandler.canUndo()) {
                        commit();
                        break;
                    }
                // $FALL-THROUGH$
                case JOptionPane.CANCEL_OPTION:
                    rollback();
            }
        }
    });
}
Also used : IMapViewManager(org.freeplane.features.ui.IMapViewManager) ViewController(org.freeplane.features.ui.ViewController) WindowEvent(java.awt.event.WindowEvent) WindowConfigurationStorage(org.freeplane.core.resources.WindowConfigurationStorage) WindowAdapter(java.awt.event.WindowAdapter) IUndoHandler(org.freeplane.core.undo.IUndoHandler) ComponentEvent(java.awt.event.ComponentEvent) MapModel(org.freeplane.features.map.MapModel) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) ViewController(org.freeplane.features.ui.ViewController) JDialog(javax.swing.JDialog) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 7 with IUndoHandler

use of org.freeplane.core.undo.IUndoHandler in project freeplane by freeplane.

the class ControllerProxy method undo.

public void undo() {
    final MapModel map = Controller.getCurrentController().getMap();
    final IUndoHandler undoHandler = (IUndoHandler) map.getExtension(IUndoHandler.class);
    undoHandler.undo();
}
Also used : IUndoHandler(org.freeplane.core.undo.IUndoHandler) MMapModel(org.freeplane.features.map.mindmapmode.MMapModel) MapModel(org.freeplane.features.map.MapModel)

Example 8 with IUndoHandler

use of org.freeplane.core.undo.IUndoHandler in project freeplane by freeplane.

the class ControllerProxy method restartTransaction.

private void restartTransaction(final MapModel oldMap, final MapModel newmap) {
    final IUndoHandler oldUndoHandler = (IUndoHandler) oldMap.getExtension(IUndoHandler.class);
    final IUndoHandler newUndoHandler = (IUndoHandler) newmap.getExtension(IUndoHandler.class);
    final int transactionLevel = oldUndoHandler.getTransactionLevel();
    if (transactionLevel == 0) {
        return;
    }
    if (transactionLevel == 1) {
        oldUndoHandler.commit();
        newUndoHandler.startTransaction();
        return;
    }
    throw new RuntimeException("can not create map inside transaction");
}
Also used : IUndoHandler(org.freeplane.core.undo.IUndoHandler)

Example 9 with IUndoHandler

use of org.freeplane.core.undo.IUndoHandler in project freeplane by freeplane.

the class EditStylesAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final Controller currentController = Controller.getCurrentController();
    final MapModel map = currentController.getMap();
    final MapStyleModel mapStyleModel = MapStyleModel.getExtension(map);
    final MapModel styleMap = mapStyleModel.getStyleMap();
    if (styleMap == null) {
        UITools.errorMessage(TextUtils.getText("no_styles_found_in_map"));
        return;
    }
    final IMapViewManager mapViewManager = currentController.getMapViewManager();
    currentMapView = mapViewManager.getMapViewComponent();
    mapViewManager.changeToMapView((Component) null);
    final IUndoHandler undoHandler = (IUndoHandler) map.getExtension(IUndoHandler.class);
    undoHandler.startTransaction();
    init();
    SModeController modeController = getModeController();
    modeController.getMapController().newMapView(styleMap);
    Controller controller = modeController.getController();
    Component mapViewComponent = controller.getMapViewManager().getMapViewComponent();
    ((DialogController) controller.getViewController()).setMapView(mapViewComponent);
    dialog.setLocationRelativeTo(currentController.getViewController().getCurrentRootComponent());
    dialog.setVisible(true);
}
Also used : IMapViewManager(org.freeplane.features.ui.IMapViewManager) MapStyleModel(org.freeplane.features.styles.MapStyleModel) IUndoHandler(org.freeplane.core.undo.IUndoHandler) MapModel(org.freeplane.features.map.MapModel) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) ViewController(org.freeplane.features.ui.ViewController) Component(java.awt.Component)

Example 10 with IUndoHandler

use of org.freeplane.core.undo.IUndoHandler in project freeplane by freeplane.

the class SModeController method tryToCloseDialog.

void tryToCloseDialog() {
    final IMapViewManager mapViewManager = getController().getMapViewManager();
    final MapModel map = mapViewManager.getModel();
    final IUndoHandler undoHandler = (IUndoHandler) map.getExtension(IUndoHandler.class);
    final Window dialog = ((DialogController) getController().getViewController()).getDialog();
    if (!undoHandler.canUndo()) {
        dialog.setVisible(false);
        return;
    }
    final String text = TextUtils.getText("save_unsaved_styles");
    final String title = TextUtils.getText("SaveAction.text");
    final int returnVal = JOptionPane.showOptionDialog(dialog, text, title, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
    if ((returnVal == JOptionPane.CANCEL_OPTION) || (returnVal == JOptionPane.CLOSED_OPTION)) {
        return;
    }
    setStatus(returnVal == JOptionPane.YES_OPTION ? JOptionPane.OK_OPTION : JOptionPane.CANCEL_OPTION);
    dialog.setVisible(false);
}
Also used : IMapViewManager(org.freeplane.features.ui.IMapViewManager) Window(java.awt.Window) IUndoHandler(org.freeplane.core.undo.IUndoHandler) MapModel(org.freeplane.features.map.MapModel)

Aggregations

IUndoHandler (org.freeplane.core.undo.IUndoHandler)21 MapModel (org.freeplane.features.map.MapModel)15 MMapModel (org.freeplane.features.map.mindmapmode.MMapModel)10 Controller (org.freeplane.features.mode.Controller)4 IActor (org.freeplane.core.undo.IActor)3 NodeModel (org.freeplane.features.map.NodeModel)3 IMapViewManager (org.freeplane.features.ui.IMapViewManager)3 ModeController (org.freeplane.features.mode.ModeController)2 LogicalStyleController (org.freeplane.features.styles.LogicalStyleController)2 ViewController (org.freeplane.features.ui.ViewController)2 Component (java.awt.Component)1 Window (java.awt.Window)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 JDialog (javax.swing.JDialog)1 WindowConfigurationStorage (org.freeplane.core.resources.WindowConfigurationStorage)1 MapStyleModel (org.freeplane.features.styles.MapStyleModel)1