Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/Messages.java27
-rw-r--r--bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/messages.properties27
-rw-r--r--bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/NewApplicationWizardPage.java88
-rw-r--r--bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/ResourceLocator.java20
-rw-r--r--bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/SimpleTemplate.java13
-rw-r--r--bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/TemplateOperation.java215
6 files changed, 232 insertions, 158 deletions
diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/Messages.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/Messages.java
index 4b568bcb..1c484b1b 100644
--- a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/Messages.java
+++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/Messages.java
@@ -38,6 +38,33 @@ public class Messages extends NLS {
public static String NewAddonClassWizard_NewAddon;
public static String NewAddonClassWizard_NewAddonClass;
public static String NewApplicationModelWizard_IncludeDefaultAddons;
+ public static String NewApplicationWizardPage_AddLifecycleClass;
+ public static String NewApplicationWizardPage_AddOptionCleanPersistedState;
+ public static String NewApplicationWizardPage_ConfigureApplication;
+ public static String NewApplicationWizardPage_CreateSampleContent;
+ public static String NewApplicationWizardPage_CSSStyle;
+ public static String NewApplicationWizardPage_Dots;
+ public static String NewApplicationWizardPage_E4Lifecycle;
+ public static String NewApplicationWizardPage_Eclipse4Application;
+ public static String NewApplicationWizardPage_EnableDevelopmentMode;
+ public static String NewApplicationWizardPage_Height;
+ public static String NewApplicationWizardPage_InputValueEmpty;
+ public static String NewApplicationWizardPage_InputValueError;
+ public static String NewApplicationWizardPage_LifecycleClassName;
+ public static String NewApplicationWizardPage_Name;
+ public static String NewApplicationWizardPage_NewE4ApplicationWizardPage;
+ public static String NewApplicationWizardPage_OnlyNumericValues;
+ public static String NewApplicationWizardPage_PreferenceCustomization;
+ public static String NewApplicationWizardPage_Product;
+ public static String NewApplicationWizardPage_Properties;
+ public static String NewApplicationWizardPage_Property;
+ public static String NewApplicationWizardPage_Rectangle;
+ public static String NewApplicationWizardPage_SetRectangle;
+ public static String NewApplicationWizardPage_TemplateOption;
+ public static String NewApplicationWizardPage_ValueShouldNotBeEmpty;
+ public static String NewApplicationWizardPage_Width;
+ public static String NewApplicationWizardPage_X;
+ public static String NewApplicationWizardPage_Y;
public static String NewDynamicMenuContributionClassWizard_AboutToShowMethod;
public static String NewDynamicMenuContributionClassWizard_CreateNewContribution;
public static String NewDynamicMenuContributionClassWizard_NewDynamicContribution;
diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/messages.properties b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/messages.properties
index 5299e7d2..8a4f5dda 100644
--- a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/messages.properties
+++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/messages.properties
@@ -27,6 +27,33 @@ E4NewProjectWizard_Save=Save
NewAddonClassWizard_NewAddon=New Addon
NewAddonClassWizard_NewAddonClass=Create a new addon class
NewApplicationModelWizard_IncludeDefaultAddons=Include default addons
+NewApplicationWizardPage_AddLifecycleClass=Add a lifecycle class
+NewApplicationWizardPage_AddOptionCleanPersistedState=Add option -clearPersistedState to the Product's Program Arguments
+NewApplicationWizardPage_ConfigureApplication=Configure application with special values.
+NewApplicationWizardPage_CreateSampleContent=Create sample content (parts, menu etc.)
+NewApplicationWizardPage_CSSStyle=CSS Style:
+NewApplicationWizardPage_Dots=...
+NewApplicationWizardPage_E4Lifecycle=E4LifeCycle
+NewApplicationWizardPage_Eclipse4Application=Eclipse 4 Application
+NewApplicationWizardPage_EnableDevelopmentMode=Enable development mode for application model
+NewApplicationWizardPage_Height=Height:
+NewApplicationWizardPage_InputValueEmpty=Input value empty
+NewApplicationWizardPage_InputValueError=Input value error
+NewApplicationWizardPage_LifecycleClassName=LifeCycle class name:
+NewApplicationWizardPage_Name=Name:*
+NewApplicationWizardPage_NewE4ApplicationWizardPage=New Eclipse 4 Application Wizard Page
+NewApplicationWizardPage_OnlyNumericValues=Only numeric is allowed\!
+NewApplicationWizardPage_PreferenceCustomization=Preference Customization:
+NewApplicationWizardPage_Product=Product
+NewApplicationWizardPage_Properties=Properties
+NewApplicationWizardPage_Property=Property "
+NewApplicationWizardPage_Rectangle=Rect
+NewApplicationWizardPage_SetRectangle=Set Rect
+NewApplicationWizardPage_TemplateOption=Template option
+NewApplicationWizardPage_ValueShouldNotBeEmpty=Value shoud not be empty\!
+NewApplicationWizardPage_Width=Width:
+NewApplicationWizardPage_X=X:
+NewApplicationWizardPage_Y=Y:
NewDynamicMenuContributionClassWizard_AboutToShowMethod=AboutToShow Method
NewDynamicMenuContributionClassWizard_CreateNewContribution=Create a new dynamic menu contribution class
NewDynamicMenuContributionClassWizard_NewDynamicContribution=New Dynamic Menu Contribution
diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/NewApplicationWizardPage.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/NewApplicationWizardPage.java
index dfe2e28d..fe9d24e5 100644
--- a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/NewApplicationWizardPage.java
+++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/NewApplicationWizardPage.java
@@ -18,6 +18,7 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IProject;
+import org.eclipse.e4.internal.tools.Messages;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -53,6 +54,9 @@ import org.eclipse.ui.branding.IProductConstants;
* @author jin.liu (jin.liu@soyatec.com)
*/
public class NewApplicationWizardPage extends WizardPage {
+ private static final String TRUE = "TRUE"; //$NON-NLS-1$
+ private static final String TRUESMALL = "true"; //$NON-NLS-1$
+ private static final String FALSE = "FALSE"; //$NON-NLS-1$
public static final String E4_APPLICATION = "org.eclipse.e4.ui.workbench.swt.E4Application"; //$NON-NLS-1$
public static final String APPLICATION_CSS_PROPERTY = "applicationCSS"; //$NON-NLS-1$
public static final String LIFECYCLE_URI_PROPERTY = "lifeCycleURI"; //$NON-NLS-1$
@@ -79,13 +83,13 @@ public class NewApplicationWizardPage extends WizardPage {
protected NewApplicationWizardPage(IProjectProvider projectProvider,
AbstractFieldData pluginData) {
- super("New Eclipse 4 Application Wizard Page");
+ super(Messages.NewApplicationWizardPage_NewE4ApplicationWizardPage);
this.projectProvider = projectProvider;
this.pluginData = pluginData;
data = new HashMap<String, String>();
- data.put(richSample, "FALSE");// minimalist by default
- setTitle("Eclipse 4 Application");
- setMessage("Configure application with special values.");
+ data.put(richSample, FALSE);// minimalist by default
+ setTitle(Messages.NewApplicationWizardPage_Eclipse4Application);
+ setMessage(Messages.NewApplicationWizardPage_ConfigureApplication);
}
public IProject getProject() {
@@ -124,7 +128,7 @@ public class NewApplicationWizardPage extends WizardPage {
private Group createTemplateGroup(Composite parent) {
final Group group = new Group(parent, SWT.NONE);
group.setLayout(new GridLayout(3, false));
- group.setText("Template option");
+ group.setText(Messages.NewApplicationWizardPage_TemplateOption);
richSampleCheckbox = new Button(group, SWT.CHECK);
@@ -132,10 +136,10 @@ public class NewApplicationWizardPage extends WizardPage {
richSampleCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- data.put(richSample, richSampleCheckbox.getSelection() ? "TRUE" : "FALSE");
+ data.put(richSample, richSampleCheckbox.getSelection() ? TRUE : FALSE);
}
});
- richSampleCheckbox.setText("Create sample content (parts, menu etc.)");
+ richSampleCheckbox.setText(Messages.NewApplicationWizardPage_CreateSampleContent);
richSampleCheckbox.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, false, false, 2, 1));
{
@@ -143,26 +147,26 @@ public class NewApplicationWizardPage extends WizardPage {
@Override
public void widgetSelected(SelectionEvent e) {
lifeCycleName.setEnabled(generateLifecycleClassCheckbox.getSelection());
- data.put(generateLifecycle, generateLifecycleClassCheckbox.getSelection() ? "TRUE" : "FALSE");
+ data.put(generateLifecycle, generateLifecycleClassCheckbox.getSelection() ? TRUE : FALSE);
}
};
generateLifecycleClassCheckbox = new Button(group, SWT.CHECK);
generateLifecycleClassCheckbox.setSelection(false);
- generateLifecycleClassCheckbox.setText("Add a lifecycle class");
+ generateLifecycleClassCheckbox.setText(Messages.NewApplicationWizardPage_AddLifecycleClass);
generateLifecycleClassCheckbox.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, false, false, 2, 1));
generateLifecycleClassCheckbox.addSelectionListener(listener);
new Label(group, SWT.NONE);
final Label lbl = new Label(group, SWT.NONE);
- lbl.setText("LifeCycle class name:");
+ lbl.setText(Messages.NewApplicationWizardPage_LifecycleClassName);
final GridData gd = new GridData();
gd.horizontalIndent = 20;
lbl.setLayoutData(gd);
lifeCycleName = new Text(group, SWT.BORDER);
- lifeCycleName.setText("E4LifeCycle");
+ lifeCycleName.setText(Messages.NewApplicationWizardPage_E4Lifecycle);
lifeCycleName.setEnabled(false);
lifeCycleName.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
lifeCycleName.addModifyListener(new ModifyListener() {
@@ -233,7 +237,7 @@ public class NewApplicationWizardPage extends WizardPage {
private Group createPropertyGroup(Composite control) {
final Group group = new Group(control, SWT.NONE);
- group.setText("Properties");
+ group.setText(Messages.NewApplicationWizardPage_Properties);
group.setLayout(new GridLayout(3, false));
@@ -245,7 +249,7 @@ public class NewApplicationWizardPage extends WizardPage {
if (property.getType() == Boolean.class) {
final Button button = new Button(parent, SWT.CHECK);
- button.setSelection("true".equalsIgnoreCase(property.getValue()));
+ button.setSelection(TRUESMALL.equalsIgnoreCase(property.getValue()));
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@@ -274,7 +278,7 @@ public class NewApplicationWizardPage extends WizardPage {
if (property.getType() == Color.class
|| property.getType() == Rectangle.class) {
final Button button = new Button(parent, SWT.PUSH);
- button.setText("...");
+ button.setText(Messages.NewApplicationWizardPage_Dots);
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@@ -293,7 +297,7 @@ public class NewApplicationWizardPage extends WizardPage {
final Label label = new Label(parent, SWT.NONE);
label.setText(property.getLabel());
label.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
- label.setToolTipText("Property \"" + property.getName() + "\"");
+ label.setToolTipText(Messages.NewApplicationWizardPage_Property + property.getName() + "\""); //$NON-NLS-1$
if (property.getExtraTooltipInfo() != null) {
label.setToolTipText(label.getToolTipText() + EOL
+ property.getExtraTooltipInfo());
@@ -323,12 +327,12 @@ public class NewApplicationWizardPage extends WizardPage {
/**
* exchange the color pattern of hex numeric
*
- * @param number
+ * @param color
* @return
*/
public String hexColorConvert(String color) {
if (color.length() == 1) {
- return "0" + color;
+ return "0" + color; //$NON-NLS-1$
}
return color;
}
@@ -354,29 +358,29 @@ public class NewApplicationWizardPage extends WizardPage {
protected Control createDialogArea(final Composite parent) {
final Composite composite = (Composite) super
.createDialogArea(parent);
- composite.getShell().setText("Set Rect");
+ composite.getShell().setText(Messages.NewApplicationWizardPage_SetRectangle);
final Group group = new Group(composite, SWT.NONE);
- group.setText("Rect");
+ group.setText(Messages.NewApplicationWizardPage_Rectangle);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 4;
group.setLayout(gridLayout);
final Label xPointLabel = new Label(group, SWT.NONE);
- xPointLabel.setText("X:");
+ xPointLabel.setText(Messages.NewApplicationWizardPage_X);
xPointText = new Text(group, SWT.BORDER);
final VerifyListener verifyListener = createVerifyListener(parent
.getShell());
xPointText.addVerifyListener(verifyListener);
final Label yPointLabel = new Label(group, SWT.NONE);
- yPointLabel.setText("Y:");
+ yPointLabel.setText(Messages.NewApplicationWizardPage_Y);
yPointText = new Text(group, SWT.BORDER);
yPointText.addVerifyListener(verifyListener);
final Label widthLabel = new Label(group, SWT.NONE);
- widthLabel.setText("Width:");
+ widthLabel.setText(Messages.NewApplicationWizardPage_Width);
widthText = new Text(group, SWT.BORDER);
widthText.addVerifyListener(verifyListener);
final Label heighttLabel = new Label(group, SWT.NONE);
- heighttLabel.setText("Height:");
+ heighttLabel.setText(Messages.NewApplicationWizardPage_Height);
heightText = new Text(group, SWT.BORDER);
heightText.addVerifyListener(verifyListener);
@@ -393,11 +397,11 @@ public class NewApplicationWizardPage extends WizardPage {
if (xPoint.length() == 0 || yPoint.length() == 0
|| width.length() == 0 || height.length() == 0) {
MessageDialog.openWarning(parent.getShell(),
- "Input value empty",
- "Value shoud not be empty!");
+ Messages.NewApplicationWizardPage_InputValueEmpty,
+ Messages.NewApplicationWizardPage_ValueShouldNotBeEmpty);
} else {
- valueText.setText(xPoint + "," + yPoint + "," + width
- + "," + height);
+ valueText.setText(xPoint + "," + yPoint + "," + width //$NON-NLS-1$ //$NON-NLS-2$
+ + "," + height); //$NON-NLS-1$
okPressed();
}
} else if (IDialogConstants.CANCEL_ID == buttonId) {
@@ -418,10 +422,10 @@ public class NewApplicationWizardPage extends WizardPage {
@Override
public void verifyText(VerifyEvent e) {
final char c = e.character;
- if ("0123456789".indexOf(c) == -1) {
+ if ("0123456789".indexOf(c) == -1) { //$NON-NLS-1$
e.doit = false;
- MessageDialog.openWarning(shell, "Input value error",
- "Only numeric is allowed!");
+ MessageDialog.openWarning(shell, Messages.NewApplicationWizardPage_InputValueError,
+ Messages.NewApplicationWizardPage_OnlyNumericValues);
return;
}
}
@@ -433,7 +437,7 @@ public class NewApplicationWizardPage extends WizardPage {
return;
}
String value = valueText.getText();
- if (value.equals("")) {
+ if (value.equals("")) { //$NON-NLS-1$
value = null;
}
data.put(property, value);
@@ -448,12 +452,12 @@ public class NewApplicationWizardPage extends WizardPage {
private Group createProductGroup(Composite control) {
final Group proGroup = new Group(control, SWT.NONE);
- proGroup.setText("Product");
+ proGroup.setText(Messages.NewApplicationWizardPage_Product);
proGroup.setLayout(new GridLayout(2, false));
final Label proNameLabel = new Label(proGroup, SWT.NONE);
- proNameLabel.setText("Name:*");
+ proNameLabel.setText(Messages.NewApplicationWizardPage_Name);
proNameText = new Text(proGroup, SWT.BORDER);
proNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
@@ -470,15 +474,15 @@ public class NewApplicationWizardPage extends WizardPage {
protected PropertyData[] getPropertyData() {
if (PROPERTIES == null) {
PROPERTIES = new PropertyData[] {
- new PropertyData(APPLICATION_CSS_PROPERTY, "CSS Style:",
- "css/default.css", String.class, true),
- new PropertyData(
- IProductConstants.PREFERENCE_CUSTOMIZATION,
- "Preference Customization:", "", String.class, true),
- new PropertyData(CLEAR_PERSISTED_STATE,
- "Enable development mode for application model",
- "true", Boolean.class, true,
- "Add option -clearPersistedState to the Product's Program Arguments") }; // plugin_customization.ini
+ new PropertyData(APPLICATION_CSS_PROPERTY, Messages.NewApplicationWizardPage_CSSStyle,
+ "css/default.css", String.class, true), //$NON-NLS-1$
+ new PropertyData(
+ IProductConstants.PREFERENCE_CUSTOMIZATION,
+ Messages.NewApplicationWizardPage_PreferenceCustomization, "", String.class, true), //$NON-NLS-1$
+ new PropertyData(CLEAR_PERSISTED_STATE,
+ Messages.NewApplicationWizardPage_EnableDevelopmentMode,
+ TRUESMALL, Boolean.class, true,
+ Messages.NewApplicationWizardPage_AddOptionCleanPersistedState) }; // plugin_customization.ini
}
return PROPERTIES;
}
diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/ResourceLocator.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/ResourceLocator.java
index 1e2c5e29..ecb0627c 100644
--- a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/ResourceLocator.java
+++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/ResourceLocator.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Soyatec - initial API and implementation
+ * Soyatec - initial API and implementation
*******************************************************************************/
package org.eclipse.e4.internal.tools.wizards.project;
@@ -18,7 +18,7 @@ import org.eclipse.core.runtime.Plugin;
import org.eclipse.e4.internal.tools.ToolsPlugin;
public class ResourceLocator {
- private static final String TEMPLATE_FOLDER = "templates";
+ private static final String TEMPLATE_FOLDER = "templates"; //$NON-NLS-1$
private static ResourceLocator instance = new ResourceLocator();
@@ -30,19 +30,19 @@ public class ResourceLocator {
}
public static URL getProjectTemplateFiles(String folder)
- throws IOException {
- Plugin plugin = getResorucePlugin();
- URL installURL = plugin.getBundle().getEntry(
- "/" + TEMPLATE_FOLDER + "/" + folder);
+ throws IOException {
+ final Plugin plugin = getResorucePlugin();
+ final URL installURL = plugin.getBundle().getEntry(
+ "/" + TEMPLATE_FOLDER + "/" + folder); //$NON-NLS-1$ //$NON-NLS-2$
// FileLocator.toFileURL(installURL);
- URL corePath = FileLocator.resolve(installURL);
+ final URL corePath = FileLocator.resolve(installURL);
return corePath;
}
public static URL getFile(String relativePath) throws IOException {
- Plugin plugin = getResorucePlugin();
- URL installURL = plugin.getBundle().getEntry(relativePath);
- URL corePath = FileLocator.resolve(installURL);
+ final Plugin plugin = getResorucePlugin();
+ final URL installURL = plugin.getBundle().getEntry(relativePath);
+ final URL corePath = FileLocator.resolve(installURL);
return corePath;
}
diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/SimpleTemplate.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/SimpleTemplate.java
index d13efba8..57a52b6e 100644
--- a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/SimpleTemplate.java
+++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/SimpleTemplate.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Steven Spungin <steven@spungin.tv> - initial API and implementation
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation
*******************************************************************************/
package org.eclipse.e4.internal.tools.wizards.project;
@@ -15,19 +15,20 @@ import java.util.Map;
/**
* A <em>very</em> basic template processor.<br />
* Any value between pairs of @@ will be substituted by the value in a map.<br />
- * Any values not in the map will be replaced by an empty string.
- * <br /> <br />
+ * Any values not in the map will be replaced by an empty string. <br />
+ * <br />
* Behavior is undefined if keys or values contain the @@ marker.
+ *
* @author Steven Spungin
*
*/
public class SimpleTemplate {
public static String process(String source, Map<String, String> substitutionMap) {
- for (String key : substitutionMap.keySet()) {
- source = source.replaceAll("@@" + key + "@@", substitutionMap.get(key));
+ for (final String key : substitutionMap.keySet()) {
+ source = source.replaceAll("@@" + key + "@@", substitutionMap.get(key)); //$NON-NLS-1$ //$NON-NLS-2$
}
- source = source.replaceAll("@@.*?@@", "");
+ source = source.replaceAll("@@.*?@@", ""); //$NON-NLS-1$ //$NON-NLS-2$
return source;
}
}
diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/TemplateOperation.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/TemplateOperation.java
index ce2c7f49..69558522 100644
--- a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/TemplateOperation.java
+++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/project/TemplateOperation.java
@@ -4,10 +4,10 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
- * Soyatec - initial API and implementation
- * Sopot Cela - ongoing enhancements
+ * Soyatec - initial API and implementation
+ * Sopot Cela - ongoing enhancements
*******************************************************************************/
package org.eclipse.e4.internal.tools.wizards.project;
@@ -42,109 +42,116 @@ import org.eclipse.pde.ui.templates.IVariableProvider;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
public class TemplateOperation extends WorkspaceModifyOperation implements
- IVariableProvider {
+IVariableProvider {
private final URL templateDirectory;
private final IContainer target;
private final Map<String, String> keys;
private final Set<String> binaryExtentions;
- private boolean isMinimalist;
+ private final boolean isMinimalist;
public TemplateOperation(URL source, IContainer target,
- Map<String, String> keys, Set<String> binaryExtentions, boolean justProduct) {
+ Map<String, String> keys, Set<String> binaryExtentions, boolean justProduct) {
templateDirectory = source;
this.binaryExtentions = binaryExtentions;
this.target = target;
this.keys = keys;
- this.isMinimalist = justProduct;
+ isMinimalist = justProduct;
}
@Override
protected void execute(IProgressMonitor monitor) throws CoreException,
- InvocationTargetException, InterruptedException {
+ InvocationTargetException, InterruptedException {
monitor.setTaskName(PDEUIMessages.AbstractTemplateSection_generating);
if ("jar".equals(templateDirectory.getProtocol())) { //$NON-NLS-1$
- String file = templateDirectory.getFile();
- int exclamation = file.indexOf('!');
- if (exclamation < 0)
+ final String file = templateDirectory.getFile();
+ final int exclamation = file.indexOf('!');
+ if (exclamation < 0) {
return;
+ }
URL fileUrl = null;
try {
fileUrl = new URL(file.substring(0, exclamation));
- } catch (MalformedURLException mue) {
+ } catch (final MalformedURLException mue) {
ToolsPlugin.logError(mue);
return;
}
- File pluginJar = new File(fileUrl.getFile());
- if (!pluginJar.exists())
+ final File pluginJar = new File(fileUrl.getFile());
+ if (!pluginJar.exists()) {
return;
- String templateDirectory = file.substring(exclamation + 1); // "/some/path/"
- IPath path = new Path(templateDirectory);
+ }
+ final String templateDirectory = file.substring(exclamation + 1); // "/some/path/"
+ final IPath path = new Path(templateDirectory);
ZipFile zipFile = null;
try {
zipFile = new ZipFile(pluginJar);
generateFiles(zipFile, path, target, monitor);
- } catch (ZipException ze) {
- } catch (IOException ioe) {
+ } catch (final ZipException ze) {
+ } catch (final IOException ioe) {
} finally {
if (zipFile != null) {
try {
zipFile.close();
- } catch (IOException e) {
+ } catch (final IOException e) {
}
}
}
} else if ("file".equals(templateDirectory.getProtocol())) { //$NON-NLS-1$
- File directory = new File(templateDirectory.getFile());
- if (!directory.exists())
+ final File directory = new File(templateDirectory.getFile());
+ if (!directory.exists()) {
return;
+ }
generateFiles(directory, target, true, monitor);
}
}
private void generateFiles(File src, IContainer dst, boolean firstLevel,
- IProgressMonitor monitor) throws CoreException {
- if ((!firstLevel)&&(isMinimalist))
- return;
- File[] members = src.listFiles();
+ IProgressMonitor monitor) throws CoreException {
+ if (!firstLevel && isMinimalist) {
+ return;
+ }
+ final File[] members = src.listFiles();
for (int i = 0; i < members.length; i++) {
- File member = members[i];
- String name = member.getName();
+ final File member = members[i];
+ final String name = member.getName();
if (member.isDirectory()) {
- if (".svn".equals(name) || "cvs".equalsIgnoreCase(name))
+ if (".svn".equals(name) || "cvs".equalsIgnoreCase(name)) { //$NON-NLS-1$ //$NON-NLS-2$
continue;
+ }
IContainer dstContainer = null;
if (dstContainer == null) {
- String folderName = getProcessedString(name, name);
+ final String folderName = getProcessedString(name, name);
dstContainer = dst.getFolder(new Path(folderName));
}
- if (dstContainer != null && !dstContainer.exists())
+ if (dstContainer != null && !dstContainer.exists()) {
((IFolder) dstContainer).create(true, true, monitor);
-
+ }
+
generateFiles(member, dstContainer, false, monitor);
} else {
InputStream in = null;
try {
in = new FileInputStream(member);
copyFile(name, in, dst, monitor);
- } catch (IOException ioe) {
+ } catch (final IOException ioe) {
} finally {
- if (in != null)
+ if (in != null) {
try {
in.close();
- } catch (IOException ioe2) {
+ } catch (final IOException ioe2) {
}
+ }
}
}
}
}
/**
- *
- *
+ *
+ *
* @param zipFile
* @param path
* @param dst
@@ -152,15 +159,15 @@ public class TemplateOperation extends WorkspaceModifyOperation implements
* @throws CoreException
*/
private void generateFiles(ZipFile zipFile, IPath path, IContainer dst,
- IProgressMonitor monitor) throws CoreException {
- int pathLength = path.segmentCount();
+ IProgressMonitor monitor) throws CoreException {
+ final int pathLength = path.segmentCount();
// Immidiate children
- Map childZipEntries = new HashMap(); // "dir/" or "dir/file.java"
+ final Map childZipEntries = new HashMap(); // "dir/" or "dir/file.java"
- for (Enumeration zipEntries = zipFile.entries(); zipEntries
- .hasMoreElements();) {
- ZipEntry zipEntry = (ZipEntry) zipEntries.nextElement();
- IPath entryPath = new Path(zipEntry.getName());
+ for (final Enumeration zipEntries = zipFile.entries(); zipEntries
+ .hasMoreElements();) {
+ final ZipEntry zipEntry = (ZipEntry) zipEntries.nextElement();
+ final IPath entryPath = new Path(zipEntry.getName());
if (entryPath.segmentCount() <= pathLength) {
// ancestor or current directory
continue;
@@ -172,55 +179,57 @@ public class TemplateOperation extends WorkspaceModifyOperation implements
if (entryPath.segmentCount() == pathLength + 1) {
childZipEntries.put(zipEntry.getName(), zipEntry);
} else {
- String name = entryPath.uptoSegment(pathLength + 1)
- .addTrailingSeparator().toString();
+ final String name = entryPath.uptoSegment(pathLength + 1)
+ .addTrailingSeparator().toString();
if (!childZipEntries.containsKey(name)) {
- ZipEntry dirEntry = new ZipEntry(name);
+ final ZipEntry dirEntry = new ZipEntry(name);
childZipEntries.put(name, dirEntry);
}
}
}
- for (Iterator it = childZipEntries.values().iterator(); it.hasNext();) {
- ZipEntry zipEnry = (ZipEntry) it.next();
- String name = new Path(zipEnry.getName()).lastSegment().toString();
+ for (final Iterator it = childZipEntries.values().iterator(); it.hasNext();) {
+ final ZipEntry zipEnry = (ZipEntry) it.next();
+ final String name = new Path(zipEnry.getName()).lastSegment().toString();
if (zipEnry.isDirectory()) {
IContainer dstContainer = null;
if (dstContainer == null) {
- String folderName = getProcessedString(name, name);
+ final String folderName = getProcessedString(name, name);
dstContainer = dst.getFolder(new Path(folderName));
}
- if (dstContainer != null && !dstContainer.exists())
+ if (dstContainer != null && !dstContainer.exists()) {
((IFolder) dstContainer).create(true, true, monitor);
+ }
generateFiles(zipFile, path.append(name), dstContainer, monitor);
} else {
InputStream in = null;
try {
in = zipFile.getInputStream(zipEnry);
copyFile(name, in, dst, monitor);
- } catch (IOException ioe) {
+ } catch (final IOException ioe) {
} finally {
- if (in != null)
+ if (in != null) {
try {
in.close();
- } catch (IOException ioe2) {
+ } catch (final IOException ioe2) {
}
+ }
}
}
}
}
private void copyFile(String fileName, InputStream input, IContainer dst,
- IProgressMonitor monitor) throws CoreException {
- String targetFileName = getProcessedString(fileName, fileName);
+ IProgressMonitor monitor) throws CoreException {
+ final String targetFileName = getProcessedString(fileName, fileName);
monitor.subTask(targetFileName);
- IFile dstFile = dst.getFile(new Path(targetFileName));
+ final IFile dstFile = dst.getFile(new Path(targetFileName));
try {
- InputStream stream = isBinary(fileName) ? input
- : getProcessedStream(fileName, input);
+ final InputStream stream = isBinary(fileName) ? input
+ : getProcessedStream(fileName, input);
if (dstFile.exists()) {
dstFile.setContents(stream, true, true, monitor);
} else {
@@ -228,12 +237,12 @@ public class TemplateOperation extends WorkspaceModifyOperation implements
}
stream.close();
- } catch (IOException e) {
+ } catch (final IOException e) {
}
}
protected void copyFile(String fileName, InputStream input, IContainer dst,
- final String destPath, IProgressMonitor monitor)
+ final String destPath, IProgressMonitor monitor)
throws CoreException {
String targetFileName = null;
if (destPath == null) {
@@ -243,11 +252,11 @@ public class TemplateOperation extends WorkspaceModifyOperation implements
}
monitor.subTask(targetFileName);
- IFile dstFile = dst.getFile(new Path(targetFileName));
+ final IFile dstFile = dst.getFile(new Path(targetFileName));
try {
- InputStream stream = isBinary(fileName) ? input
- : getProcessedStream(fileName, input);
+ final InputStream stream = isBinary(fileName) ? input
+ : getProcessedStream(fileName, input);
if (dstFile.exists()) {
dstFile.setContents(stream, true, true, monitor);
} else {
@@ -255,12 +264,12 @@ public class TemplateOperation extends WorkspaceModifyOperation implements
}
stream.close();
- } catch (IOException e) {
+ } catch (final IOException e) {
}
}
/**
- *
+ *
* @param fileName
* @param input
* @param dst
@@ -269,21 +278,21 @@ public class TemplateOperation extends WorkspaceModifyOperation implements
* @throws CoreException
*/
public void copyFile(String fileName, InputStream input, IContainer dst,
- final String basePath, final String destName,
- IProgressMonitor monitor) throws CoreException {
- if (basePath == null || basePath.equals("")) {
+ final String basePath, final String destName,
+ IProgressMonitor monitor) throws CoreException {
+ if (basePath == null || basePath.equals("")) { //$NON-NLS-1$
copyFile(fileName, input, dst, monitor);
}
- String targetFileName = destName == null ? getProcessedString(fileName,
- fileName) : destName;
+ final String targetFileName = destName == null ? getProcessedString(fileName,
+ fileName) : destName;
monitor.subTask(targetFileName);
- IFile dstFile = dst.getFile(new Path(basePath + targetFileName));
+ final IFile dstFile = dst.getFile(new Path(basePath + targetFileName));
try {
- InputStream stream = isBinary(fileName) ? input
- : getProcessedStream(fileName, input);
+ final InputStream stream = isBinary(fileName) ? input
+ : getProcessedStream(fileName, input);
if (dstFile.exists()) {
dstFile.setContents(stream, true, true, monitor);
} else {
@@ -291,7 +300,7 @@ public class TemplateOperation extends WorkspaceModifyOperation implements
}
stream.close();
- } catch (IOException e) {
+ } catch (final IOException e) {
}
}
@@ -300,27 +309,29 @@ public class TemplateOperation extends WorkspaceModifyOperation implements
return false;
}
- String ext = getfileExtention(fileName);
- if (ext == null)
+ final String ext = getfileExtention(fileName);
+ if (ext == null) {
return false;
+ }
return binaryExtentions.contains(ext);
}
private String getfileExtention(String name) {
- int indexOf = name.lastIndexOf('.');
- if (indexOf == -1)
+ final int indexOf = name.lastIndexOf('.');
+ if (indexOf == -1) {
return null;
+ }
return name.substring(indexOf);
}
private InputStream getProcessedStream(String fileName, InputStream stream)
- throws IOException, CoreException {
- InputStreamReader reader = new InputStreamReader(stream);
- int bufsize = 1024;
- char[] cbuffer = new char[bufsize];
+ throws IOException, CoreException {
+ final InputStreamReader reader = new InputStreamReader(stream);
+ final int bufsize = 1024;
+ final char[] cbuffer = new char[bufsize];
int read = 0;
- StringBuffer keyBuffer = new StringBuffer();
- StringBuffer outBuffer = new StringBuffer();
+ final StringBuffer keyBuffer = new StringBuffer();
+ final StringBuffer outBuffer = new StringBuffer();
boolean replacementMode = false;
boolean almostReplacementMode = false;
@@ -328,10 +339,10 @@ public class TemplateOperation extends WorkspaceModifyOperation implements
while (read != -1) {
read = reader.read(cbuffer);
for (int i = 0; i < read; i++) {
- char c = cbuffer[i];
+ final char c = cbuffer[i];
if (escape) {
- StringBuffer buf = outBuffer;
+ final StringBuffer buf = outBuffer;
buf.append(c);
escape = false;
continue;
@@ -342,9 +353,9 @@ public class TemplateOperation extends WorkspaceModifyOperation implements
almostReplacementMode = false;
} else if (replacementMode) {
replacementMode = false;
- String key = keyBuffer.toString();
- String value = key.length() == 0 ? "@@" //$NON-NLS-1$
- : getReplacementString(key);
+ final String key = keyBuffer.toString();
+ final String value = key.length() == 0 ? "@@" //$NON-NLS-1$
+ : getReplacementString(key);
outBuffer.append(value);
keyBuffer.delete(0, keyBuffer.length());
} else if (almostReplacementMode) {
@@ -353,11 +364,12 @@ public class TemplateOperation extends WorkspaceModifyOperation implements
almostReplacementMode = true;
}
} else {
- if (replacementMode)
+ if (replacementMode) {
keyBuffer.append(c);
- else {
- if (almostReplacementMode)
+ } else {
+ if (almostReplacementMode) {
outBuffer.append('@');
+ }
outBuffer.append(c);
almostReplacementMode = false;
}
@@ -371,17 +383,18 @@ public class TemplateOperation extends WorkspaceModifyOperation implements
}
private String getProcessedString(String fileName, String source) {
- if (source.indexOf('$') == -1)
+ if (source.indexOf('$') == -1) {
return source;
+ }
int loc = -1;
- StringBuffer buffer = new StringBuffer();
+ final StringBuffer buffer = new StringBuffer();
boolean replacementMode = false;
for (int i = 0; i < source.length(); i++) {
- char c = source.charAt(i);
+ final char c = source.charAt(i);
if (c == '$') {
if (replacementMode) {
- String key = source.substring(loc, i);
- String value = key.length() == 0 ? "$" : getReplacementString(key); //$NON-NLS-1$
+ final String key = source.substring(loc, i);
+ final String value = key.length() == 0 ? "$" : getReplacementString(key); //$NON-NLS-1$
buffer.append(value);
replacementMode = false;
} else {
@@ -389,17 +402,19 @@ public class TemplateOperation extends WorkspaceModifyOperation implements
loc = i + 1;
continue;
}
- } else if (!replacementMode)
+ } else if (!replacementMode) {
buffer.append(c);
+ }
}
return buffer.toString();
}
public String getReplacementString(String key) {
- String result = keys.get(key);
+ final String result = keys.get(key);
return result != null ? result : key;
}
+ @Override
public Object getValue(String variable) {
return getReplacementString(variable);
}

Back to the top