Commit 62000d16 authored by Jay Jay Billings's avatar Jay Jay Billings
Browse files

Merge branch 'jay/projectSupport' of https://github.com/eclipse/ice into jay/projectSupport

parents 4fcce4e6 114f8c97
......@@ -41,7 +41,6 @@ public class ICEItemTemplate extends OptionTemplateSection {
protected static final String EXTENSION_POINT = "org.eclipse.ice.item.itemBuilder";
protected static final String KEY_CLASS_NAME = "className";
protected static final String KEY_EXTENSION_NAME = "extensionName";
protected static final String KEY_PACKAGE_NAME = "packageName";
/**
* Constructor
......@@ -51,6 +50,7 @@ public class ICEItemTemplate extends OptionTemplateSection {
setOptions();
}
/**
* Add pages to the wizard
*/
......@@ -67,8 +67,6 @@ public class ICEItemTemplate extends OptionTemplateSection {
* Define the options, descriptions, default values, and page numbers
*/
protected void setOptions() {
addOption(KEY_EXTENSION_NAME , "Extension Base Name" , "" , 0);
addOption(KEY_PACKAGE_NAME , "Package Name" , "" , 0);
addOption(KEY_CLASS_NAME , "Class Base Name" , "" , 0);
}
......@@ -116,13 +114,14 @@ public class ICEItemTemplate extends OptionTemplateSection {
protected void updateModel(IProgressMonitor monitor) throws CoreException {
// Model builder plugin.xml entry
IPluginBase plugin = model.getPluginBase();
String pluginId = plugin.getId();
IPluginExtension extension = createExtension(EXTENSION_POINT, false);
extension.setName(splitCamelCase(getStringOption(KEY_EXTENSION_NAME) + " Model"));
extension.setId(getStringOption(KEY_EXTENSION_NAME).toLowerCase() + "ModelBuilder");
extension.setName(splitCamelCase(getStringOption(KEY_CLASS_NAME) + " Model"));
extension.setId(getStringOption(KEY_CLASS_NAME) + "ModelBuilder");
IPluginModelFactory factory = model.getPluginFactory();
IPluginElement element = factory.createElement(extension);
element.setName("implementation");
element.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_CLASS_NAME) + "ModelBuilder");
element.setAttribute("class", pluginId + "." + getStringOption(KEY_CLASS_NAME) + "ModelBuilder");
extension.add(element);
if (!extension.isInTheModel())
plugin.add(extension);
......@@ -130,12 +129,12 @@ public class ICEItemTemplate extends OptionTemplateSection {
// Job launcher builder plugin.xml entry
plugin = model.getPluginBase();
extension = createExtension(EXTENSION_POINT, false);
extension.setName(splitCamelCase(getStringOption(KEY_EXTENSION_NAME) + " Launcher"));
extension.setId(getStringOption(KEY_EXTENSION_NAME).toLowerCase() + "LauncherBuilder");
extension.setName(splitCamelCase(getStringOption(KEY_CLASS_NAME)+ " Launcher"));
extension.setId(getStringOption(KEY_CLASS_NAME) + "LauncherBuilder");
factory = model.getPluginFactory();
element = factory.createElement(extension);
element.setName("implementation");
element.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_CLASS_NAME) + "LauncherBuilder");
element.setAttribute("class", pluginId + "." + getStringOption(KEY_CLASS_NAME) + "LauncherBuilder");
extension.add(element);
if (!extension.isInTheModel())
plugin.add(extension);
......
......@@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.ice.projectgeneration.templates;
import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
import org.eclipse.pde.ui.IFieldData;
import org.eclipse.pde.ui.templates.ITemplateSection;
import org.eclipse.pde.ui.templates.NewPluginTemplateWizard;
......@@ -27,10 +28,8 @@ public class ICEItemWizard extends NewPluginTemplateWizard {
super();
}
@Override
public void init(IFieldData data) {
super.init(data);
setWindowTitle("New ICE Item Parameters");
}
@Override
......
......@@ -12,11 +12,16 @@
*******************************************************************************/
package org.eclipse.ice.projectgeneration.wizards;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import static java.nio.file.StandardCopyOption.*;
import java.util.Arrays;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
......@@ -47,6 +52,7 @@ import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
import org.eclipse.ice.projectgeneration.ICEItemNature;
import org.eclipse.ice.projectgeneration.templates.ICEItemWizard;
/**
* This class defines the steps for creating a new New ICE Item project via the
......@@ -62,14 +68,14 @@ public class NewICEItemProjectWizard extends NewPluginProjectFromTemplateWizard
private static final String WIZARD_NAME = "New ICE Item Project";
private static final String WIZARD_TITLE = "Create a new ICE item project";
private static final String TEMPLATE_ID = "org.eclipse.ice.projectgeneration.pluginContent.ICEItem";
private AbstractFieldData fPluginData;
private NewProjectCreationPage fProjectPage;
private PluginContentPage fContentPage;
private IPluginContentWizard fTemplateWizard;
private ICEItemWizard fTemplateWizard;
private IProjectProvider fProjectProvider;
private IConfigurationElement fConfig;
private IStructuredSelection selection;
private IWorkbench workbench;
......@@ -82,15 +88,15 @@ public class NewICEItemProjectWizard extends NewPluginProjectFromTemplateWizard
setWindowTitle(WIZARD_TITLE);
}
/**
* Creates and adds the pages to the wizard. Three pages are created.
* Creates and adds the pages to the wizard. Three pages are created.
*/
@Override
public void addPages() {
WizardElement templateWizardElement = getTemplateWizard();
fProjectPage = new NewProjectCreationFromTemplatePage("main", fPluginData, getSelection(), templateWizardElement); //$NON-NLS-1$
fProjectPage = new NewProjectCreationFromTemplatePage("main", fPluginData, getSelection(), //$NON-NLS-1$
templateWizardElement);
fProjectPage.setTitle(WIZARD_TITLE);
fProjectPage.setDescription(DESCRIPTION);
......@@ -103,9 +109,11 @@ public class NewICEItemProjectWizard extends NewPluginProjectFromTemplateWizard
public String getProjectName() {
return fProjectPage.getProjectName();
}
public IProject getProject() {
return fProjectPage.getProjectHandle();
}
public IPath getLocationPath() {
return fProjectPage.getLocationPath();
}
......@@ -113,9 +121,8 @@ public class NewICEItemProjectWizard extends NewPluginProjectFromTemplateWizard
fContentPage = new PluginContentPage("page2", fProjectProvider, fProjectPage, fPluginData); //$NON-NLS-1$
addPage(fContentPage);
try {
fTemplateWizard = (IPluginContentWizard) templateWizardElement.createExecutableExtension();
fTemplateWizard = (ICEItemWizard) templateWizardElement.createExecutableExtension();
fTemplateWizard.init(fPluginData);
fTemplateWizard.addPages();
IWizardPage[] pages = fTemplateWizard.getPages();
......@@ -127,7 +134,6 @@ public class NewICEItemProjectWizard extends NewPluginProjectFromTemplateWizard
}
}
/**
* Takes all of the information from the wizard pages and uses it to create
* the plugin and java classes.
......@@ -136,6 +142,7 @@ public class NewICEItemProjectWizard extends NewPluginProjectFromTemplateWizard
*/
@Override
public boolean performFinish() {
boolean successful = false;
try {
fProjectPage.updateData();
fContentPage.updateData();
......@@ -146,11 +153,13 @@ public class NewICEItemProjectWizard extends NewPluginProjectFromTemplateWizard
}
BasicNewProjectResourceWizard.updatePerspective(fConfig);
// If the PDE models are not initialized, initialize with option to cancel
// If the PDE models are not initialized, initialize with option to
// cancel
if (!PDECore.getDefault().areModelsInitialized()) {
try {
getContainer().run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
PDECore.getDefault().getModelManager().targetReloaded(monitor);
if (monitor.isCanceled()) {
throw new InterruptedException();
......@@ -158,27 +167,31 @@ public class NewICEItemProjectWizard extends NewPluginProjectFromTemplateWizard
}
});
} catch (InterruptedException e) {
return false;
e.printStackTrace();
}
}
getContainer().run(false, true, new NewProjectCreationOperation(fPluginData, fProjectProvider, fTemplateWizard));
getContainer().run(false, true,
new NewProjectCreationOperation(fPluginData, fProjectProvider, fTemplateWizard));
IWorkingSet[] workingSets = fProjectPage.getSelectedWorkingSets();
if (workingSets.length > 0)
getWorkbench().getWorkingSetManager().addToWorkingSets(fProjectProvider.getProject(), workingSets);
setNature(fProjectProvider.getProject());
return true;
setPackageLayout();
successful = true;
} catch (InvocationTargetException e) {
PDEPlugin.logException(e);
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (CoreException e) {
e.printStackTrace();
}
return false;
return successful;
}
/**
* Make sure that the project has the ICEItemNature associated with it.
*
......@@ -195,16 +208,16 @@ public class NewICEItemProjectWizard extends NewPluginProjectFromTemplateWizard
}
}
/**
* Creates a new wizard element for the definition of the java code templates
* Creates a new wizard element for the definition of the java code
* templates
*
* @return the wizard element corresponding to the project's template
*/
private WizardElement getTemplateWizard() {
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint point = registry.getExtensionPoint("org.eclipse.ice.projectgeneration", PLUGIN_POINT);
if (point == null)
if (point == null)
return null;
IExtension[] extensions = point.getExtensions();
for (int i = 0; i < extensions.length; i++) {
......@@ -220,6 +233,34 @@ public class NewICEItemProjectWizard extends NewPluginProjectFromTemplateWizard
return null;
}
/**
* Sets the package layout to be as specified in the wizard.
*/
private void setPackageLayout() {
String sep = System.getProperty("file.separator");
String[] packageHierarchy = fProjectProvider.getProjectName().split("\\.");
String projectSrcPath = fProjectProvider.getLocationPath().makeAbsolute().toOSString() + sep
+ fProjectProvider.getProjectName() + sep + fPluginData.getSourceFolderName();
File[] projectSrcs = new File(projectSrcPath).listFiles();
File modelDir = new File(projectSrcPath + sep + String.join(sep, packageHierarchy) + sep + "model");
File launcherDir = new File(projectSrcPath + sep + String.join(sep, packageHierarchy) + sep + "launcher");
try {
modelDir.mkdirs();
launcherDir.mkdirs();
for (File f : projectSrcs) {
if (f.getName().endsWith("Launcher.java") || f.getName().endsWith("LauncherBuilder.java")) {
Files.move(f.toPath(), (new File(launcherDir.getAbsolutePath() + sep + f.getName())).toPath(), REPLACE_EXISTING);
} else if (f.getName().endsWith("Model.java") || f.getName().endsWith("ModelBuilder.java")) {
Files.move(f.toPath(), (new File(modelDir.getAbsolutePath() + sep + f.getName())).toPath(), REPLACE_EXISTING);
}
}
fProjectProvider.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (CoreException ce) {
ce.printStackTrace();
}
}
@Override
protected String getTemplateID() {
......
......@@ -24,7 +24,7 @@ import org.eclipse.ice.datastructures.form.Material;
public class MaterialSelection {
/**
* The mateiral for this selection (the row)
* The material for this selection (the row)
*/
private Material material;
......@@ -81,11 +81,28 @@ public class MaterialSelection {
} else {
MaterialSelection selection = (MaterialSelection) other;
equal = this.material.equals(selection.material)
&& this.selectedProperty
.equals(selection.selectedProperty);
&& this.selectedProperty.equals(selection.selectedProperty);
}
}
return equal;
}
/**
* Returns the hashCode of the object.
*
* @return The hashCode of the Object.
*/
@Override
public int hashCode() {
// Call the super's hashCode.
int hash = super.hashCode();
// Add local hashes.
hash = 31 * hash + material.hashCode();
hash = 31 * hash + selectedProperty.hashCode();
return hash;
}
}
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