Commit 33ff0da9 authored by Alexander Diewald's avatar Alexander Diewald

Merge remote-tracking branch 'origin/master' into 3838

parents dd7a493d db4d2bc6
AF3ExplorationUIActivator.java 9d2d437f57c50fa728c6bf0300ed86bca1311c33 GREEN
AF3ExplorationUIActivator.java a1b08c5c94bfd6d9f192535e2db9bd5cbe8fbedd GREEN
......@@ -31,7 +31,9 @@ import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PerspectiveAdapter;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.fortiss.af3.exploration.ui.cli.CommandLineDSEProjectLoading;
import org.fortiss.af3.exploration.ui.perspective.process.IProcessManager;
import org.fortiss.tooling.kernel.service.ICommandLineInterfaceService;
import org.osgi.framework.BundleContext;
/**
......@@ -95,6 +97,9 @@ public class AF3ExplorationUIActivator extends AbstractUIPlugin {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
ICommandLineInterfaceService cliService = ICommandLineInterfaceService.getInstance();
cliService.registerHandler("--loadDSE", new CommandLineDSEProjectLoading());
}
/** Closes all opened views except Main Menu View */
......
CommandLineDSEProjectLoading.java 3baa51b26a31bcc4eaa19e4f6c17820d76ae1d92 GREEN
/*-------------------------------------------------------------------------+
| Copyright 2020 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.ui.cli;
import static org.apache.commons.lang3.StringUtils.countMatches;
import static org.conqat.ide.commons.ui.logging.LoggingUtils.logAndShowError;
import static org.fortiss.af3.exploration.ui.util.ExplorationUiUtils.getFQNID;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.showError;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.fortiss.af3.exploration.model.project.DSE;
import org.fortiss.af3.exploration.ui.AF3ExplorationUIActivator;
import org.fortiss.af3.exploration.ui.perspective.DSEperspective;
import org.fortiss.af3.exploration.ui.perspective.dashboard.DashboardFXViewPart;
import org.fortiss.af3.exploration.ui.perspective.service.IDSEPerspectiveManager;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.tooling.kernel.extension.ICommandLineSwitchHandler;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
/**
* Handler to preload a DSE project and switch the initial perspective to the DSE perspective.
*
* @author diewald
*/
public class CommandLineDSEProjectLoading implements ICommandLineSwitchHandler {
/** Name of the AF3 project to be searched for a matching DSE project. */
private String af3PrjName;
/** Name of the DSE project to be searched in the given AF3 project. */
private String dsePrjName;
/** The first AF3 project matching the given AF3 project name. */
private FileProject matchingAF3Project;
/** The first DSE project matching the given project name within the found AF3 project. */
private DSE matchingDSE;
/** {@inheritDoc} */
@Override
public boolean hasAdditionalArgument() {
return true;
}
/** {@inheritDoc} */
@Override
public void handleCLISwitch(String argument) {
if(!parseArgument(argument)) {
return;
}
if(!findReferencedDSEProject()) {
return;
}
showDSEPerspective();
// Load the DSE project.
IDSEPerspectiveManager.INSTANCE.setCurrentlySelectedDSE(matchingDSE);
}
/**
* Parses the argument for the required structure and extracts the AF3 and its DSE project name.
*
* @return {@code true} if the argument could be parsed, {@code false} otherwise.
*/
private boolean parseArgument(String argument) {
int slashCount = countMatches(argument, "/");
if(slashCount != 1) {
logAndShowError(AF3ExplorationUIActivator.getDefault(),
"The DSE to be loaded at startup must be provided in the format " +
"<AF3-Project>/<DSE-Name>",
null);
return false;
}
String[] argParts = argument.split("/");
af3PrjName = argParts[0];
dsePrjName = argParts[1];
return true;
}
/**
* Finds the AF3 project and a contained DSE project by the names given with the switch.
*
* @return {@code true} if the DSE project was found, {@code false} otherwise.
*/
private boolean findReferencedDSEProject() {
for(ITopLevelElement topElement : IPersistencyService.getInstance().getTopLevelElements()) {
if(topElement.getRootModelElement() instanceof FileProject) {
FileProject fp = (FileProject)topElement.getRootModelElement();
if(fp.getName().equals(af3PrjName)) {
matchingAF3Project = fp;
break;
}
}
}
if(matchingAF3Project == null) {
String errMsg = "Could not find a matching AF3 Project with the name " + af3PrjName +
" to load a DSE project.";
error(AF3ExplorationUIActivator.getDefault(), errMsg);
showError(errMsg);
return false;
}
for(DSE dse : pickInstanceOf(DSE.class, matchingAF3Project.getRootElements())) {
if(dse.getName().equals(dsePrjName)) {
matchingDSE = dse;
break;
}
}
if(matchingDSE == null) {
String errMsg = "Could not find a matching DSE project with the name " + dsePrjName +
" in the AF3 project " + af3PrjName + ".";
error(AF3ExplorationUIActivator.getDefault(), errMsg);
showError(errMsg);
return false;
}
return true;
}
/** Loads the DSE perspective. */
private void showDSEPerspective() {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
IPerspectiveDescriptor dsePespective =
wb.getPerspectiveRegistry().findPerspectiveWithId(getFQNID(DSEperspective.class));
activePage.setPerspective(dsePespective);
// The Dashboard view does not open itself, so manually open it here.
try {
activePage.showView(getFQNID(DashboardFXViewPart.class));
} catch(PartInitException e) {
error(AF3ExplorationUIActivator.getDefault(), "Could not open the DSE dashboard.");
}
}
}
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