Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,6 @@ public class ManagedBeanIterator implements TemplateWizard.Iterator {
FACES_SCOPE.put(ManagedBean.Scope.VIEW, "ViewScoped"); // NOI18N
}

/**
* List of ContextDependencyInjection scopes.
*/
private static final Map<NamedScope, String> NAMED_SCOPE = new EnumMap<>(NamedScope.class);
static {
NAMED_SCOPE.put(NamedScope.DEPENDENT, "Dependent"); //NOI18N
NAMED_SCOPE.put(NamedScope.APPLICATION, "ApplicationScoped"); //NOI18N
NAMED_SCOPE.put(NamedScope.REQUEST, "RequestScoped"); //NOI18N
NAMED_SCOPE.put(NamedScope.SESSION, "SessionScoped"); //NOI18N
NAMED_SCOPE.put(NamedScope.CONVERSATION, "ConversationScoped"); //NOI18N
NAMED_SCOPE.put(NamedScope.FLOW, "FlowScoped"); //NOI18N
NAMED_SCOPE.put(NamedScope.VIEW, "ViewScoped"); //NOI18N

}

@Override
public void initialize(TemplateWizard wizard) {
index = 0;
Expand All @@ -101,27 +86,24 @@ public void initialize(TemplateWizard wizard) {

SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
managedBeanPanel = new ManagedBeanPanel(project, wizard);
WizardDescriptor.Panel javaPanel;
WizardDescriptor.Panel<WizardDescriptor> javaPanel;
if (sourceGroups.length == 0) {
wizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, NbBundle.getMessage(ManagedBeanIterator.class, "MSG_No_Sources_found"));
javaPanel = managedBeanPanel;
} else {
javaPanel = JavaTemplates.createPackageChooser(project, sourceGroups, managedBeanPanel);

javaPanel.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
managedBeanPanel.updateManagedBeanName((WizardDescriptor.Panel) e.getSource());
}
javaPanel.addChangeListener((ChangeEvent e) -> {
managedBeanPanel.updateManagedBeanName((WizardDescriptor.Panel) e.getSource());
});
}
panels = new WizardDescriptor.Panel[]{javaPanel};

// Creating steps.
Object prop = wizard.getProperty(WizardDescriptor.PROP_CONTENT_DATA); // NOI18N
String[] beforeSteps = null;
if (prop instanceof String[]) {
beforeSteps = (String[]) prop;
if (prop instanceof String[] strings) {
beforeSteps = strings;
}
String[] steps = createSteps(beforeSteps, panels);
for (int i = 0; i < panels.length; i++) {
Expand All @@ -140,7 +122,7 @@ public void uninitialize(TemplateWizard wizard) {
}

@Override
public Set instantiate(TemplateWizard wizard) throws IOException {
public Set<DataObject> instantiate(TemplateWizard wizard) throws IOException {
FileObject dir = Templates.getTargetFolder(wizard);
DataFolder df = DataFolder.findFolder(dir);
FileObject template = Templates.getTemplate(wizard);
Expand All @@ -162,31 +144,19 @@ public Set instantiate(TemplateWizard wizard) throws IOException {
DataObject dobj = null;

if (isAnnotate && (Utilities.isJavaEE6Plus(wizard) || (JSFUtils.isJSF20Plus(wm, true) && JSFUtils.isJavaEE5(wizard)))) {
Map<String, Object> templateProperties = new HashMap<String, Object>();
Map<String, Object> templateProperties = new HashMap<>();
String targetName = Templates.getTargetName(wizard);
boolean jakartaJsfPackages;
if(JSFUtils.isJakartaEE9Plus(wizard)) {
templateProperties.put("jakartaJsfPackages", true);
jakartaJsfPackages = true;
} else {
templateProperties.put("jakartaJsfPackages", false);
jakartaJsfPackages = false;
}
boolean jakartaJsfPackages = JSFUtils.isJakartaEE9Plus(wizard);
templateProperties.put("jakartaJsfPackages", jakartaJsfPackages);
org.netbeans.modules.web.beans.CdiUtil cdiUtil = project.getLookup().lookup(org.netbeans.modules.web.beans.CdiUtil.class);
boolean isCdiEnabled = cdiUtil != null && cdiUtil.isCdiEnabled();
if (isCdiEnabled) {
templateProperties.put("cdiEnabled", true);
templateProperties.put("classAnnotation", "@Named(value=\"" + beanName + "\")"); //NOI18N
templateProperties.put("scope", ScopeEntry.getFor(scope, jakartaJsfPackages)); //NOI18N
NamedScope namedScope = (NamedScope) scope;
switch (namedScope) {
case SESSION:
case CONVERSATION:
case VIEW:
templateProperties.put("passivationCapable", "true"); //NOI18N
break;
default:
break;
if (namedScope.isPassivationCapable()) {
templateProperties.put("passivationCapable", "true"); //NOI18N
}
} else {
if (targetName.equalsIgnoreCase(beanName) && targetName.substring(0, 1).equalsIgnoreCase(beanName.substring(0, 1))) {
Expand Down Expand Up @@ -220,8 +190,8 @@ public Set instantiate(TemplateWizard wizard) throws IOException {
} else {
packageName = "";
}
String className = null;
if (packageName.length() > 0) {
String className;
if (!packageName.isEmpty()) {
className = packageName + "." + targetName; //NOI18N
} else {
className = targetName;
Expand All @@ -243,11 +213,8 @@ public Set instantiate(TemplateWizard wizard) throws IOException {
bean.addDescription(beanDescription);
}

JSFConfigModelUtilities.doInTransaction(configModel, new Runnable() {
@Override
public void run() {
facesConfig.addManagedBean(bean);
}
JSFConfigModelUtilities.doInTransaction(configModel, () -> {
facesConfig.addManagedBean(bean);
});
JSFConfigModelUtilities.saveChanges(configModel);
}
Expand Down Expand Up @@ -329,23 +296,44 @@ private String getUniqueName(String original, Project project) {
}

protected enum NamedScope {
DEPENDENT("dependent"), //NOI18N
APPLICATION("application"), //NOI18N
REQUEST("request"), //NOI18N
SESSION("session"), //NOI18N
CONVERSATION("conversation"), //NOI18N
FLOW("flow"), //NOI18N
VIEW("view"); //NOI18N

private String scope;

NamedScope(String scope) {
this.scope = scope;
DEPENDENT("Dependent", false), //NOI18N
APPLICATION("ApplicationScoped", false), //NOI18N
REQUEST("RequestScoped", false), //NOI18N
SESSION("SessionScoped", true), //NOI18N
CONVERSATION("ConversationScoped", true), //NOI18N
FLOW("FlowScoped", false, "faces.flow"), //NOI18N
VIEW("ViewScoped", true, "faces.view"), //NOI18N
CLIENT_WINDOW("ClientWindowScoped", true, "faces.lifecycle"); //NOI18N

private final String simpleName;
private final boolean passivationCapable;
private final String subpackage;

private NamedScope(String simpleName, boolean passivationCapable) {
this(simpleName, passivationCapable, "enterprise.context");
}

private NamedScope(String simpleName, boolean passivationCapable, String subpackage) {
this.simpleName = simpleName;
this.passivationCapable = passivationCapable;
this.subpackage = subpackage;
}

@Override
public String toString() {
return scope;
return name().toLowerCase();
}

public String getSimpleName() {
return simpleName;
}

public boolean isPassivationCapable() {
return passivationCapable;
}

public String getSubpackage() {
return subpackage;
}
}

Expand Down Expand Up @@ -373,12 +361,11 @@ public String getParameters() {
}

private static ScopeEntry getFor(Object scope, boolean jakartaJsfPackages) {
if (scope instanceof Scope) {
Scope typedScope = (Scope) scope;
if (scope instanceof Scope typedScope) {
return new ScopeEntry(FACES_SCOPE.get(typedScope), getScopeImport(typedScope, jakartaJsfPackages));
} else {
NamedScope typedScope = (NamedScope) scope;
ScopeEntry se = new ScopeEntry(NAMED_SCOPE.get(typedScope), getScopeImport(typedScope, jakartaJsfPackages));
ScopeEntry se = new ScopeEntry(typedScope.getSimpleName(), getScopeImport(typedScope, jakartaJsfPackages));
if (typedScope == NamedScope.FLOW) {
se.parameters = "\"\""; //NOI18N
}
Expand All @@ -395,24 +382,8 @@ private static String getScopeImport(Scope scope, boolean jakartaJsfPackages) {
}

private static String getScopeImport(NamedScope scope, boolean jakartaJsfPackages) {
String scopeSimpleName = NAMED_SCOPE.get(scope);
if (jakartaJsfPackages) {
if (scope == NamedScope.FLOW) {
return "jakarta.faces.flow." + scopeSimpleName; //NOI18N
} else if (scope == NamedScope.VIEW) {
return "jakarta.faces.view." + scopeSimpleName; //NOI18N
} else {
return "jakarta.enterprise.context." + scopeSimpleName; //NOI18N
}
} else {
if (scope == NamedScope.FLOW) {
return "javax.faces.flow." + scopeSimpleName; //NOI18N
} else if (scope == NamedScope.VIEW) {
return "javax.faces.view." + scopeSimpleName; //NOI18N
} else {
return "javax.enterprise.context." + scopeSimpleName; //NOI18N
}
}
return jakartaJsfPackages ? "jakarta." : "javax."
+ scope.getSubpackage() + "." + scope.getSimpleName();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.netbeans.api.project.Project;
import org.netbeans.modules.j2ee.common.ProjectUtil;
import org.netbeans.modules.j2ee.common.ServerUtil;

import org.openide.WizardDescriptor;
Expand All @@ -40,7 +39,7 @@
* Panel asking for web frameworks to use.
* @author Radko Najman
*/
final class ManagedBeanPanel implements WizardDescriptor.Panel, WizardDescriptor.FinishablePanel, ChangeListener {
final class ManagedBeanPanel implements WizardDescriptor.FinishablePanel<WizardDescriptor>, ChangeListener {

private TemplateWizard wizard;
private ManagedBeanPanelVisual component;
Expand Down Expand Up @@ -81,7 +80,7 @@ public void updateManagedBeanName(WizardDescriptor.Panel panel) {
return;
}

if ((targetName == null) || targetName.trim().equals("")) {
if ((targetName == null) || targetName.trim().isEmpty()) {
return;
}

Expand Down Expand Up @@ -140,21 +139,21 @@ public final void removeChangeListener(ChangeListener l) {
}
}
protected final void fireChangeEvent() {
Iterator it;
Iterator<ChangeListener> it;
synchronized (listeners) {
it = new HashSet(listeners).iterator();
it = new HashSet<>(listeners).iterator();
}
ChangeEvent ev = new ChangeEvent(this);
while (it.hasNext()) {
((ChangeListener)it.next()).stateChanged(ev);
it.next().stateChanged(ev);
}
}

@Override
public void readSettings(Object settings) {
public void readSettings(WizardDescriptor settings) {
wizard = (TemplateWizard) settings;
component.read(wizard);

// XXX hack, TemplateWizard in final setTemplateImpl() forces new wizard's title
// this name is used in NewProjectWizard to modify the title
Object substitute = ((JComponent) component).getClientProperty("NewProjectWizard_Title"); // NOI18N
Expand All @@ -163,11 +162,10 @@ public void readSettings(Object settings) {
}

@Override
public void storeSettings(Object settings) {
WizardDescriptor d = (WizardDescriptor) settings;
component.store(d);
public void storeSettings(WizardDescriptor settings) {
component.store(settings);

((WizardDescriptor) d).putProperty("NewProjectWizard_Title", null); // NOI18N
settings.putProperty("NewProjectWizard_Title", null); // NOI18N
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jComboBoxConfigFileActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="jLabelName">
<Properties>
Expand Down Expand Up @@ -157,6 +160,9 @@
<ResourceString bundle="org/netbeans/modules/web/jsf/wizards/Bundle.properties" key="ACSD_ManagedBeanScope" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</AccessibilityProperties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;Object&gt;"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="jLabelDesc">
<Properties>
Expand Down
Loading
Loading