Skip to content

Commit

Permalink
Move flag checks from TemplateWizardHelper to WizardElement
Browse files Browse the repository at this point in the history
Currently there are two helper methods in TemplateWizardHelper that can
be used to check for flags, as this is generic functionality it could
better be moved to WizardElement itself so it can be customized there
depending on backing store element
  • Loading branch information
laeubi committed Dec 1, 2023
1 parent 3f15a1e commit a31752b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ public String getDescription() {
return description;
}

public Boolean getFlag(String name) {
if (configurationElement != null) {
String value = configurationElement.getAttribute(name);
if (value != null) {
return Boolean.valueOf(value.equalsIgnoreCase("true")); //$NON-NLS-1$
}
}
return null;
}

public boolean getFlag(String name, boolean defaultValue) {
if (configurationElement != null) {
String value = configurationElement.getAttribute(name);
if (value != null) {
return value.equalsIgnoreCase("true"); //$NON-NLS-1$
}
}
return defaultValue;
}

/**
* We allow replacement variables in description values as well. This is to
* allow extension template description reuse in project template wizards.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public NewProjectCreationFromTemplatePage(String pageName, AbstractFieldData dat
@Override
protected void createFormatGroup(Composite container) {
super.createFormatGroup(container);
Boolean osgiFlag = TemplateWizardHelper.getFlag(fTemplateWizard, TemplateWizardHelper.FLAG_OSGI);
Boolean osgiFlag = fTemplateWizard.getFlag(TemplateWizardHelper.FLAG_OSGI);
if (osgiFlag != null) {
boolean isOSGi = osgiFlag.booleanValue();
fEclipseButton.setSelection(!isOSGi);
Expand All @@ -46,7 +46,7 @@ protected void createFormatGroup(Composite container) {
@Override
protected void createProjectTypeGroup(Composite container) {
super.createProjectTypeGroup(container);
Boolean javaFlag = TemplateWizardHelper.getFlag(fTemplateWizard, TemplateWizardHelper.FLAG_JAVA);
Boolean javaFlag = fTemplateWizard.getFlag(TemplateWizardHelper.FLAG_JAVA);
if (javaFlag != null) {
boolean isJava = javaFlag.booleanValue();
fJavaButton.setSelection(isJava);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public PluginContentFromTemplatePage(String pageName, IProjectProvider provider,
@Override
protected void createRCPQuestion(Composite parent, int horizontalSpan) {
super.createRCPQuestion(parent, horizontalSpan);
Boolean rcpFlag = TemplateWizardHelper.getFlag(fTemplateWizard, TemplateWizardHelper.FLAG_RCP);
Boolean rcpFlag = fTemplateWizard.getFlag(TemplateWizardHelper.FLAG_RCP);
if (rcpFlag != null) {
boolean isRCP = rcpFlag.booleanValue();
fYesButton.setSelection(isRCP);
Expand All @@ -45,13 +45,13 @@ protected void createRCPQuestion(Composite parent, int horizontalSpan) {
@Override
protected void createPluginClassGroup(Composite container) {
super.createPluginClassGroup(container);
Boolean activatorFlag = TemplateWizardHelper.getFlag(fTemplateWizard, TemplateWizardHelper.FLAG_ACTIVATOR);
Boolean activatorFlag = fTemplateWizard.getFlag(TemplateWizardHelper.FLAG_ACTIVATOR);
if (activatorFlag != null) {
fGenerateActivator.setSelection(activatorFlag.booleanValue());
fGenerateActivator.setEnabled(false);
fNameText.setEnabled(activatorFlag.booleanValue());
}
Boolean uiFlag = TemplateWizardHelper.getFlag(fTemplateWizard, TemplateWizardHelper.FLAG_UI);
Boolean uiFlag = fTemplateWizard.getFlag(TemplateWizardHelper.FLAG_UI);
if (uiFlag != null) {
fUIPlugin.setSelection(uiFlag.booleanValue());
fUIPlugin.setEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public boolean select(Viewer viewer, Object parentElement, Object element) {
boolean automatic = osgi && data.isAutomaticMetadataGeneration();
WizardElement welement = (WizardElement) element;
boolean active = TemplateWizardHelper.isActive(welement);
boolean uiFlag = TemplateWizardHelper.getFlag(welement, TemplateWizardHelper.FLAG_UI, true);
boolean javaFlag = TemplateWizardHelper.getFlag(welement, TemplateWizardHelper.FLAG_JAVA, true);
boolean rcpFlag = TemplateWizardHelper.getFlag(welement, TemplateWizardHelper.FLAG_RCP, false);
boolean osgiFlag = TemplateWizardHelper.getFlag(welement, TemplateWizardHelper.FLAG_OSGI, false);
boolean uiFlag = welement.getFlag(TemplateWizardHelper.FLAG_UI, true);
boolean javaFlag = welement.getFlag(TemplateWizardHelper.FLAG_JAVA, true);
boolean rcpFlag = welement.getFlag(TemplateWizardHelper.FLAG_RCP, false);
boolean osgiFlag = welement.getFlag(TemplateWizardHelper.FLAG_OSGI, false);
boolean bndFlag = osgiFlag && javaFlag
&& TemplateWizardHelper.getFlag(welement, TemplateWizardHelper.FLAG_BND, false);
boolean activatorFlag = TemplateWizardHelper.getFlag(welement, TemplateWizardHelper.FLAG_ACTIVATOR, false);
&& welement.getFlag(TemplateWizardHelper.FLAG_BND, false);
boolean activatorFlag = welement.getFlag(TemplateWizardHelper.FLAG_ACTIVATOR, false);

//filter out wizards from disabled activities
if (!active)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ public class TemplateWizardHelper {
public static final String FLAG_BND = "bnd"; //$NON-NLS-1$
public static final String FLAG_ACTIVATOR = "requiresActivator"; //$NON-NLS-1$

public static Boolean getFlag(WizardElement element, String name) {
IConfigurationElement config = element.getConfigurationElement();
String value = config.getAttribute(name);
if (value == null)
return null;
return Boolean.valueOf(value.equalsIgnoreCase("true")); //$NON-NLS-1$
}

public static boolean getFlag(WizardElement element, String name, boolean defaultValue) {
IConfigurationElement config = element.getConfigurationElement();
String value = config.getAttribute(name);
if (value == null)
return defaultValue;
return value.equalsIgnoreCase("true"); //$NON-NLS-1$
}

public static boolean isActive(WizardElement element) {
IConfigurationElement config = element.getConfigurationElement();
final String pluginId = config.getNamespaceIdentifier();
Expand Down

0 comments on commit a31752b

Please sign in to comment.