Skip to content

Commit

Permalink
Simplify new E4 wizards and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed May 4, 2023
1 parent dabb850 commit 4621352
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.pde.internal.ui.templates.e4;

import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
Expand Down Expand Up @@ -45,8 +46,7 @@ public void init(IFieldData data) {
/** The template must generate an E4 compliant plugin */
protected void setE4Plugin(boolean e4Mode) {
IFieldData data = getData();
if (data instanceof PluginFieldData) {
PluginFieldData pfd = (PluginFieldData) data;
if (data instanceof PluginFieldData pfd) {
pfd.setE4Plugin(e4Mode);
}
}
Expand Down Expand Up @@ -115,13 +115,13 @@ private void openEditorForApplicationModel(IProject project) throws PartInitExce
String filename = getFilenameToEdit();
if (filename != null) {
final IFile file = project.getFile(filename);
if (file != null) {
final FileEditorInput input = new FileEditorInput(file);
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
final IWorkbenchPage page = window.getActivePage();
if (page != null)
page.openEditor(input, MODEL_EDITOR_ID);
}
if (file != null) {
final FileEditorInput input = new FileEditorInput(file);
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
final IWorkbenchPage page = window.getActivePage();
if (page != null)
page.openEditor(input, MODEL_EDITOR_ID);
}
}
}

Expand All @@ -133,5 +133,10 @@ protected String getFilenameToEdit() {
return null;
}

static IPluginReference[] createPluginReferences(List<String> requiredBundles) {
return requiredBundles.stream()//
.map(bsn -> new PluginReference(bsn, null, IMatchRules.GREATER_OR_EQUAL))
.toArray(IPluginReference[]::new);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
*******************************************************************************/
package org.eclipse.pde.internal.ui.templates.e4;

import java.util.List;
import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
import org.eclipse.pde.ui.IFieldData;
import org.eclipse.pde.ui.templates.ITemplateSection;

public class E4ApplicationNewWizard extends AbstractE4NewPluginTemplateWizard {

private static final List<String> PACKAGE_IMPORTS = List.of( //
"javax.annotation;version=\"0.0.0\""); //$NON-NLS-1$

@Override
public void init(IFieldData data) {
super.init(data);
Expand All @@ -27,16 +31,17 @@ public void init(IFieldData data) {

@Override
public ITemplateSection[] createTemplateSections() {
return new ITemplateSection[] {new E4ApplicationTemplate()};
return new ITemplateSection[] { new E4ApplicationTemplate() };
}

@Override
protected String getFilenameToEdit() {
return E4ApplicationTemplate.E4_MODEL_FILE;
}

@Override
public String[] getImportPackages() {
return new String[] { "javax.annotation;version=\"0.0.0\"" }; //$NON-NLS-1$
return PACKAGE_IMPORTS.toArray(String[]::new);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
package org.eclipse.pde.internal.ui.templates.e4;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.pde.core.plugin.*;
import org.eclipse.pde.internal.ui.templates.*;
import org.eclipse.pde.ui.IFieldData;
import org.eclipse.pde.ui.templates.PluginReference;
import org.eclipse.pde.ui.templates.TemplateOption;

public class E4ApplicationTemplate extends PDETemplateSection {
Expand All @@ -44,6 +43,18 @@ public class E4ApplicationTemplate extends PDETemplateSection {
// name of the EMPTY application model file stored in the org.eclipse.pde.ui.templates/templates_3.5/E4Application/bin folder
private static final String EMPTY_E4_MODEL_FILE = "bin" + File.separator + E4_MODEL_FILE; //$NON-NLS-1$

private static final List<String> REQUIRED_BUNDLES = List.of(//
"javax.inject", //$NON-NLS-1$
"org.eclipse.core.runtime", //$NON-NLS-1$
"org.eclipse.swt", //$NON-NLS-1$
"org.eclipse.e4.ui.model.workbench", //$NON-NLS-1$
"org.eclipse.jface", //$NON-NLS-1$
"org.eclipse.e4.ui.services", //$NON-NLS-1$
"org.eclipse.e4.ui.workbench", //$NON-NLS-1$
"org.eclipse.e4.core.di", //$NON-NLS-1$
"org.eclipse.e4.ui.di", //$NON-NLS-1$
"org.eclipse.e4.core.contexts"); //$NON-NLS-1$

private TemplateOption lifeCycleClassnameOption;

public E4ApplicationTemplate() {
Expand Down Expand Up @@ -202,25 +213,11 @@ public int getNumberOfWorkUnits() {

@Override
public IPluginReference[] getDependencies(String schemaVersion) {

String[] dependencies = new String[] {"javax.inject", //$NON-NLS-1$
"org.eclipse.core.runtime", "org.eclipse.swt", //$NON-NLS-1$//$NON-NLS-2$
"org.eclipse.e4.ui.model.workbench", "org.eclipse.jface", //$NON-NLS-1$ //$NON-NLS-2$
"org.eclipse.e4.ui.services", "org.eclipse.e4.ui.workbench", //$NON-NLS-1$ //$NON-NLS-2$
"org.eclipse.e4.core.di", "org.eclipse.e4.ui.di", //$NON-NLS-1$ //$NON-NLS-2$
"org.eclipse.e4.core.contexts",}; //$NON-NLS-1$

final ArrayList<IPluginReference> result = new ArrayList<>(dependencies.length);
for (final String dependency : dependencies) {
String versionString = "0.0.0"; //$NON-NLS-1$
result.add(new PluginReference(dependency, versionString, IMatchRules.GREATER_OR_EQUAL));
}
return result.toArray(new IPluginReference[0]);

return AbstractE4NewPluginTemplateWizard.createPluginReferences(REQUIRED_BUNDLES);
}

@Override
public String[] getNewFiles() {
return new String[] {"icons/", "css/default.css", "Application.e4xmi"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return new String[] { "icons/", "css/default.css", "Application.e4xmi" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
*******************************************************************************/
package org.eclipse.pde.internal.ui.templates.e4;

import java.util.List;
import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
import org.eclipse.pde.ui.IFieldData;
import org.eclipse.pde.ui.templates.ITemplateSection;

public class E4HandlerNewWizard extends AbstractE4NewPluginTemplateWizard {

private static final List<String> PACKAGE_IMPORTS = List.of( //
"javax.annotation;version=\"1.2.0\""); //$NON-NLS-1$

@Override
public void init(IFieldData data) {
super.init(data);
Expand All @@ -37,7 +41,7 @@ protected String getFilenameToEdit() {

@Override
public String[] getImportPackages() {
return new String[] {"javax.annotation;version=\"1.2.0\""}; //$NON-NLS-1$
return PACKAGE_IMPORTS.toArray(String[]::new);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@

package org.eclipse.pde.internal.ui.templates.e4;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.pde.core.plugin.*;
import org.eclipse.pde.internal.ui.templates.*;
import org.eclipse.pde.ui.IFieldData;
import org.eclipse.pde.ui.templates.PluginReference;

public class E4HandlerTemplate extends PDETemplateSection {

static final String E4_FRAGMENT_FILE = "fragment.e4xmi"; //$NON-NLS-1$

private static final List<String> REQUIRED_BUNDLES = List.of(//
"javax.inject", //$NON-NLS-1$
"org.eclipse.osgi", //$NON-NLS-1$
"org.eclipse.jface", //$NON-NLS-1$
"org.eclipse.e4.ui.services", //$NON-NLS-1$
"org.eclipse.e4.core.di.annotations"); //$NON-NLS-1$

/**
* Constructor for HelloWorldTemplate.
*/
Expand All @@ -53,15 +59,13 @@ private void createOptions() {
addOption(KEY_PACKAGE_NAME, PDETemplateMessages.E4HandlerTemplate_packageName, (String) null, 0);
addOption("className", PDETemplateMessages.E4HandlerTemplate_className, "HelloWorldHandler", 0); //$NON-NLS-1$ //$NON-NLS-2$
addOption("message", PDETemplateMessages.E4HandlerMessage, PDETemplateMessages.E4HandlerMessage_default, 0); //$NON-NLS-1$

}

@Override
protected void initializeFields(IFieldData data) {
// In a new project wizard, we don't know this yet - the
// model has not been created
initializeFields(data.getId());

}

@Override
Expand Down Expand Up @@ -90,18 +94,14 @@ public void addPages(Wizard wizard) {
markPagesAdded();
}



@Override
public String getUsedExtensionPoint() {
return "org.eclipse.e4.workbench.model"; //$NON-NLS-1$
}

@Override
protected void updateModel(IProgressMonitor monitor) throws CoreException {

createE4ModelExtension();

}

private void createE4ModelExtension() throws CoreException {
Expand All @@ -121,28 +121,14 @@ private void createE4ModelExtension() throws CoreException {
plugin.add(extension);
}


@Override
public String[] getNewFiles() {
return new String[] { "icons/", E4_FRAGMENT_FILE }; //$NON-NLS-1$
}

@Override
public IPluginReference[] getDependencies(String schemaVersion) {
ArrayList<PluginReference> result = new ArrayList<>();

final int matchRule = IMatchRules.GREATER_OR_EQUAL;

result.add(new PluginReference("javax.inject", null, matchRule)); //$NON-NLS-1$
result.add(new PluginReference("org.eclipse.osgi", null, matchRule)); //$NON-NLS-1$
result.add(new PluginReference("org.eclipse.jface", null, matchRule)); //$NON-NLS-1$
result.add(new PluginReference("org.eclipse.e4.ui.services", null, matchRule)); //$NON-NLS-1$
result.add(new PluginReference("org.eclipse.e4.core.di.annotations", null, matchRule)); //$NON-NLS-1$

return result.toArray(new IPluginReference[result.size()]);

return AbstractE4NewPluginTemplateWizard.createPluginReferences(REQUIRED_BUNDLES);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
*******************************************************************************/
package org.eclipse.pde.internal.ui.templates.e4;

import java.util.List;
import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
import org.eclipse.pde.ui.IFieldData;
import org.eclipse.pde.ui.templates.ITemplateSection;

public class E4ToolbarContributionNewWizard extends AbstractE4NewPluginTemplateWizard {

private static final List<String> PACKAGE_IMPORTS = List.of( //
"javax.annotation;version=\"1.2.0\""); //$NON-NLS-1$

@Override
public void init(IFieldData data) {
super.init(data);
Expand All @@ -37,7 +41,7 @@ protected String getFilenameToEdit() {

@Override
public String[] getImportPackages() {
return new String[] {"javax.annotation;version=\"1.2.0\""}; //$NON-NLS-1$
return PACKAGE_IMPORTS.toArray(String[]::new);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@

package org.eclipse.pde.internal.ui.templates.e4;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.pde.core.plugin.*;
import org.eclipse.pde.internal.ui.templates.*;
import org.eclipse.pde.ui.IFieldData;
import org.eclipse.pde.ui.templates.PluginReference;

public class E4ToolbarContributionTemplate extends PDETemplateSection {

static final String E4_FRAGMENT_FILE = "fragment.e4xmi"; //$NON-NLS-1$

private static final List<String> REQUIRED_BUNDLES = List.of(//
"javax.inject", //$NON-NLS-1$
"org.eclipse.osgi", //$NON-NLS-1$
"org.eclipse.jface", //$NON-NLS-1$
"org.eclipse.e4.ui.services", //$NON-NLS-1$
"org.eclipse.e4.core.di.annotations"); //$NON-NLS-1$

/**
* Constructor for HelloWorldTemplate.
*/
Expand All @@ -54,15 +60,13 @@ private void createOptions() {
addOption("className", PDETemplateMessages.E4ToolbarContributionTemplate_className, "HelloWorldHandler", 0); //$NON-NLS-1$ //$NON-NLS-2$
addOption("message", PDETemplateMessages.E4ToolbarContributionMessage, //$NON-NLS-1$
PDETemplateMessages.E4ToolbarContributionMessage_default, 0);

}

@Override
protected void initializeFields(IFieldData data) {
// In a new project wizard, we don't know this yet - the
// model has not been created
initializeFields(data.getId());

}

@Override
Expand Down Expand Up @@ -91,18 +95,14 @@ public void addPages(Wizard wizard) {
markPagesAdded();
}



@Override
public String getUsedExtensionPoint() {
return "org.eclipse.e4.workbench.model"; //$NON-NLS-1$
}

@Override
protected void updateModel(IProgressMonitor monitor) throws CoreException {

createE4ModelExtension();

}

private void createE4ModelExtension() throws CoreException {
Expand All @@ -122,28 +122,14 @@ private void createE4ModelExtension() throws CoreException {
plugin.add(extension);
}


@Override
public String[] getNewFiles() {
return new String[] { "icons/", E4_FRAGMENT_FILE }; //$NON-NLS-1$
}

@Override
public IPluginReference[] getDependencies(String schemaVersion) {
ArrayList<PluginReference> result = new ArrayList<>();

final int matchRule = IMatchRules.GREATER_OR_EQUAL;

result.add(new PluginReference("javax.inject", null, matchRule)); //$NON-NLS-1$
result.add(new PluginReference("org.eclipse.osgi", null, matchRule)); //$NON-NLS-1$
result.add(new PluginReference("org.eclipse.jface", null, matchRule)); //$NON-NLS-1$
result.add(new PluginReference("org.eclipse.e4.ui.services", null, matchRule)); //$NON-NLS-1$
result.add(new PluginReference("org.eclipse.e4.core.di.annotations", null, matchRule)); //$NON-NLS-1$

return result.toArray(new IPluginReference[result.size()]);

return AbstractE4NewPluginTemplateWizard.createPluginReferences(REQUIRED_BUNDLES);
}



}
Loading

0 comments on commit 4621352

Please sign in to comment.