Search in sources :

Example 1 with CayenneModelerController

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");
    }
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) UpgradeService(org.apache.cayenne.project.upgrade.UpgradeService) CayenneModelerController(org.apache.cayenne.modeler.CayenneModelerController) URLResource(org.apache.cayenne.resource.URLResource) Resource(org.apache.cayenne.resource.Resource) UpgradeMetaData(org.apache.cayenne.project.upgrade.UpgradeMetaData) URL(java.net.URL)

Example 2 with CayenneModelerController

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;
}
Also used : CayenneModelerController(org.apache.cayenne.modeler.CayenneModelerController)

Example 3 with CayenneModelerController

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...");
    }
}
Also used : DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo) CayenneModelerController(org.apache.cayenne.modeler.CayenneModelerController) ProjectController(org.apache.cayenne.modeler.ProjectController) DBConnectionInfo(org.apache.cayenne.modeler.pref.DBConnectionInfo)

Example 4 with CayenneModelerController

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));
}
Also used : Project(org.apache.cayenne.project.Project) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DomainDisplayEvent(org.apache.cayenne.modeler.event.DomainDisplayEvent) CayenneModelerController(org.apache.cayenne.modeler.CayenneModelerController)

Example 5 with CayenneModelerController

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();
}
Also used : Project(org.apache.cayenne.project.Project) CayenneModelerController(org.apache.cayenne.modeler.CayenneModelerController) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) File(java.io.File)

Aggregations

CayenneModelerController (org.apache.cayenne.modeler.CayenneModelerController)5 Project (org.apache.cayenne.project.Project)2 File (java.io.File)1 URL (java.net.URL)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)1 DataSourceInfo (org.apache.cayenne.conn.DataSourceInfo)1 ProjectController (org.apache.cayenne.modeler.ProjectController)1 DomainDisplayEvent (org.apache.cayenne.modeler.event.DomainDisplayEvent)1 DBConnectionInfo (org.apache.cayenne.modeler.pref.DBConnectionInfo)1 UpgradeMetaData (org.apache.cayenne.project.upgrade.UpgradeMetaData)1 UpgradeService (org.apache.cayenne.project.upgrade.UpgradeService)1 Resource (org.apache.cayenne.resource.Resource)1 URLResource (org.apache.cayenne.resource.URLResource)1