From fcd44ef406f5ebfd004bd0ae35797ad51dc73c2a Mon Sep 17 00:00:00 2001 From: junichi11 Date: Fri, 4 Oct 2013 21:01:53 +0900 Subject: [PATCH 01/10] Fix cakephp check #59 --- .../cakephp/netbeans/module/CakePhp1ModuleImpl.java | 13 ++++++++++++- .../cakephp/netbeans/module/CakePhp2ModuleImpl.java | 11 +++++++++++ src/org/cakephp/netbeans/module/CakePhpModule.java | 8 +------- .../netbeans/module/CakePhpModuleFactory.java | 12 ++++++++---- .../cakephp/netbeans/module/CakePhpModuleImpl.java | 5 +++-- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/org/cakephp/netbeans/module/CakePhp1ModuleImpl.java b/src/org/cakephp/netbeans/module/CakePhp1ModuleImpl.java index 70c0d91..6ee27f5 100644 --- a/src/org/cakephp/netbeans/module/CakePhp1ModuleImpl.java +++ b/src/org/cakephp/netbeans/module/CakePhp1ModuleImpl.java @@ -80,12 +80,22 @@ public class CakePhp1ModuleImpl extends CakePhpModuleImpl { private static final String DIR_HELPERS = "helpers"; private static final String DIR_BEHAVIORS = "behaviors"; private static final String DIR_FIXTURES = "fixtures"; - private FileObject appDirectory; public CakePhp1ModuleImpl(PhpModule phpModule) { super(phpModule); } + @Override + public boolean isInCakePhp() { + FileObject console = getDirectory(DIR_TYPE.CORE, FILE_TYPE.CONSOLE, null); + if (console == null) { + return false; + } + + FileObject cake = console.getFileObject("cake.php"); // NOI18N + return cake != null && !cake.isFolder(); + } + @Override public FileObject getConsoleDirectory(DIR_TYPE type) { return getDirectory(DIR_TYPE.CORE, FILE_TYPE.CONSOLE); @@ -574,5 +584,6 @@ public FILE_TYPE getFileType(FileObject currentFile) { @Override public void refresh() { + setAppDirectory(); } } diff --git a/src/org/cakephp/netbeans/module/CakePhp2ModuleImpl.java b/src/org/cakephp/netbeans/module/CakePhp2ModuleImpl.java index 8ffb7ab..8ce8533 100644 --- a/src/org/cakephp/netbeans/module/CakePhp2ModuleImpl.java +++ b/src/org/cakephp/netbeans/module/CakePhp2ModuleImpl.java @@ -82,6 +82,17 @@ public CakePhp2ModuleImpl(PhpModule phpModule) { super(phpModule); } + @Override + public boolean isInCakePhp() { + FileObject console = getDirectory(DIR_TYPE.APP, FILE_TYPE.CONSOLE, null); + if (console == null) { + return false; + } + + FileObject cake = getDirectory(DIR_TYPE.CORE); + return cake != null && cake.isFolder(); + } + @Override public void refresh() { setAppDirectory(); diff --git a/src/org/cakephp/netbeans/module/CakePhpModule.java b/src/org/cakephp/netbeans/module/CakePhpModule.java index 035b0d7..36ab9c8 100644 --- a/src/org/cakephp/netbeans/module/CakePhpModule.java +++ b/src/org/cakephp/netbeans/module/CakePhpModule.java @@ -400,13 +400,7 @@ public FileObject createView(FileObject controller, PhpBaseElement phpElement) t } public boolean isInCakePhp() { - FileObject console = getDirectory(DIR_TYPE.APP, FILE_TYPE.CONSOLE, null); - if (console == null) { - return false; - } - - FileObject cake = getDirectory(DIR_TYPE.CORE); - return cake != null && cake.isFolder(); + return impl.isInCakePhp(); } public static CakePhpModule forPhpModule(PhpModule phpModule) { diff --git a/src/org/cakephp/netbeans/module/CakePhpModuleFactory.java b/src/org/cakephp/netbeans/module/CakePhpModuleFactory.java index d2cad02..fb225b5 100644 --- a/src/org/cakephp/netbeans/module/CakePhpModuleFactory.java +++ b/src/org/cakephp/netbeans/module/CakePhpModuleFactory.java @@ -43,8 +43,7 @@ import java.util.HashMap; import java.util.Map; -import org.cakephp.netbeans.module.CakePhpModule.DIR_TYPE; -import org.cakephp.netbeans.module.CakePhpModule.FILE_TYPE; +import org.cakephp.netbeans.preferences.CakePreferences; import org.cakephp.netbeans.util.CakeVersion; import org.netbeans.modules.php.api.phpmodule.PhpModule; import org.openide.filesystems.FileObject; @@ -95,8 +94,13 @@ public synchronized CakePhpModule create(PhpModule phpModule) { if (impl == null) { return null; } - FileObject console = impl.getDirectory(DIR_TYPE.APP, FILE_TYPE.CONSOLE); - if (console == null) { + String appPath = CakePreferences.getAppDirectoryPath(phpModule); + FileObject projectDirectory = phpModule.getProjectDirectory(); + if (projectDirectory == null) { + return null; + } + FileObject app = projectDirectory.getFileObject(appPath); + if (app == null) { return null; } // create module class diff --git a/src/org/cakephp/netbeans/module/CakePhpModuleImpl.java b/src/org/cakephp/netbeans/module/CakePhpModuleImpl.java index 0a3d180..c7cdecf 100644 --- a/src/org/cakephp/netbeans/module/CakePhpModuleImpl.java +++ b/src/org/cakephp/netbeans/module/CakePhpModuleImpl.java @@ -58,7 +58,7 @@ * * @author junichi11 */ -public abstract class CakePhpModuleImpl{ +public abstract class CakePhpModuleImpl { protected PhpModule phpModule; protected static String PHP_EXT = "php"; @@ -287,7 +287,6 @@ protected FileObject getAppDirectory() { } protected void setAppDirectory() { - // custom String appDirectoryPath = CakePreferences.getAppDirectoryPath(phpModule); if (!StringUtils.isEmpty(appDirectoryPath)) { appDirectory = phpModule.getProjectDirectory().getFileObject(appDirectoryPath); @@ -320,6 +319,8 @@ public DIR_TYPE getDirectoryType(FileObject currentFile) { return DIR_TYPE.NONE; } + public abstract boolean isInCakePhp(); + public abstract FILE_TYPE getFileType(FileObject fileObject); public abstract boolean isView(FileObject fo); From df6851351fa992c1a6c0502a5f7c33b58ef722ab Mon Sep 17 00:00:00 2001 From: junichi11 Date: Fri, 4 Oct 2013 23:25:00 +0900 Subject: [PATCH 02/10] Add enabled checkbox #60 --- .../netbeans/CakePhpFrameworkProvider.java | 12 ++++++---- .../CakePhpModuleCustomizerExtender.java | 6 +++++ .../netbeans/preferences/CakePreferences.java | 13 +++++++++++ .../netbeans/ui/customizer/Bundle.properties | 1 + .../ui/customizer/CakePhpCustomizerPanel.form | 23 +++++++++++++++---- .../ui/customizer/CakePhpCustomizerPanel.java | 22 ++++++++++++++++-- 6 files changed, 67 insertions(+), 10 deletions(-) diff --git a/src/org/cakephp/netbeans/CakePhpFrameworkProvider.java b/src/org/cakephp/netbeans/CakePhpFrameworkProvider.java index 5629aa3..f4cb902 100644 --- a/src/org/cakephp/netbeans/CakePhpFrameworkProvider.java +++ b/src/org/cakephp/netbeans/CakePhpFrameworkProvider.java @@ -51,6 +51,7 @@ import org.cakephp.netbeans.editor.codecompletion.CakePhpEditorExtenderFactory; import org.cakephp.netbeans.module.CakePhpModule; import org.cakephp.netbeans.module.CakePhpModule.DIR_TYPE; +import org.cakephp.netbeans.preferences.CakePreferences; import org.netbeans.modules.php.api.framework.BadgeIcon; import org.netbeans.modules.php.api.phpmodule.PhpModule; import org.netbeans.modules.php.api.phpmodule.PhpModuleProperties; @@ -102,11 +103,14 @@ public BadgeIcon getBadgeIcon() { @Override public boolean isInPhpModule(PhpModule phpModule) { - CakePhpModule module = CakePhpModule.forPhpModule(phpModule); - if (module == null) { - return false; + Boolean enabled = CakePreferences.isEnabled(phpModule); + if (enabled != null) { + // manually + return enabled; } - return module.isInCakePhp(); + // automatically + CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); + return cakeModule == null ? false : cakeModule.isInCakePhp(); } @Override diff --git a/src/org/cakephp/netbeans/CakePhpModuleCustomizerExtender.java b/src/org/cakephp/netbeans/CakePhpModuleCustomizerExtender.java index 1d7b1dc..7e74014 100755 --- a/src/org/cakephp/netbeans/CakePhpModuleCustomizerExtender.java +++ b/src/org/cakephp/netbeans/CakePhpModuleCustomizerExtender.java @@ -65,6 +65,7 @@ public class CakePhpModuleCustomizerExtender extends PhpModuleCustomizerExtender private final boolean isShowPopupForOneItem; private final boolean originalAutoCreateState; private final boolean originalIgnoreTmpDirectory; + private final boolean isEnabled; private ChangeSupport changeSupport = new ChangeSupport(this); CakePhpModuleCustomizerExtender(PhpModule phpModule) { @@ -74,6 +75,7 @@ public class CakePhpModuleCustomizerExtender extends PhpModuleCustomizerExtender originalIgnoreTmpDirectory = CakePreferences.ignoreTmpDirectory(phpModule); isShowPopupForOneItem = CakePreferences.isShowPopupForOneItem(phpModule); appDirectoryPath = CakePreferences.getAppDirectoryPath(phpModule); + isEnabled = CakePreferences.isEnabled(phpModule); } @Override @@ -126,6 +128,9 @@ public EnumSet save(PhpModule phpModule) { if (newAutoCreateState != originalAutoCreateState) { CakePreferences.setAutoCreateView(phpModule, newAutoCreateState); } + if (isEnabled != getPanel().isEnabledCakePhp()) { + CakePreferences.setEnabled(phpModule, !isEnabled); + } if (isProjectDir != getPanel().isUseProjectDirectory()) { CakePreferences.setUseProjectDirectory(phpModule, !isProjectDir); } @@ -155,6 +160,7 @@ private CakePhpCustomizerPanel getPanel() { component.setIgnoreTmpDirectory(originalIgnoreTmpDirectory); component.setShowPopupForOneItem(isShowPopupForOneItem); component.setAppDirectoryPath(appDirectoryPath); + component.setEnabledCakePhp(isEnabled); } return component; } diff --git a/src/org/cakephp/netbeans/preferences/CakePreferences.java b/src/org/cakephp/netbeans/preferences/CakePreferences.java index 2d300f5..ba6ea4a 100755 --- a/src/org/cakephp/netbeans/preferences/CakePreferences.java +++ b/src/org/cakephp/netbeans/preferences/CakePreferences.java @@ -51,6 +51,7 @@ */ public class CakePreferences { + private static final String ENABLED = "enabled"; // NOI18N private static final String APP_NAME = "app-name"; // NOI18N private static final String AUTO_CREATE_VIEW = "auto-create-view"; // NOI18N private static final String CAKE_PHP_DIR_PATH = "cake-php-dir-path"; // NOI18N @@ -61,6 +62,18 @@ public class CakePreferences { private static final String SHOW_POPUP_FOR_ONE_ITEM = "show-popup-for-one-item"; // NOI18N private static final String APP_DIRECTORY_PATH = "app-directory-path"; // NOI18N + public static void setEnabled(PhpModule phpModule, Boolean isEnabled) { + getPreferences(phpModule).putBoolean(ENABLED, isEnabled); + } + + public static Boolean isEnabled(PhpModule phpModule) { + String enabled = getPreferences(phpModule).get(ENABLED, null); + if (enabled == null) { + return null; + } + return Boolean.valueOf(enabled); + } + public static void setAppName(PhpModule phpModule, String appName) { getPreferences(phpModule).put(APP_NAME, appName); } diff --git a/src/org/cakephp/netbeans/ui/customizer/Bundle.properties b/src/org/cakephp/netbeans/ui/customizer/Bundle.properties index 659ecca..a72e8e0 100755 --- a/src/org/cakephp/netbeans/ui/customizer/Bundle.properties +++ b/src/org/cakephp/netbeans/ui/customizer/Bundle.properties @@ -9,3 +9,4 @@ CakePhpCustomizerPanel.appDirectoryTextField.text= CakePhpCustomizerPanel.appDirectoryLabel.text=app: CakePhpCustomizerPanel.customDirectoryPathLabel.text=Custom directory path (from project directory): CakePhpCustomizerPanel.generalLabel.text=General: +CakePhpCustomizerPanel.enabledCheckBox.text=enabled diff --git a/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.form b/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.form index 3e2309a..4ee62f2 100755 --- a/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.form +++ b/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.form @@ -44,10 +44,9 @@ - + - @@ -59,7 +58,14 @@ - + + + + + + + + @@ -77,7 +83,9 @@ - + + + @@ -197,5 +205,12 @@ + + + + + + + diff --git a/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.java b/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.java index 707bcad..e69d925 100755 --- a/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.java +++ b/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.java @@ -65,6 +65,14 @@ public CakePhpCustomizerPanel() { initComponents(); } + public boolean isEnabledCakePhp() { + return enabledCheckBox.isSelected(); + } + + public void setEnabledCakePhp(boolean isEnabled) { + enabledCheckBox.setSelected(isEnabled); + } + public boolean isAutoCreateView() { return autoCreateViewCheckBox.isSelected(); } @@ -154,6 +162,7 @@ private void initComponents() { appDirectoryTextField = new javax.swing.JTextField(); generalLabel = new javax.swing.JLabel(); generalSeparator = new javax.swing.JSeparator(); + enabledCheckBox = new javax.swing.JCheckBox(); autoCreateViewCheckBox.setText(org.openide.util.NbBundle.getMessage(CakePhpCustomizerPanel.class, "CakePhpCustomizerPanel.autoCreateViewCheckBox.text")); // NOI18N @@ -182,6 +191,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { generalLabel.setText(org.openide.util.NbBundle.getMessage(CakePhpCustomizerPanel.class, "CakePhpCustomizerPanel.generalLabel.text")); // NOI18N + enabledCheckBox.setText(org.openide.util.NbBundle.getMessage(CakePhpCustomizerPanel.class, "CakePhpCustomizerPanel.enabledCheckBox.text")); // NOI18N + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -212,7 +223,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createSequentialGroup() .addGap(12, 12, 12) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(useProjectDirectoryCheckBox) .addGroup(layout.createSequentialGroup() .addGap(12, 12, 12) .addComponent(cakePhpDirLabel) @@ -222,7 +232,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(appDirectoryLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(appDirectoryTextField)) - .addComponent(ignoreTmpCheckBox)))) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(enabledCheckBox) + .addComponent(useProjectDirectoryCheckBox) + .addComponent(ignoreTmpCheckBox)) + .addGap(0, 0, Short.MAX_VALUE))))) .addContainerGap()))) ); layout.setVerticalGroup( @@ -233,6 +248,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(generalLabel) .addComponent(generalSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(enabledCheckBox) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(ignoreTmpCheckBox) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) @@ -271,6 +288,7 @@ private void useProjectDirectoryCheckBoxActionPerformed(java.awt.event.ActionEve private javax.swing.JTextField cakePhpDirTextField; private javax.swing.JLabel customDirectoryPathLabel; private javax.swing.JSeparator customDirectoryPathSeparator; + private javax.swing.JCheckBox enabledCheckBox; private javax.swing.JLabel generalLabel; private javax.swing.JSeparator generalSeparator; private javax.swing.JLabel goToActionsLabel; From 966a9129891863bcec77d6d44fced87632f190c5 Mon Sep 17 00:00:00 2001 From: junichi11 Date: Sat, 5 Oct 2013 22:16:13 +0900 Subject: [PATCH 03/10] Improvement for project properties for cakephp #60 --- .../CakePhpModuleCustomizerExtender.java | 72 +++++++++--- .../netbeans/CakePhpModuleExtender.java | 3 + .../netbeans/module/CakePhpModule.java | 13 ++- .../netbeans/module/CakePhpModuleImpl.java | 5 +- .../netbeans/ui/customizer/Bundle.properties | 5 +- .../ui/customizer/CakePhpCustomizerPanel.form | 26 +---- .../ui/customizer/CakePhpCustomizerPanel.java | 95 ++++++++++------ .../validator/CakePhpCustomizerValidator.java | 105 ++++++++++++++++++ 8 files changed, 245 insertions(+), 79 deletions(-) create mode 100644 src/org/cakephp/netbeans/validator/CakePhpCustomizerValidator.java diff --git a/src/org/cakephp/netbeans/CakePhpModuleCustomizerExtender.java b/src/org/cakephp/netbeans/CakePhpModuleCustomizerExtender.java index 7e74014..c82b7dc 100755 --- a/src/org/cakephp/netbeans/CakePhpModuleCustomizerExtender.java +++ b/src/org/cakephp/netbeans/CakePhpModuleCustomizerExtender.java @@ -44,10 +44,14 @@ import java.util.EnumSet; import javax.swing.JComponent; import javax.swing.event.ChangeListener; +import org.cakephp.netbeans.module.CakePhpModule; import org.cakephp.netbeans.preferences.CakePreferences; import org.cakephp.netbeans.ui.customizer.CakePhpCustomizerPanel; +import org.cakephp.netbeans.validator.CakePhpCustomizerValidator; import org.netbeans.modules.php.api.phpmodule.PhpModule; +import org.netbeans.modules.php.api.validation.ValidationResult; import org.netbeans.modules.php.spi.framework.PhpModuleCustomizerExtender; +import org.openide.filesystems.FileObject; import org.openide.util.ChangeSupport; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; @@ -61,21 +65,24 @@ public class CakePhpModuleCustomizerExtender extends PhpModuleCustomizerExtender private CakePhpCustomizerPanel component; private final String appDirectoryPath; private final String cakePhpDirPath; - private final boolean isProjectDir; private final boolean isShowPopupForOneItem; private final boolean originalAutoCreateState; private final boolean originalIgnoreTmpDirectory; private final boolean isEnabled; private ChangeSupport changeSupport = new ChangeSupport(this); + private String errorMessage; + private boolean isValid; + private final PhpModule phpModule; CakePhpModuleCustomizerExtender(PhpModule phpModule) { + this.phpModule = phpModule; originalAutoCreateState = CakePreferences.getAutoCreateView(phpModule); cakePhpDirPath = CakePreferences.getCakePhpDirPath(phpModule); - isProjectDir = CakePreferences.useProjectDirectory(phpModule); originalIgnoreTmpDirectory = CakePreferences.ignoreTmpDirectory(phpModule); isShowPopupForOneItem = CakePreferences.isShowPopupForOneItem(phpModule); appDirectoryPath = CakePreferences.getAppDirectoryPath(phpModule); - isEnabled = CakePreferences.isEnabled(phpModule); + Boolean enabled = CakePreferences.isEnabled(phpModule); + isEnabled = enabled == null ? false : enabled; } @Override @@ -85,12 +92,18 @@ public String getDisplayName() { @Override public void addChangeListener(ChangeListener listener) { - changeSupport.addChangeListener(listener); + if (listener instanceof CakePhpModule) { + changeSupport.addChangeListener(listener); + } + getPanel().addChangeListener(listener); } @Override public void removeChangeListener(ChangeListener listener) { - changeSupport.removeChangeListener(listener); + if (listener instanceof CakePhpModule) { + changeSupport.removeChangeListener(listener); + } + getPanel().removeChangeListener(listener); } @Override @@ -105,15 +118,17 @@ public HelpCtx getHelp() { @Override public boolean isValid() { - return true; + validate(); + return isValid; } @Override public String getErrorMessage() { - return null; + validate(); + return errorMessage; } - public void fireChange() { + void fireChange() { changeSupport.fireChange(); } @@ -121,7 +136,7 @@ public void fireChange() { public EnumSet save(PhpModule phpModule) { EnumSet enumset = EnumSet.of(Change.FRAMEWORK_CHANGE); boolean newAutoCreateState = getPanel().isAutoCreateView(); - String newCakePhpDirPath = getPanel().getCakePhpDirTextField(); + String newCakePhpDirPath = getPanel().getCakePhpDirPath(); boolean newIgnoreTmpDirectory = getPanel().ignoreTmpDirectory(); String newAppDirectoryPath = getPanel().getAppDirectoryPath(); @@ -131,9 +146,6 @@ public EnumSet save(PhpModule phpModule) { if (isEnabled != getPanel().isEnabledCakePhp()) { CakePreferences.setEnabled(phpModule, !isEnabled); } - if (isProjectDir != getPanel().isUseProjectDirectory()) { - CakePreferences.setUseProjectDirectory(phpModule, !isProjectDir); - } if (isShowPopupForOneItem != getPanel().isShowPopupForOneItem()) { CakePreferences.setShowPopupForOneItem(phpModule, !isShowPopupForOneItem); } @@ -155,8 +167,7 @@ private CakePhpCustomizerPanel getPanel() { if (component == null) { component = new CakePhpCustomizerPanel(); component.setAutoCreateView(originalAutoCreateState); - component.setCakePhpDirTextField(cakePhpDirPath); - component.setUseProjectDirectory(isProjectDir); + component.setCakePhpDirPath(cakePhpDirPath); component.setIgnoreTmpDirectory(originalIgnoreTmpDirectory); component.setShowPopupForOneItem(isShowPopupForOneItem); component.setAppDirectoryPath(appDirectoryPath); @@ -164,4 +175,37 @@ private CakePhpCustomizerPanel getPanel() { } return component; } + + @NbBundle.Messages("CakePhpModuleCustomizerExtender.error.source.invalid=Can't find source directory. Project might be broken.") + void validate() { + CakePhpCustomizerPanel panel = getPanel(); + if (!panel.isEnabledCakePhp()) { + isValid = true; + errorMessage = null; + return; + } + + // get source directory + FileObject sourceDirectory = phpModule.getSourceDirectory(); + if (sourceDirectory == null) { + // broken project + isValid = false; + errorMessage = Bundle.CakePhpModuleCustomizerExtender_error_source_invalid(); + return; + } + + // validate + CakePhpCustomizerValidator validator = new CakePhpCustomizerValidator() + .validateCakePhpPath(sourceDirectory, panel.getCakePhpDirPath()) + .validateAppPath(sourceDirectory, panel.getAppDirectoryPath()); + ValidationResult result = validator.getResult(); + if (result.hasWarnings()) { + isValid = false; + errorMessage = result.getWarnings().get(0).getMessage(); + return; + } + // no problem + isValid = true; + errorMessage = null; + } } diff --git a/src/org/cakephp/netbeans/CakePhpModuleExtender.java b/src/org/cakephp/netbeans/CakePhpModuleExtender.java index e35fb69..e9600b2 100755 --- a/src/org/cakephp/netbeans/CakePhpModuleExtender.java +++ b/src/org/cakephp/netbeans/CakePhpModuleExtender.java @@ -192,6 +192,9 @@ public Set extend(PhpModule phpModule) throws ExtendingException { } else { createDatabaseFile(phpModule); } + + // set enabled + CakePreferences.setEnabled(phpModule, Boolean.TRUE); Set files = getOpenedFiles(config, targetDirectory); return files; } diff --git a/src/org/cakephp/netbeans/module/CakePhpModule.java b/src/org/cakephp/netbeans/module/CakePhpModule.java index 36ab9c8..c706d2a 100644 --- a/src/org/cakephp/netbeans/module/CakePhpModule.java +++ b/src/org/cakephp/netbeans/module/CakePhpModule.java @@ -50,6 +50,7 @@ import org.cakephp.netbeans.preferences.CakePreferences; import org.netbeans.modules.php.api.editor.PhpBaseElement; import org.netbeans.modules.php.api.phpmodule.PhpModule; +import org.netbeans.modules.php.api.util.StringUtils; import org.openide.filesystems.FileChangeAdapter; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileRenameEvent; @@ -282,9 +283,15 @@ public String getCurrentPluginName(FileObject currentFile) { } public static FileObject getCakePhpDirectory(PhpModule phpModule) { - FileObject cakePhpDirectory = null; - if (CakePreferences.useProjectDirectory(phpModule)) { - cakePhpDirectory = phpModule.getProjectDirectory().getFileObject(CakePreferences.getCakePhpDirPath(phpModule)); + FileObject sourceDirectory = phpModule.getSourceDirectory(); + if (sourceDirectory == null) { + return null; + } + + String cakePhpDirRelativePath = CakePreferences.getCakePhpDirPath(phpModule); + FileObject cakePhpDirectory; + if (!StringUtils.isEmpty(cakePhpDirRelativePath)) { + cakePhpDirectory = sourceDirectory.getFileObject(CakePreferences.getCakePhpDirPath(phpModule)); } else { cakePhpDirectory = phpModule.getSourceDirectory(); } diff --git a/src/org/cakephp/netbeans/module/CakePhpModuleImpl.java b/src/org/cakephp/netbeans/module/CakePhpModuleImpl.java index c7cdecf..71e5994 100644 --- a/src/org/cakephp/netbeans/module/CakePhpModuleImpl.java +++ b/src/org/cakephp/netbeans/module/CakePhpModuleImpl.java @@ -288,8 +288,9 @@ protected FileObject getAppDirectory() { protected void setAppDirectory() { String appDirectoryPath = CakePreferences.getAppDirectoryPath(phpModule); - if (!StringUtils.isEmpty(appDirectoryPath)) { - appDirectory = phpModule.getProjectDirectory().getFileObject(appDirectoryPath); + FileObject sourceDirectory = phpModule.getSourceDirectory(); + if (sourceDirectory != null && !StringUtils.isEmpty(appDirectoryPath)) { + appDirectory = sourceDirectory.getFileObject(appDirectoryPath); return; } appDirectory = null; diff --git a/src/org/cakephp/netbeans/ui/customizer/Bundle.properties b/src/org/cakephp/netbeans/ui/customizer/Bundle.properties index a72e8e0..cb63550 100755 --- a/src/org/cakephp/netbeans/ui/customizer/Bundle.properties +++ b/src/org/cakephp/netbeans/ui/customizer/Bundle.properties @@ -1,12 +1,11 @@ CakePhpCustomizerPanel.autoCreateViewCheckBox.text=Auto create a view file when go to view action is run. -CakePhpCustomizerPanel.cakePhpDirLabel.text=CakePHP Directory : +CakePhpCustomizerPanel.cakePhpDirLabel.text=CakePHP Root : CakePhpCustomizerPanel.cakePhpDirTextField.text= -CakePhpCustomizerPanel.useProjectDirectoryCheckBox.text=Use the relative path to the CakePHP directory from the project directory. CakePhpCustomizerPanel.ignoreTmpCheckBox.text=ignore tmp directory CakePhpCustomizerPanel.goToActionsLabel.text=Go To Actions: CakePhpCustomizerPanel.showPopupForOneItemCheckBox.text=Show the popup for one candidate item. CakePhpCustomizerPanel.appDirectoryTextField.text= CakePhpCustomizerPanel.appDirectoryLabel.text=app: -CakePhpCustomizerPanel.customDirectoryPathLabel.text=Custom directory path (from project directory): +CakePhpCustomizerPanel.customDirectoryPathLabel.text=Custom directory path (from source directory): CakePhpCustomizerPanel.generalLabel.text=General: CakePhpCustomizerPanel.enabledCheckBox.text=enabled diff --git a/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.form b/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.form index 4ee62f2..c876ca1 100755 --- a/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.form +++ b/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.form @@ -25,7 +25,7 @@ - + @@ -47,12 +47,6 @@ - - - - - - @@ -61,11 +55,15 @@ - + + + + + @@ -107,8 +105,6 @@ - - @@ -126,16 +122,6 @@ - - - - - - - - - - diff --git a/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.java b/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.java index e69d925..8572ff8 100755 --- a/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.java +++ b/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.java @@ -46,7 +46,11 @@ */ package org.cakephp.netbeans.ui.customizer; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import javax.swing.event.ChangeListener; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import org.openide.util.ChangeSupport; /** @@ -63,6 +67,21 @@ public class CakePhpCustomizerPanel extends javax.swing.JPanel { */ public CakePhpCustomizerPanel() { initComponents(); + init(); + setFieldsEnabled(enabledCheckBox.isSelected()); + } + + private void init() { + enabledCheckBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + fireChange(); + setFieldsEnabled(e.getStateChange() == ItemEvent.SELECTED); + } + }); + DocumentListener documentListener = new DefaultDocumentListener(); + appDirectoryTextField.getDocument().addDocumentListener(documentListener); + cakePhpDirTextField.getDocument().addDocumentListener(documentListener); } public boolean isEnabledCakePhp() { @@ -81,20 +100,11 @@ public void setAutoCreateView(boolean isAuto) { autoCreateViewCheckBox.setSelected(isAuto); } - public boolean isUseProjectDirectory() { - return useProjectDirectoryCheckBox.isSelected(); - } - - public void setUseProjectDirectory(boolean isCheck) { - useProjectDirectoryCheckBox.setSelected(isCheck); - setEnabledCakePhpDirectory(); - } - - public String getCakePhpDirTextField() { + public String getCakePhpDirPath() { return cakePhpDirTextField.getText(); } - public void setCakePhpDirTextField(String cakePhpDir) { + public void setCakePhpDirPath(String cakePhpDir) { cakePhpDirTextField.setText(cakePhpDir); } @@ -134,9 +144,12 @@ void fireChange() { changeSupport.fireChange(); } - public void setEnabledCakePhpDirectory() { - boolean selected = useProjectDirectoryCheckBox.isSelected(); - cakePhpDirTextField.setEnabled(selected); + final void setFieldsEnabled(boolean enabled) { + ignoreTmpCheckBox.setEnabled(enabled); + autoCreateViewCheckBox.setEnabled(enabled); + showPopupForOneItemCheckBox.setEnabled(enabled); + appDirectoryTextField.setEnabled(enabled); + cakePhpDirTextField.setEnabled(enabled); } /** @@ -149,7 +162,6 @@ public void setEnabledCakePhpDirectory() { private void initComponents() { autoCreateViewCheckBox = new javax.swing.JCheckBox(); - useProjectDirectoryCheckBox = new javax.swing.JCheckBox(); cakePhpDirLabel = new javax.swing.JLabel(); cakePhpDirTextField = new javax.swing.JTextField(); ignoreTmpCheckBox = new javax.swing.JCheckBox(); @@ -166,13 +178,6 @@ private void initComponents() { autoCreateViewCheckBox.setText(org.openide.util.NbBundle.getMessage(CakePhpCustomizerPanel.class, "CakePhpCustomizerPanel.autoCreateViewCheckBox.text")); // NOI18N - useProjectDirectoryCheckBox.setText(org.openide.util.NbBundle.getMessage(CakePhpCustomizerPanel.class, "CakePhpCustomizerPanel.useProjectDirectoryCheckBox.text")); // NOI18N - useProjectDirectoryCheckBox.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - useProjectDirectoryCheckBoxActionPerformed(evt); - } - }); - cakePhpDirLabel.setText(org.openide.util.NbBundle.getMessage(CakePhpCustomizerPanel.class, "CakePhpCustomizerPanel.cakePhpDirLabel.text")); // NOI18N cakePhpDirTextField.setText(org.openide.util.NbBundle.getMessage(CakePhpCustomizerPanel.class, "CakePhpCustomizerPanel.cakePhpDirTextField.text")); // NOI18N @@ -205,7 +210,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(autoCreateViewCheckBox) .addComponent(showPopupForOneItemCheckBox)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap(160, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -223,11 +228,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createSequentialGroup() .addGap(12, 12, 12) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(12, 12, 12) - .addComponent(cakePhpDirLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cakePhpDirTextField)) .addGroup(layout.createSequentialGroup() .addComponent(appDirectoryLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -235,9 +235,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(enabledCheckBox) - .addComponent(useProjectDirectoryCheckBox) .addComponent(ignoreTmpCheckBox)) - .addGap(0, 0, Short.MAX_VALUE))))) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(cakePhpDirLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cakePhpDirTextField))))) .addContainerGap()))) ); layout.setVerticalGroup( @@ -268,18 +271,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(appDirectoryLabel) .addComponent(appDirectoryTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(useProjectDirectoryCheckBox) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cakePhpDirLabel) .addComponent(cakePhpDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// //GEN-END:initComponents - - private void useProjectDirectoryCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useProjectDirectoryCheckBoxActionPerformed - setEnabledCakePhpDirectory(); - }//GEN-LAST:event_useProjectDirectoryCheckBoxActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel appDirectoryLabel; private javax.swing.JTextField appDirectoryTextField; @@ -295,6 +292,30 @@ private void useProjectDirectoryCheckBoxActionPerformed(java.awt.event.ActionEve private javax.swing.JSeparator goToActionsSeparator; private javax.swing.JCheckBox ignoreTmpCheckBox; private javax.swing.JCheckBox showPopupForOneItemCheckBox; - private javax.swing.JCheckBox useProjectDirectoryCheckBox; // End of variables declaration//GEN-END:variables + + private class DefaultDocumentListener implements DocumentListener { + + public DefaultDocumentListener() { + } + + @Override + public void insertUpdate(DocumentEvent e) { + processChange(); + } + + @Override + public void removeUpdate(DocumentEvent e) { + processChange(); + } + + @Override + public void changedUpdate(DocumentEvent e) { + processChange(); + } + + private void processChange() { + fireChange(); + } + } } diff --git a/src/org/cakephp/netbeans/validator/CakePhpCustomizerValidator.java b/src/org/cakephp/netbeans/validator/CakePhpCustomizerValidator.java new file mode 100644 index 0000000..b26c298 --- /dev/null +++ b/src/org/cakephp/netbeans/validator/CakePhpCustomizerValidator.java @@ -0,0 +1,105 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.cakephp.netbeans.validator; + +import org.netbeans.modules.php.api.validation.ValidationResult; +import org.openide.filesystems.FileObject; +import org.openide.util.NbBundle; + +/** + * + * @author junichi11 + */ +public final class CakePhpCustomizerValidator { + + private final ValidationResult result = new ValidationResult(); + + public ValidationResult getResult() { + return result; + } + + @NbBundle.Messages({ + "CakePhpCustomizerValidator.error.cake.invalid=Existing CakePHP directory must be set.", + "CakePhpCustomizerValidator.error.cake.script.invalid=Not found cake script file(cake.php)." + }) + public CakePhpCustomizerValidator validateCakePhpPath(FileObject sourceDirectory, String path) { + FileObject targetDirectory = sourceDirectory.getFileObject(path); + if (targetDirectory == null) { + result.addWarning(new ValidationResult.Message("cake.path", Bundle.CakePhpCustomizerValidator_error_cake_invalid())); // NOI18N + return this; + } + FileObject cake = targetDirectory.getFileObject("cake"); // NOI18N + FileObject script; + if (cake != null) { + script = targetDirectory.getFileObject("cake/console/cake.php"); // NOI18N + } else { + script = targetDirectory.getFileObject("lib/Cake/Console/cake.php"); // NOI18N + } + if (script == null) { + result.addWarning(new ValidationResult.Message("cake.script", Bundle.CakePhpCustomizerValidator_error_cake_script_invalid())); // NOI18N + } + return this; + } + + @NbBundle.Messages({ + "CakePhpCustomizerValidator.error.app.invalid=Existing app directory must be set.", + "CakePhpCustomizerValidator.error.app.config.invalid=App directory must have config/Config directory." + }) + public CakePhpCustomizerValidator validateAppPath(FileObject sourceDirectory, String path) { + FileObject targetDirectory = sourceDirectory.getFileObject(path); + if (targetDirectory == null) { + result.addWarning(new ValidationResult.Message("app.path", Bundle.CakePhpCustomizerValidator_error_app_invalid())); // NOI18N + return this; + } + + // Cake2.x, Cake3.x + FileObject config = targetDirectory.getFileObject("Config"); // NOI18N + if (config == null) { + // Cake1.x + config = targetDirectory.getFileObject("config"); // NOI18N + } + if (config == null) { + result.addWarning(new ValidationResult.Message("app.config", Bundle.CakePhpCustomizerValidator_error_app_config_invalid())); + } + return this; + } +} From 2204bc03f4db0595d9b1afe99b52f9ca96752ef8 Mon Sep 17 00:00:00 2001 From: junichi11 Date: Sun, 6 Oct 2013 00:05:26 +0900 Subject: [PATCH 04/10] Minor improvement --- .../netbeans/CakePhpModuleExtender.java | 113 +++++++++++------- 1 file changed, 69 insertions(+), 44 deletions(-) diff --git a/src/org/cakephp/netbeans/CakePhpModuleExtender.java b/src/org/cakephp/netbeans/CakePhpModuleExtender.java index e9600b2..6d3ee49 100755 --- a/src/org/cakephp/netbeans/CakePhpModuleExtender.java +++ b/src/org/cakephp/netbeans/CakePhpModuleExtender.java @@ -71,6 +71,7 @@ import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; import org.openide.util.HelpCtx; +import org.openide.util.NbBundle; /** * @author juncihi11 @@ -129,45 +130,24 @@ public String getWarningMessage() { return null; } + @NbBundle.Messages({ + "# {0} - name", + "CakePhpModuleExtender.extending.exception=This project might be broken: {0}" + }) @Override public Set extend(PhpModule phpModule) throws ExtendingException { FileObject targetDirectory = phpModule.getSourceDirectory(); if (targetDirectory == null) { - return Collections.emptySet(); + // broken project + throw new ExtendingException(Bundle.CakePhpModuleExtender_extending_exception(phpModule.getName())); } - // get panel - NewProjectConfigurationPanel p = getPanel(); // disabled components - Container parent = p.getParent().getParent(); - enabledComponents(parent, false); + Container parent = getPanel().getParent().getParent(); + setComponentsEnabled(parent, false); - // create cakephp files - if (p.getUnzipRadioButton().isSelected()) { - // unzip - Map tagsMap = p.getTagsMap(); - String url = tagsMap.get(p.getVersionList().getSelectedValue().toString()); - File target = FileUtil.toFile(targetDirectory); - boolean deleteEmpty = false; - try { - CakePhpFileUtils.unzip(url, target, new CakeZipEntryFilter(deleteEmpty, p.getUnzipFileNameTextField())); - } catch (MalformedURLException ex) { - Exceptions.printStackTrace(ex); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } - } else if (p.useLocalFile()) { - // local zip file - String path = CakePhpOptions.getInstance().getLocalZipFilePath(); - try { - FileUtils.unzip(path, FileUtil.toFile(targetDirectory), new ZipEntryFilterImpl()); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } - } else { - // Linux Mac ... run git command - createProjectFromGitCommand(targetDirectory); - } + // create + createCakePHP(targetDirectory); setAppName(targetDirectory); @@ -181,22 +161,19 @@ public Set extend(PhpModule phpModule) throws ExtendingException { setIgnoreTmpDirectory(phpModule); setAutoCreateViewFile(phpModule); + // set enabled + CakePreferences.setEnabled(phpModule, Boolean.TRUE); + CakePhpModule module = CakePhpModule.forPhpModule(phpModule); FileObject config = module.getConfigFile(); + // change security string changeSecurityString(config); - // create database.php - if (CakeVersion.getInstance(phpModule).isCakePhp(3)) { - createDatasourcesFile(phpModule); - } else { - createDatabaseFile(phpModule); - } + // create database file + createDBFile(phpModule); - // set enabled - CakePreferences.setEnabled(phpModule, Boolean.TRUE); - Set files = getOpenedFiles(config, targetDirectory); - return files; + return getInitialFiles(config, targetDirectory); } /** @@ -205,11 +182,11 @@ public Set extend(PhpModule phpModule) throws ExtendingException { * @param parent root container * @param enabled enabled true, disable false */ - private void enabledComponents(Container parent, boolean enabled) { + private void setComponentsEnabled(Container parent, boolean enabled) { parent.setEnabled(enabled); for (Component component : parent.getComponents()) { if (component instanceof Container) { - enabledComponents((Container) component, enabled); + setComponentsEnabled((Container) component, enabled); } else { component.setEnabled(false); } @@ -398,7 +375,7 @@ private void changeSecurityString(FileObject config) { * @return file set if plugin can find app/Config/core.php or * app/webroot/index.php, otherwize return empty set. */ - private Set getOpenedFiles(FileObject config, FileObject targetDirectory) { + private Set getInitialFiles(FileObject config, FileObject targetDirectory) { if (config == null) { return Collections.emptySet(); } @@ -455,6 +432,54 @@ private void setAppName(FileObject targetDirectory) { } } + private void createCakePHP(FileObject targetDirectory) { + // create cakephp files + NewProjectConfigurationPanel p = getPanel(); + if (p.getUnzipRadioButton().isSelected()) { + unzipFromGitHub(p, targetDirectory); + } else if (p.useLocalFile()) { + unzipFromLocalZip(targetDirectory); + } else { + // Linux Mac ... run git command + createProjectFromGitCommand(targetDirectory); + } + } + + private void unzipFromGitHub(NewProjectConfigurationPanel p, FileObject targetDirectory) { + // unzip + Map tagsMap = p.getTagsMap(); + String url = tagsMap.get(p.getVersionList().getSelectedValue().toString()); + File target = FileUtil.toFile(targetDirectory); + boolean deleteEmpty = false; + try { + CakePhpFileUtils.unzip(url, target, new CakeZipEntryFilter(deleteEmpty, p.getUnzipFileNameTextField())); + } catch (MalformedURLException ex) { + Exceptions.printStackTrace(ex); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + + private void unzipFromLocalZip(FileObject targetDirectory) { + // local zip file + String path = CakePhpOptions.getInstance().getLocalZipFilePath(); + try { + FileUtils.unzip(path, FileUtil.toFile(targetDirectory), new ZipEntryFilterImpl()); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + + private void createDBFile(PhpModule phpModule) { + // create database.php + if (CakeVersion.getInstance(phpModule).isCakePhp(3)) { + createDatasourcesFile(phpModule); + } else { + createDatabaseFile(phpModule); + } + } + + //~ Inner class private class ZipEntryFilterImpl implements FileUtils.ZipEntryFilter { private static final String CAKEPHP = "cakephp"; // NOI18N From 7b3488d85f0906c1b809a20d5735c7f46e24e376 Mon Sep 17 00:00:00 2001 From: junichi11 Date: Sun, 6 Oct 2013 08:22:59 +0900 Subject: [PATCH 05/10] Update README --- README.md | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2e7744e..16679f0 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This plugin provides support for CakePHP. ## About CakePHP 3.x -This plugin recognizes CakePHP3. But many features might not work yet. +Currently, This plugin doesn't recognize CakePHP3. ## WHAT WORKS @@ -82,16 +82,10 @@ CakePHP 2.x NewProject (Ctrl + Shift + N) > PHP > PHP Application with Existing Source Please select your cakephp dir(e.g. /home/NetBeansProjects/myproject) -### App Directory Name +### App Directory Path -Multiple app directory names support. - -#### Change app directory name - -Please set the following if you would like to different app directory name. - -1. Project properties > Framework > CakePHP -2. `app Folder name` : please set your new app folder name +You can set app directory path from source directory. +Project properties > Framework > CakePHP > Custom directory path > app #### Use multiple app directories @@ -146,8 +140,8 @@ myproject(e.g. myapp) ``` 1. Project properties > Framework > CakePHP -2. Check `Use the relative path to the CakePHP directory from the project directory.` -3. `CakePHP Directory` : "../" +2. `app` : "" (empty or ".") +3. `CakePHP Root` : "../" Please notice that Code Completion is not available. You have to add the cakephp core path to include path. From ca5220bfcf66ba53072266c153addc277d04eb53 Mon Sep 17 00:00:00 2001 From: junichi11 Date: Sun, 6 Oct 2013 08:23:36 +0900 Subject: [PATCH 06/10] Minor improvement --- src/org/cakephp/netbeans/CakePhpFrameworkProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/cakephp/netbeans/CakePhpFrameworkProvider.java b/src/org/cakephp/netbeans/CakePhpFrameworkProvider.java index f4cb902..3c4a944 100644 --- a/src/org/cakephp/netbeans/CakePhpFrameworkProvider.java +++ b/src/org/cakephp/netbeans/CakePhpFrameworkProvider.java @@ -119,7 +119,7 @@ public File[] getConfigurationFiles(PhpModule phpModule) { List configFiles = new LinkedList(); FileObject config = CakePhpModule.forPhpModule(phpModule).getConfigDirectory(DIR_TYPE.APP); assert config != null : "app/config or app/Config not found for CakePHP project " + phpModule.getDisplayName(); - if (config != null && config.isFolder()) { + if (config.isFolder()) { Enumeration children = config.getChildren(true); while (children.hasMoreElements()) { FileObject child = children.nextElement(); From 8bdac089c2ce911947c26dfc6424c850e8673f0a Mon Sep 17 00:00:00 2001 From: junichi11 Date: Sun, 6 Oct 2013 17:31:46 +0900 Subject: [PATCH 07/10] Fix base directory to source directory --- .../cakephp/netbeans/module/CakePhpModuleFactory.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/org/cakephp/netbeans/module/CakePhpModuleFactory.java b/src/org/cakephp/netbeans/module/CakePhpModuleFactory.java index fb225b5..eed2cb2 100644 --- a/src/org/cakephp/netbeans/module/CakePhpModuleFactory.java +++ b/src/org/cakephp/netbeans/module/CakePhpModuleFactory.java @@ -94,15 +94,18 @@ public synchronized CakePhpModule create(PhpModule phpModule) { if (impl == null) { return null; } + + // check app directory String appPath = CakePreferences.getAppDirectoryPath(phpModule); - FileObject projectDirectory = phpModule.getProjectDirectory(); - if (projectDirectory == null) { + FileObject sourceDirectory = phpModule.getSourceDirectory(); + if (sourceDirectory == null) { return null; } - FileObject app = projectDirectory.getFileObject(appPath); + FileObject app = sourceDirectory.getFileObject(appPath); if (app == null) { return null; } + // create module class module = new CakePhpModule(phpModule, impl); modules.put(phpModule, module); From 88a4489fbda0aa5cea2a25d8a58cc744a80da057 Mon Sep 17 00:00:00 2001 From: junichi11 Date: Sun, 6 Oct 2013 21:13:03 +0900 Subject: [PATCH 08/10] Add ToSingular and ToPlural actions #61 --- .../netbeans/ui/actions/ToPluralAction.java | 81 ++++++++++++ .../netbeans/ui/actions/ToSingularAction.java | 81 ++++++++++++ .../ui/actions/ToSingularPluralAction.java | 115 ++++++++++++++++++ 3 files changed, 277 insertions(+) create mode 100644 src/org/cakephp/netbeans/ui/actions/ToPluralAction.java create mode 100644 src/org/cakephp/netbeans/ui/actions/ToSingularAction.java create mode 100644 src/org/cakephp/netbeans/ui/actions/ToSingularPluralAction.java diff --git a/src/org/cakephp/netbeans/ui/actions/ToPluralAction.java b/src/org/cakephp/netbeans/ui/actions/ToPluralAction.java new file mode 100644 index 0000000..f5e2ddf --- /dev/null +++ b/src/org/cakephp/netbeans/ui/actions/ToPluralAction.java @@ -0,0 +1,81 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.cakephp.netbeans.ui.actions; + +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; +import org.openide.util.NbBundle; + +@ActionID( + category = "PHP", + id = "org.cakephp.netbeans.ui.actions.ToPluralAction") +@ActionRegistration(displayName = "#ToPluralAction_Name") +@ActionReference(path = "Shortcuts", name = "D-AT P") +@NbBundle.Messages("ToPluralAction_Name=To Plural") +public final class ToPluralAction extends ToSingularPluralAction { + + private static final long serialVersionUID = 588751827401955561L; + private static final ToPluralAction INSTANCE = new ToPluralAction(); + + private ToPluralAction() { + } + + public static ToPluralAction getInstance() { + return INSTANCE; + } + + @Override + public boolean isSingular() { + return false; + } + + @Override + protected String getFullName() { + return getPureName(); + } + + @Override + protected String getPureName() { + return Bundle.ToPluralAction_Name(); + } +} diff --git a/src/org/cakephp/netbeans/ui/actions/ToSingularAction.java b/src/org/cakephp/netbeans/ui/actions/ToSingularAction.java new file mode 100644 index 0000000..a2fa3b4 --- /dev/null +++ b/src/org/cakephp/netbeans/ui/actions/ToSingularAction.java @@ -0,0 +1,81 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.cakephp.netbeans.ui.actions; + +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; +import org.openide.util.NbBundle; + +@ActionID( + category = "PHP", + id = "org.cakephp.netbeans.ui.actions.ToSingularAction") +@ActionRegistration(displayName = "#ToSingularAction_Name") +@ActionReference(path = "Shortcuts", name = "D-AT S") +@NbBundle.Messages("ToSingularAction_Name=To Singular") +public final class ToSingularAction extends ToSingularPluralAction { + + private static final ToSingularAction INSTANCE = new ToSingularAction(); + private static final long serialVersionUID = -4605260636718462058L; + + private ToSingularAction() { + } + + public static ToSingularAction getInstance() { + return INSTANCE; + } + + @Override + public boolean isSingular() { + return true; + } + + @Override + protected String getFullName() { + return getPureName(); + } + + @Override + protected String getPureName() { + return Bundle.ToSingularAction_Name(); + } +} diff --git a/src/org/cakephp/netbeans/ui/actions/ToSingularPluralAction.java b/src/org/cakephp/netbeans/ui/actions/ToSingularPluralAction.java new file mode 100644 index 0000000..ce4f35e --- /dev/null +++ b/src/org/cakephp/netbeans/ui/actions/ToSingularPluralAction.java @@ -0,0 +1,115 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.cakephp.netbeans.ui.actions; + +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import javax.swing.text.JTextComponent; +import org.cakephp.netbeans.util.Inflector; +import org.netbeans.api.editor.EditorRegistry; +import org.netbeans.modules.php.api.phpmodule.PhpModule; +import org.netbeans.modules.php.api.util.StringUtils; +import org.netbeans.modules.php.spi.framework.actions.BaseAction; +import org.openide.util.Exceptions; + +/** + * + * @author junichi11 + */ +public abstract class ToSingularPluralAction extends BaseAction { + + private static final long serialVersionUID = 5109846082422483171L; + + public abstract boolean isSingular(); + + @Override + public void actionPerformed(PhpModule phpModule) { + JTextComponent editor = EditorRegistry.lastFocusedComponent(); + if (editor == null) { + return; + } + + // get selected text + String selectedText = editor.getSelectedText(); + if (StringUtils.isEmpty(selectedText)) { + return; + } + + // get start and end position + int selectionStart = editor.getSelectionStart(); + int selectionEnd = editor.getSelectionEnd(); + if (selectionEnd == 0) { + return; + } + + // singularize or pluralize + Inflector inflector = Inflector.getInstance(); + String changedText; + if (isSingular()) { + changedText = inflector.singularize(selectedText); + } else { + changedText = inflector.pluralize(selectedText); + } + if (selectedText.equals(changedText)) { + return; + } + + Document document = editor.getDocument(); + if (document == null) { + return; + } + // remove and insert + int removeLength = selectionEnd - selectionStart; + try { + document.remove(selectionStart, removeLength); + document.insertString(selectionStart, changedText, null); + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + } + + @Override + protected abstract String getFullName(); + + @Override + protected abstract String getPureName(); +} From e761f5e0cc3036cb453e70d007e00abec9235367 Mon Sep 17 00:00:00 2001 From: junichi11 Date: Fri, 11 Oct 2013 15:53:12 +0900 Subject: [PATCH 09/10] Use webroot of project.properties as app/webroot directory #62 --- src/org/cakephp/netbeans/module/CakePhpModuleImpl.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/org/cakephp/netbeans/module/CakePhpModuleImpl.java b/src/org/cakephp/netbeans/module/CakePhpModuleImpl.java index 71e5994..0e7ad63 100644 --- a/src/org/cakephp/netbeans/module/CakePhpModuleImpl.java +++ b/src/org/cakephp/netbeans/module/CakePhpModuleImpl.java @@ -51,6 +51,7 @@ import org.cakephp.netbeans.preferences.CakePreferences; import org.netbeans.modules.php.api.editor.PhpBaseElement; import org.netbeans.modules.php.api.phpmodule.PhpModule; +import org.netbeans.modules.php.api.phpmodule.PhpModuleProperties; import org.netbeans.modules.php.api.util.StringUtils; import org.openide.filesystems.FileObject; @@ -199,7 +200,12 @@ public FileObject getTestDirectory(DIR_TYPE type, String pluginName) { } public FileObject getWebrootDirectory(DIR_TYPE type) { - return getDirectory(type, FILE_TYPE.WEBROOT); + PhpModuleProperties properties = phpModule.getProperties(); + FileObject webroot = properties.getWebRoot(); + if (webroot == phpModule.getSourceDirectory()) { + return getDirectory(type, FILE_TYPE.WEBROOT); + } + return webroot != null ? webroot : getDirectory(type, FILE_TYPE.WEBROOT); } public FileObject getWebrootDirectory(DIR_TYPE type, String pluginName) { From e38167f5c4f1457fa87cbf1296ca0846920adcce Mon Sep 17 00:00:00 2001 From: junichi11 Date: Fri, 11 Oct 2013 15:55:54 +0900 Subject: [PATCH 10/10] Update version number to 0.9.6 --- manifest.mf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.mf b/manifest.mf index 5856458..807acc9 100644 --- a/manifest.mf +++ b/manifest.mf @@ -2,4 +2,4 @@ Manifest-Version: 1.0 OpenIDE-Module: org.cakephp.netbeans OpenIDE-Module-Layer: org/cakephp/netbeans/resources/layer.xml OpenIDE-Module-Localizing-Bundle: org/cakephp/netbeans/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 0.9.5 +OpenIDE-Module-Specification-Version: 0.9.6