Skip to content

Commit

Permalink
Consolidate multiple model projects wizards to single project wizard.
Browse files Browse the repository at this point in the history
Closes eclipse-vorto#65

Signed-off-by: Nagavijay Sivakumar <[email protected]>

Added new Vorto Nature for single model project.

Signed-off-by: Nagavijay Sivakumar <[email protected]>
  • Loading branch information
Nagavijay Sivakumar committed May 6, 2016
1 parent 25c8bdd commit 0c40520
Show file tree
Hide file tree
Showing 16 changed files with 646 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
public class ModelGenerationTask extends
AbstractTemplateGeneratorTask<IModelProjectContext> {

public static final String SRC_MODELS = "src/models/";
private final String suffix;
private final ITemplate<IModelProjectContext> fileTemplate;
private final String modelFolder;

public ModelGenerationTask(String fileSuffix,
ITemplate<IModelProjectContext> template) {
ITemplate<IModelProjectContext> template, String modelFolder) {
suffix = fileSuffix.startsWith(".") ? fileSuffix : "."
.concat(fileSuffix);
fileTemplate = template;
this.modelFolder = modelFolder;
}

@Override
Expand All @@ -39,7 +40,7 @@ public String getFileName(IModelProjectContext ctx) {

@Override
public String getPath(IModelProjectContext ctx) {
return SRC_MODELS;
return modelFolder;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.vorto.core.api.model.model.ModelReference;
import org.eclipse.vorto.core.api.model.model.ModelType;
import org.eclipse.vorto.core.model.nature.InformationModelProjectNature;
import org.eclipse.vorto.core.model.nature.VortoProjectNature;
import org.eclipse.vorto.core.parser.IModelParser;

public class InformationModelProject extends AbstractModelProject {
Expand All @@ -45,7 +46,7 @@ public IFile getModelFile() {

public static boolean isInformationModelProject(IProject project) {
try {
return project.getNature(InformationModelProjectNature.NATURE_ID) != null;
return (project.getNature(InformationModelProjectNature.NATURE_ID) != null || project.getNature(VortoProjectNature.VORTO_NATURE) != null);
} catch (CoreException e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2016 Bosch Software Innovations GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
*******************************************************************************/
package org.eclipse.vorto.core.model.nature;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;

public class VortoProjectNature implements IProjectNature {

public static final String VORTO_NATURE = "org.eclipse.vorto.vortonature";

private IProject project;

@Override
public void configure() throws CoreException {

}

@Override
public void deconfigure() throws CoreException {

}

@Override
public IProject getProject() {
return project;
}

@Override
public void setProject(IProject project) {
this.project = project;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*******************************************************************************
* Copyright (c) 2016 Bosch Software Innovations GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
*******************************************************************************/
package org.eclipse.vorto.wizard;

import java.io.IOException;
import java.util.regex.Pattern;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.vorto.codegen.ui.context.IModelProjectContext;

import com.google.common.base.Strings;

public abstract class AbstractModelWizardPage extends AbstractWizardPage implements
IModelProjectContext {

public static final String PROJECTNAME_REGEX = "[^a-zA-Z0-9 \\._]";
public static final String FUNCTIONBLOCK_REGEX = "[A-Z][a-zA-Z0-9_]*$";
public static final String VERSION_REGEX = "^\\d+\\.\\d+\\.\\d+(-\\w+)*$";

protected AbstractModelWizardPage(String pageName) {
super(pageName);
}

protected boolean checkProjectName(String projectName) {
if (checkForRegexPattern(projectName, true, PROJECTNAME_REGEX)) {
setErrorMessage("Project name should not contain special characters.");
return false;
}
return true;
}

protected boolean checkModelName(String modelName) {
if (checkForRegexPattern(modelName, false, FUNCTIONBLOCK_REGEX)) {
setErrorMessage("Model name should start with a capital letter and must not contain any special characters.");
return false;
}
return true;
}

protected boolean checkFBVersion(String fbVersion) {
if (checkForRegexPattern(fbVersion, false, VERSION_REGEX)) {
setErrorMessage("Version should follow pattern <MAJOR>.<MINOR>.<PATCH>");
return false;
}
return true;
}

protected boolean checkForRegexPattern(String input, boolean expectedBool,
String regexPattern) {
return Pattern.compile(regexPattern).matcher(input).matches() == expectedBool;
}

protected boolean validateStrExist(String string, String errorMsgToBeShown) {
if (Strings.isNullOrEmpty(string)) {
this.setErrorMessage(errorMsgToBeShown);
return false;
}
return true;
}

protected boolean validateExistingSameProjectName(String projectName) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();

if (workspace.getRoot().getProject(getProjectName()).exists()) {
setErrorMessage("Project " + getProjectName() + " already exists.");
return false;
}

IPath projectLocation = ResourcesPlugin.getWorkspace().getRoot()
.getLocation().append(projectName);
if (projectLocation.toFile().exists()) {
try {
String canonicalPath = projectLocation.toFile()
.getCanonicalPath();
projectLocation = new Path(canonicalPath);

String existingName = projectLocation.lastSegment();
if (!existingName.equals(projectName)) {
setErrorMessage("Project " + getProjectName()
+ " already exists.");
return false;
}
} catch (IOException e) {
}

}

return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.vorto.codegen.ui.context.IModelProjectContext;

import com.google.common.base.Strings;

public abstract class AbstractWizardPage extends WizardPage implements
IModelProjectContext {
public abstract class AbstractWizardPage extends WizardPage {

public static final String PROJECTNAME_REGEX = "[^a-zA-Z0-9 \\._]";
public static final String FUNCTIONBLOCK_REGEX = "[A-Z][a-zA-Z0-9_]*$";
Expand All @@ -36,6 +35,14 @@ public abstract class AbstractWizardPage extends WizardPage implements
protected AbstractWizardPage(String pageName) {
super(pageName);
}

protected AbstractWizardPage(String pageName, String title, ImageDescriptor descriptor) {
super(pageName, title, descriptor);
}

protected String getWindowTitle() {
return "";
}

protected boolean checkProjectName(String projectName) {
if (checkForRegexPattern(projectName, true, PROJECTNAME_REGEX)) {
Expand Down Expand Up @@ -104,4 +111,6 @@ protected boolean validateExistingSameProjectName(String projectName) {
return true;
}

protected abstract String getProjectName();

}
Loading

0 comments on commit 0c40520

Please sign in to comment.