use of org.apache.cayenne.modeler.CayenneModelerController in project cayenne by apache.
the class OpenProjectAction method openProject.
/**
* Opens specified project file. File must already exist.
*/
public void openProject(File file) {
try {
if (!file.exists()) {
JOptionPane.showMessageDialog(Application.getFrame(), "Can't open project - file \"" + file.getPath() + "\" does not exist", "Can't Open Project", JOptionPane.ERROR_MESSAGE);
return;
}
CayenneModelerController controller = Application.getInstance().getFrameController();
controller.addToLastProjListAction(file);
URL url = file.toURI().toURL();
Resource rootSource = new URLResource(url);
UpgradeService upgradeService = getApplication().getInjector().getInstance(UpgradeService.class);
UpgradeMetaData metaData = upgradeService.getUpgradeType(rootSource);
switch(metaData.getUpgradeType()) {
case INTERMEDIATE_UPGRADE_NEEDED:
String modelerVersion = PROJECT_TO_MODELER_VERSION.get(metaData.getProjectVersion());
if (modelerVersion == null) {
modelerVersion = "";
}
JOptionPane.showMessageDialog(Application.getFrame(), "Open the project in the older Modeler " + modelerVersion + " to do an intermediate upgrade\nbefore you can upgrade to latest version.", "Can't Upgrade Project", JOptionPane.ERROR_MESSAGE);
closeProject(false);
return;
case DOWNGRADE_NEEDED:
JOptionPane.showMessageDialog(Application.getFrame(), "Can't open project - it was created using a newer version of the Modeler", "Can't Open Project", JOptionPane.ERROR_MESSAGE);
closeProject(false);
return;
case UPGRADE_NEEDED:
if (processUpgrades()) {
rootSource = upgradeService.upgradeProject(rootSource);
} else {
closeProject(false);
return;
}
break;
}
openProjectResourse(rootSource, controller);
} catch (Exception ex) {
logObj.warn("Error loading project file.", ex);
ErrorDebugDialog.guiWarning(ex, "Error loading project");
}
}
use of org.apache.cayenne.modeler.CayenneModelerController in project cayenne by apache.
the class ProjectAction method closeProject.
/**
* Returns true if successfully closed project, false otherwise.
*/
public boolean closeProject(boolean checkUnsaved) {
// check if there is a project...
if (getProjectController() == null || getProjectController().getProject() == null) {
return true;
}
if (checkUnsaved && !checkSaveOnClose()) {
return false;
}
CayenneModelerController controller = Application.getInstance().getFrameController();
application.getUndoManager().discardAllEdits();
controller.projectClosedAction();
return true;
}
use of org.apache.cayenne.modeler.CayenneModelerController in project cayenne by apache.
the class JDBCDataSourceEditor method syncDataSourceAction.
/**
* This action is called whenever the password location is changed
* in the GUI pulldown. It changes labels and editability of the
* password fields depending on the option that was selected.
*/
public void syncDataSourceAction() {
CayenneModelerController mainController = getApplication().getFrameController();
if (getNode() == null || getNode().getDataSourceDescriptor() == null) {
return;
}
DataSourceInfo projectDSI = getNode().getDataSourceDescriptor();
ProjectController parent = (ProjectController) getParent();
String key = parent.getDataNodePreferences().getLocalDataSource();
if (key == null) {
mainController.updateStatus("No Local DataSource selected for node...");
return;
}
DBConnectionInfo dataSource = (DBConnectionInfo) getApplication().getCayenneProjectPreferences().getDetailObject(DBConnectionInfo.class).getObject(key);
if (dataSource != null) {
if (dataSource.copyTo(projectDSI)) {
refreshView();
super.nodeChangeProcessor.modelUpdated(null, null, null);
mainController.updateStatus(null);
} else {
mainController.updateStatus("DataNode is up to date...");
}
} else {
mainController.updateStatus("Invalid Local DataSource selected for node...");
}
}
use of org.apache.cayenne.modeler.CayenneModelerController in project cayenne by apache.
the class NewProjectAction method performAction.
public void performAction(ActionEvent e) {
CayenneModelerController controller = Application.getInstance().getFrameController();
// Save and close (if needed) currently open project.
if (getCurrentProject() != null && !closeProject(true)) {
return;
}
DataChannelDescriptor dataChannelDescriptor = new DataChannelDescriptor();
dataChannelDescriptor.setName(NameBuilder.builder(dataChannelDescriptor).name());
Project project = new Project(new ConfigurationTree<DataChannelDescriptor>(dataChannelDescriptor));
controller.projectOpenedAction(project);
// select default domain
getProjectController().fireDomainDisplayEvent(new DomainDisplayEvent(this, dataChannelDescriptor));
}
use of org.apache.cayenne.modeler.CayenneModelerController in project cayenne by apache.
the class RevertAction method performAction.
public void performAction(ActionEvent e) {
Project project = getCurrentProject();
if (project == null) {
return;
}
boolean isNew = project.getConfigurationResource() == null;
CayenneModelerController controller = getApplication().getFrameController();
// close ... don't use OpenProjectAction close method as it will ask for save, we
// don't want that here
controller.projectClosedAction();
File fileDirectory = new File(project.getConfigurationResource().getURL().getPath());
// reopen existing
if (!isNew && fileDirectory.isFile()) {
OpenProjectAction openAction = controller.getApplication().getActionManager().getAction(OpenProjectAction.class);
openAction.openProject(fileDirectory);
} else // create new
if (!(project instanceof Project)) {
throw new CayenneRuntimeException("Only ApplicationProjects are supported.");
} else {
controller.getApplication().getActionManager().getAction(NewProjectAction.class).performAction(e);
}
application.getUndoManager().discardAllEdits();
}
Aggregations