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();
}
}
});
}
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();
}
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");
}
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);
}
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);
}
Aggregations