Skip to content

Commit

Permalink
Unify creation of WizardElements
Browse files Browse the repository at this point in the history
Currently WizardElement are created based on slightly different
precondition checks, beside that, there is even one factory method but
only used in one place.

This unify the access to always using the factory method and instead
passing the required attributes to check as parameters.
  • Loading branch information
laeubi committed Dec 1, 2023
1 parent f7063df commit 5a3eebe
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,20 +350,7 @@ public String getPluginId() {
* @return new wizard element
*/
protected WizardElement createWizardElement(IConfigurationElement config) {
String name = config.getAttribute(WizardElement.ATT_NAME);
String id = config.getAttribute(WizardElement.ATT_ID);
if (name == null || id == null)
return null;
WizardElement element = new WizardElement(config);

String imageName = config.getAttribute(WizardElement.ATT_ICON);
Image image = null;
if (imageName != null) {
String pluginID = config.getNamespaceIdentifier();
image = PDEPlugin.getDefault().getLabelProvider().getImageFromPlugin(pluginID, imageName);
}
element.setImage(image);
return element;
return WizardElement.create(config, WizardElement.ATT_NAME, WizardElement.ATT_ID);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class WizardElement extends NamedElement implements IPluginContribution {
protected IConfigurationElement configurationElement;
private IConfigurationElement template;

public WizardElement(IConfigurationElement config) {
WizardElement(IConfigurationElement config) {
super(config.getAttribute(ATT_NAME));
this.configurationElement = config;
}
Expand Down Expand Up @@ -167,12 +167,12 @@ public String getPluginId() {
return null;
}

public static WizardElement create(IConfigurationElement config) {
String name = config.getAttribute(ATT_NAME);
String id = config.getAttribute(ATT_ID);
String className = config.getAttribute(ATT_CLASS);
if (name == null || id == null || className == null)
return null;
public static WizardElement create(IConfigurationElement config, String... requiredAttributes) {
for (String required : requiredAttributes) {
if (config.getAttribute(required) == null) {
return null;
}
}
WizardElement element = new WizardElement(config);
String imageName = config.getAttribute(ATT_ICON);
if (imageName != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.pde.internal.ui.PDEPlugin;
import org.eclipse.pde.internal.ui.PDEUIMessages;
import org.eclipse.pde.internal.ui.elements.ElementList;
import org.eclipse.pde.internal.ui.wizards.Category;
import org.eclipse.pde.internal.ui.wizards.WizardCollectionElement;
import org.eclipse.pde.internal.ui.wizards.WizardElement;
import org.eclipse.swt.graphics.Image;

public class NewExtensionRegistryReader {
public static final String TAG_WIZARD = "wizard"; //$NON-NLS-1$
Expand Down Expand Up @@ -61,41 +59,17 @@ protected WizardCollectionElement createCollectionElement(WizardCollectionElemen
}

protected WizardElement createWizardElement(IConfigurationElement config) {
String name = config.getAttribute(WizardElement.ATT_NAME);
String id = config.getAttribute(WizardElement.ATT_ID);
String className = config.getAttribute(WizardElement.ATT_CLASS);
String template = config.getAttribute(WizardElement.ATT_TEMPLATE);
if (name == null || id == null)
if (className == null && template == null) {
return null;
if (className == null && template == null)
return null;
WizardElement element = new WizardElement(config);
String imageName = config.getAttribute(WizardElement.ATT_ICON);
if (imageName != null) {
String pluginID = config.getNamespaceIdentifier();
Image image = PDEPlugin.getDefault().getLabelProvider().getImageFromPlugin(pluginID, imageName);
element.setImage(image);
}
return element;
return WizardElement.create(config, WizardElement.ATT_NAME, WizardElement.ATT_ID);
}

protected WizardElement createEditorWizardElement(IConfigurationElement config) {
String name = config.getAttribute(WizardElement.ATT_NAME);
String id = config.getAttribute(WizardElement.ATT_ID);
String className = config.getAttribute(WizardElement.ATT_CLASS);
String point = config.getAttribute(WizardElement.ATT_POINT);
if (name == null || id == null || className == null)
return null;
if (point == null)
return null;
WizardElement element = new WizardElement(config);
String imageName = config.getAttribute(WizardElement.ATT_ICON);
if (imageName != null) {
String pluginID = config.getNamespaceIdentifier();
Image image = PDEPlugin.getDefault().getLabelProvider().getImageFromPlugin(pluginID, imageName);
element.setImage(image);
}
return element;
return WizardElement.create(config, WizardElement.ATT_NAME, WizardElement.ATT_ID, WizardElement.ATT_CLASS,
WizardElement.ATT_POINT);
}

protected String getCategoryStringFor(IConfigurationElement config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.eclipse.pde.internal.ui.wizards.WizardElement;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkingSet;
Expand Down Expand Up @@ -107,19 +106,7 @@ public String getProjectName() {
}

protected WizardElement createWizardElement(IConfigurationElement config) {
String name = config.getAttribute(WizardElement.ATT_NAME);
String id = config.getAttribute(WizardElement.ATT_ID);
String className = config.getAttribute(WizardElement.ATT_CLASS);
if (name == null || id == null || className == null)
return null;
WizardElement element = new WizardElement(config);
String imageName = config.getAttribute(WizardElement.ATT_ICON);
if (imageName != null) {
String pluginID = config.getNamespaceIdentifier();
Image image = PDEPlugin.getDefault().getLabelProvider().getImageFromPlugin(pluginID, imageName);
element.setImage(image);
}
return element;
return WizardElement.create(config, WizardElement.ATT_NAME, WizardElement.ATT_ID, WizardElement.ATT_CLASS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.eclipse.pde.internal.ui.wizards.NewWizard;
import org.eclipse.pde.internal.ui.wizards.WizardElement;
import org.eclipse.pde.ui.IPluginContentWizard;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;

Expand Down Expand Up @@ -157,19 +156,7 @@ public void setInitializationData(IConfigurationElement config, String propertyN
}

protected WizardElement createWizardElement(IConfigurationElement config) {
String name = config.getAttribute(WizardElement.ATT_NAME);
String id = config.getAttribute(WizardElement.ATT_ID);
String className = config.getAttribute(WizardElement.ATT_CLASS);
if (name == null || id == null || className == null)
return null;
WizardElement element = new WizardElement(config);
String imageName = config.getAttribute(WizardElement.ATT_ICON);
if (imageName != null) {
String pluginID = config.getNamespaceIdentifier();
Image image = PDEPlugin.getDefault().getLabelProvider().getImageFromPlugin(pluginID, imageName);
element.setImage(image);
}
return element;
return WizardElement.create(config, WizardElement.ATT_NAME, WizardElement.ATT_ID, WizardElement.ATT_CLASS);
}

public ElementList getAvailableCodegenWizards() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ private WizardElement getTemplateWizard() {
for (IConfigurationElement element : elements) {
if (element.getName().equals(TAG_WIZARD)) {
if (templateID.equals(element.getAttribute(WizardElement.ATT_ID))) {
return WizardElement.create(element);
return WizardElement.create(element, WizardElement.ATT_NAME, WizardElement.ATT_ID,
WizardElement.ATT_CLASS);
}
}
}
Expand Down

0 comments on commit 5a3eebe

Please sign in to comment.