Commit 1332e036 authored by Hernan Ponce de Leon's avatar Hernan Ponce de Leon
Browse files

Taking care of code review

parent 126c0087
ApplicationCommandHandler.java 95389af912d99ccf66a372d462611c01efffddaa YELLOW
ApplicationCommandHandler.java 11f2035cca4656fd80dd5d56f49abd8c156357a1 RED
......@@ -16,29 +16,37 @@
package org.fortiss.af3.rcp.application.handler;
import static org.conqat.ide.commons.ui.ui.WorkbenchUtils.getActiveWorkbenchWindow;
import static org.eclipse.emf.common.util.URI.createFileURI;
import static org.eclipse.jface.dialogs.ErrorDialog.openError;
import static org.eclipse.jface.dialogs.MessageDialog.openError;
import static org.eclipse.jface.dialogs.MessageDialog.openWarning;
import static org.eclipse.ui.internal.about.AboutUtils.openErrorLogBrowser;
import static org.fortiss.af3.project.storage.LocationProvider.CURRENT_AF3_PROJECT_FILES_EXTENSION;
import static org.fortiss.af3.project.ui.utils.ExportProjectUtils.exportProject;
import static org.fortiss.af3.project.ui.utils.ExportProjectUtils.fileSelectionDialog;
import static org.fortiss.af3.project.ui.utils.ImportProjectUtils.fileSelectionDialog;
import static org.fortiss.af3.project.ui.utils.ImportProjectUtils.importFileCopy;
import static org.fortiss.af3.project.ui.utils.NewProjectUtils.createNewGeneralProject;
import static org.fortiss.af3.project.ui.utils.NewProjectUtils.generalProjectExists;
import static org.fortiss.af3.project.utils.FileUtils.saveFileLibrary;
import static org.fortiss.af3.project.utils.LibraryModelElementFactory.createFileLibrary;
import static org.fortiss.af3.project.utils.ProjectUtils.loadProjectFromPlugin;
import static org.fortiss.af3.rcp.application.utils.ApplicationUtils.refreshWorkspace;
import static org.fortiss.af3.rcp.application.utils.ApplicationUtils.saveProject;
import static org.fortiss.af3.rcp.application.utils.ApplicationUtils.switchToAF3Perspective;
import static org.fortiss.tooling.kernel.ToolingKernelActivator.getDefault;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.copy;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import java.util.List;
import org.conqat.ide.commons.ui.ui.WorkbenchUtils;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Display;
......@@ -51,12 +59,9 @@ import org.fortiss.af3.project.model.FileLibrary;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.af3.project.ui.utils.ExportProjectUtils;
import org.fortiss.af3.project.ui.utils.FileNameValidatorUtil;
import org.fortiss.af3.project.ui.utils.ImportProjectUtils;
import org.fortiss.af3.project.utils.ProjectUtils;
import org.fortiss.af3.rcp.application.AF3ApplicationActivator;
import org.fortiss.af3.rcp.application.example.SimpleTrafficLightsCodeGenerationExample;
import org.fortiss.af3.rcp.application.utils.ApplicationUtils;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.extension.data.ModelStorageError;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.fortiss.tooling.kernel.ui.service.INavigatorService;
......@@ -111,9 +116,9 @@ public class ApplicationCommandHandler {
// otherwise the Example is shown twice).
FileProject project = null;
try {
project = ProjectUtils.loadProjectFromPlugin(pluginID, relativePath, false);
project = loadProjectFromPlugin(pluginID, relativePath, false);
} catch(Exception e) {
error(ToolingKernelActivator.getDefault(), "Failed to load model from " + relativePath);
error(getDefault(), "Failed to load model from " + relativePath);
} finally {
if(project == null) {
return;
......@@ -150,7 +155,7 @@ public class ApplicationCommandHandler {
}
// Enable the AF3 Perspective.
ApplicationUtils.switchToAF3Perspective();
switchToAF3Perspective();
}
/** Command to exit the application. */
......@@ -207,14 +212,13 @@ public class ApplicationCommandHandler {
// If a file with this name already exists.
if(!saveFileLibrary(library)) {
openError(WorkbenchUtils.getActiveWorkbenchWindow().getShell(),
openError(getActiveWorkbenchWindow().getShell(),
"Error While Saving the Library",
"A library with name " + dlg.getValue() + " already exists");
}
INavigatorService.getInstance().setLibraryViewActive();
} catch(Exception e) {
openError(WorkbenchUtils.getActiveWorkbenchWindow().getShell(), "Error",
e.getMessage());
openError(getActiveWorkbenchWindow().getShell(), "Error", e.getMessage());
return false;
}
......@@ -455,10 +459,6 @@ public class ApplicationCommandHandler {
*/
@Override
public Object execute(ExecutionEvent event) {
// TODO(AD): There are two files in the test-data directory:
// STLCBeagleJavaDeploymentNoUseCase and stlc_beagle_java_deployment_example. Either
// both shall be present in the menu or stlc_beagle_java_deployment_example is outdated
// and should be removed (IMHO).
loadExistingModel(AF3ApplicationActivator.PLUGIN_ID,
"test-data/STLCBeagleJavaDeploymentNoUseCase.af3_23",
"STLC Beagle Java Deployment");
......@@ -478,11 +478,11 @@ public class ApplicationCommandHandler {
startup();
// Open file selection dialog to select the file to be imported.
String importFile = ImportProjectUtils.fileSelectionDialog();
String importFile = fileSelectionDialog();
if(importFile != null) {
// Copy selected file into workspace.
ImportProjectUtils.importFileCopy(URI.createFileURI(importFile));
importFileCopy(createFileURI(importFile));
refreshWorkspace();
}
......@@ -504,16 +504,15 @@ public class ApplicationCommandHandler {
if(selectedProject != null) {
// Open file selection dialog to select the target file
// location.
String exportFileLocation =
ExportProjectUtils.fileSelectionDialog(selectedProject.getName());
String exportFileLocation = fileSelectionDialog(selectedProject.getName());
// If the user doesn't abort the export during file selection.
if(exportFileLocation != null) {
// Use copy to avoid error 'Cannot modify resource set
// without a write transaction'.
ExportProjectUtils.exportProject(copy(selectedProject), selectedProject
.eResource().getURI(), URI.createFileURI(exportFileLocation));
exportProject(copy(selectedProject), selectedProject.eResource().getURI(),
createFileURI(exportFileLocation));
}
}
return null;
......@@ -531,8 +530,7 @@ public class ApplicationCommandHandler {
@SuppressWarnings("restriction")
@Override
public Object execute(ExecutionEvent event) {
org.eclipse.ui.internal.about.AboutUtils.openErrorLogBrowser(Display.getCurrent()
.getActiveShell());
openErrorLogBrowser(Display.getCurrent().getActiveShell());
return null;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment