Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
#50 [Optional Files] Special case -> package name is configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoghuman committed Dec 8, 2016
1 parent 0699ec7 commit cbcba3c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 24 deletions.
1 change: 1 addition & 0 deletions releases/Release_v1.5_2016-12-dd_HH-mm.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Naoghuman


[//]: # (Issues which will be integrated in this release)
#50 [Optional Files] Special case -> package name is configuration. (Enhancement)



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@
package com.github.naoghuman.netbeanside.afterburnerfx.plugin;

import com.github.naoghuman.netbeanside.afterburnerfx.plugin.support.IPluginSupport;
import com.github.naoghuman.netbeanside.afterburnerfx.plugin.support.PluginSupport;
import javax.swing.event.ChangeListener;
import org.openide.WizardDescriptor;
import org.openide.util.HelpCtx;
import org.openide.util.NbPreferences;

public class PluginWizardPanelOptionalFiles implements WizardDescriptor.Panel<WizardDescriptor>, IPluginSupport {

private String packageName = null;

/**
* The visual component that displays this panel. If you need to access the
* component from this class, just use getComponent().
*/
private PluginVisualPanelOptionalFiles component;
private WizardDescriptor wizardDescriptor;

@Override
public PluginVisualPanelOptionalFiles getComponent() {
Expand All @@ -45,6 +49,10 @@ public HelpCtx getHelp() {

@Override
public boolean isValid() {
if (PluginSupport.isLastPackageNameConfiguration(packageName)) {
PluginSupport.setWarningMessage(MSG_WARNING__OPTION_GENERATION_CONFIGURATION_PROPERTIES_DEACTIVATED, wizardDescriptor);
}

return true;
}

Expand All @@ -59,9 +67,11 @@ public void removeChangeListener(ChangeListener l) {
}

@Override
public void readSettings(WizardDescriptor wiz) {
public void readSettings(WizardDescriptor wizardDescriptor) {
this.wizardDescriptor = wizardDescriptor;

final String baseName = NbPreferences.forModule(PluginWizardIterator.class).get(PROP__FILENAME_CHOOSEN, PROP__FILENAME_CHOOSEN_DEFAULT_VALUE);
final String packageName = NbPreferences.forModule(PluginWizardIterator.class).get(PROP__CHOOSEN_PACKAGE, PROP__FILENAME_CHOOSEN_DEFAULT_VALUE);
packageName = NbPreferences.forModule(PluginWizardIterator.class).get(PROP__CHOOSEN_PACKAGE, PROP__FILENAME_CHOOSEN_DEFAULT_VALUE);

final boolean shouldFXMLtoLowerCase = NbPreferences.forModule(PluginWizardIterator.class).getBoolean(PROP__FXML_TO_LOWERCASE, Boolean.TRUE);

Expand All @@ -83,7 +93,7 @@ public void readSettings(WizardDescriptor wiz) {
}

@Override
public void storeSettings(WizardDescriptor wiz) {
public void storeSettings(WizardDescriptor wizardDescriptor) {
NbPreferences.forModule(PluginWizardIterator.class).putBoolean(PROP__CSS_FILE_SHOULD_CREATE, getComponent().shouldCreateCSS());
NbPreferences.forModule(PluginWizardIterator.class).putBoolean(PROP__CSS_FILE_SHOULD_INJECT, getComponent().shouldInjectCSS());
NbPreferences.forModule(PluginWizardIterator.class).putBoolean(PROP__CSS_TO_LOWERCASE, getComponent().shouldCSStoLowerCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class PluginWizardPanelPrimaryFiles implements WizardDescriptor.Panel<Wiz
private final SourceGroupSupport sourceGroupSupport;

private final PropertyChangeSupport propertyChangeSupport;
private WizardDescriptor settings;
private WizardDescriptor wizardDescriptor;

/**
* The visual component that displays this panel. If you need to access the
Expand Down Expand Up @@ -70,35 +70,35 @@ public HelpCtx getHelp() {
@Override
public boolean isValid() {
if (!PluginSupport.isValidBaseName(component.getBaseName())) {
PluginSupport.setInfoMessage(MSG_INFO__FILE_NAME_ISNT_VALID, settings);
PluginSupport.setInfoMessage(MSG_INFO__FILE_NAME_ISNT_VALID, wizardDescriptor);
propertyChangeSupport.firePropertyChange(PROP__SHOW_INFORMATION_CREATE_FOLLOWING_FILES, null, Boolean.FALSE);

return false;
}

if (!PluginSupport.isBaseNameContainsWrongFileNameChars(component.getBaseName())) {
PluginSupport.setErrorMessage(MSG_ERROR__FILE_NAME_CONTAINS_WRONG_CHARS, settings);
PluginSupport.setErrorMessage(MSG_ERROR__FILE_NAME_CONTAINS_WRONG_CHARS, wizardDescriptor);
propertyChangeSupport.firePropertyChange(PROP__SHOW_INFORMATION_CREATE_FOLLOWING_FILES, null, Boolean.FALSE);

return false;
}

if (!PluginSupport.isValidPackageName(component.getPackageName())) {
PluginSupport.setErrorMessage(MSG_ERROR__PACKAGE_NAME_ISNT_VALID, settings);
PluginSupport.setErrorMessage(MSG_ERROR__PACKAGE_NAME_ISNT_VALID, wizardDescriptor);
propertyChangeSupport.firePropertyChange(PROP__SHOW_INFORMATION_CREATE_FOLLOWING_FILES, null, Boolean.FALSE);

return false;
}

if (!PluginSupport.isValidPackage(component.getLocationFolder(), component.getPackageName())) {
PluginSupport.setErrorMessage(MSG_ERROR__PACKAGE_ISNT_FOLDER, settings);
PluginSupport.setErrorMessage(MSG_ERROR__PACKAGE_ISNT_FOLDER, wizardDescriptor);
propertyChangeSupport.firePropertyChange(PROP__SHOW_INFORMATION_CREATE_FOLLOWING_FILES, null, Boolean.FALSE);

return false;
}

if (!PluginSupport.isValidBaseNameAndPackage(component.getBaseName(), component.getLocationFolder(), component.getPackageName())) {
PluginSupport.setWarningMessage(MSG_WARNING__FILE_AND_PACKAGE_NAME_ARENT_EQUALS, settings);
PluginSupport.setWarningMessage(MSG_WARNING__FILE_AND_PACKAGE_NAME_ARENT_EQUALS, wizardDescriptor);
propertyChangeSupport.firePropertyChange(PROP__SHOW_INFORMATION_CREATE_FOLLOWING_FILES, null, Boolean.FALSE);

return false;
Expand All @@ -107,13 +107,13 @@ public boolean isValid() {
final String errorMessage = PluginSupport.canUseFileName(component.getLocationFolder(), component.getPackageFileName(),
component.getBaseName(), TEMPLATE_PARAMETER__FXML);
if (errorMessage != null) {
settings.getNotificationLineSupport().setErrorMessage(errorMessage);
wizardDescriptor.getNotificationLineSupport().setErrorMessage(errorMessage);
propertyChangeSupport.firePropertyChange(PROP__SHOW_INFORMATION_CREATE_FOLLOWING_FILES, null, Boolean.FALSE);

return false;
}

PluginSupport.clearMessages(settings);
PluginSupport.clearMessages(wizardDescriptor);
propertyChangeSupport.firePropertyChange(PROP__SHOW_INFORMATION_CREATE_FOLLOWING_FILES, null, Boolean.TRUE);

return true;
Expand All @@ -130,17 +130,17 @@ public void removeChangeListener(ChangeListener listener) {
}

@Override
public void readSettings(WizardDescriptor settings) {
this.settings = settings;
public void readSettings(WizardDescriptor wizardDescriptor) {
this.wizardDescriptor = wizardDescriptor;

final FileObject preselectedFolder = Templates.getTargetFolder(settings);
final FileObject preselectedFolder = Templates.getTargetFolder(wizardDescriptor);
final String layoutContainer = NbPreferences.forModule(PluginWizardIterator.class).get(PROP__LAYOUT_CONTAINER, DEFAULT_LAYOUT_CONTAINER);
final boolean shouldFXMLtoLowerCase = NbPreferences.forModule(PluginWizardIterator.class).getBoolean(PROP__FXML_TO_LOWERCASE, Boolean.TRUE);
this.getComponent().initValues(Templates.getTemplate(settings), preselectedFolder, layoutContainer, shouldFXMLtoLowerCase);
this.getComponent().initValues(Templates.getTemplate(wizardDescriptor), preselectedFolder, layoutContainer, shouldFXMLtoLowerCase);
}

@Override
public void storeSettings(WizardDescriptor wiz) {
public void storeSettings(WizardDescriptor wizardDescriptor) {
NbPreferences.forModule(PluginWizardIterator.class).put(PROP__CHOOSEN_PACKAGE, getComponent().getPackageName());
NbPreferences.forModule(PluginWizardIterator.class).put(PROP__FILENAME_CHOOSEN, getComponent().getBaseName());
NbPreferences.forModule(PluginWizardIterator.class).put(PROP__LAYOUT_CONTAINER, getComponent().getLayoutContainer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void removeChangeListener(ChangeListener l) {
}

@Override
public void readSettings(WizardDescriptor wiz) {
public void readSettings(WizardDescriptor wizardDescriptor) {
final String baseName = NbPreferences.forModule(PluginWizardIterator.class).get(PROP__FILENAME_CHOOSEN, "Afterburner"); // NOI18N
final String packageName = NbPreferences.forModule(PluginWizardIterator.class).get(PROP__CHOOSEN_PACKAGE, "Afterburner"); // NOI18N

Expand All @@ -83,7 +83,7 @@ public void readSettings(WizardDescriptor wiz) {
}

@Override
public void storeSettings(WizardDescriptor wiz) {
public void storeSettings(WizardDescriptor wizardDescriptor) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ error.target.folder.is.readonly=The 'target' folder is read-only.
msg.combobox.model.please.wait=Please Wait...

warning.file.and.package.name.arent.equals=Provided 'file and package' names aren't equals.
warning.option.generation.configuration.properties.deactivated=Last packagename is 'configuration'. Last option for 'configuration.properties' is deactivated!
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public interface IPluginSupport {
public static final String MSG_ERROR__TARGET_FOLDER_DOESNT_EXISTS = "error.target.folder.doesnt.exists"; // NOI18N
public static final String MSG_ERROR__TARGET_FOLDER_IS_READONLY = "error.target.folder.is.readonly"; // NOI18N
public static final String MSG_WARNING__FILE_AND_PACKAGE_NAME_ARENT_EQUALS = "warning.file.and.package.name.arent.equals"; // NOI18N
public static final String MSG_WARNING__OPTION_GENERATION_CONFIGURATION_PROPERTIES_DEACTIVATED = "warning.option.generation.configuration.properties.deactivated"; // NOI18N

public static final String PROP__CHOOSEN_PACKAGE = "PROP__CHOOSEN_PACKAGE"; // NOI18N
public static final String PROP__CONFIGURATION_FILE_SHOULD_CREATE = "PROP__CONFIGURATION_FILE_SHOULD_CREATE"; // NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static boolean isMavenProject(@NonNull final Project prj) {
return false;
}

fo = fo.getFileObject("pom.xml"); //NOI18N
fo = fo.getFileObject("pom.xml"); // NOI18N
if (fo != null) {
return true;
}
Expand All @@ -206,12 +206,25 @@ public static boolean checkIfBaseNameEqualsLastPackageName(String baseName, Stri
return false;
}

if (!packageName.toLowerCase().endsWith(baseName.toLowerCase())) { // NOI18N
if (!packageName.toLowerCase().endsWith(baseName.toLowerCase())) {
return false;
}

return true;
}

public static boolean isLastPackageNameConfiguration(String packageName) {
boolean isLastPackageNameConfiguration = false;
if (packageName == null) {
return isLastPackageNameConfiguration;
}

if (packageName.toLowerCase().endsWith("configuration")) { // NOI18N
isLastPackageNameConfiguration = true;
}

return isLastPackageNameConfiguration;
}

public static boolean isValidBaseNameAndPackage(String baseName, FileObject root, String packageName) {
if (!isValidBaseName(baseName)) {
Expand Down Expand Up @@ -291,12 +304,12 @@ public static void setErrorMessage(String key, WizardDescriptor wizardDescriptor
wizardDescriptor.getNotificationLineSupport().setErrorMessage(NbBundle.getMessage(PluginSupport.class, key));
}

public static void setInfoMessage(String key, WizardDescriptor settings) {
settings.getNotificationLineSupport().setInformationMessage(NbBundle.getMessage(PluginSupport.class, key));
public static void setInfoMessage(String key, WizardDescriptor wizardDescriptor) {
wizardDescriptor.getNotificationLineSupport().setInformationMessage(NbBundle.getMessage(PluginSupport.class, key));
}

public static void setWarningMessage(String key, WizardDescriptor settings) {
settings.getNotificationLineSupport().setWarningMessage(NbBundle.getMessage(PluginSupport.class, key));
public static void setWarningMessage(String key, WizardDescriptor wizardDescriptor) {
wizardDescriptor.getNotificationLineSupport().setWarningMessage(NbBundle.getMessage(PluginSupport.class, key));
}

}

0 comments on commit cbcba3c

Please sign in to comment.