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. 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 diff --git a/src/org/cakephp/netbeans/CakePhpFrameworkProvider.java b/src/org/cakephp/netbeans/CakePhpFrameworkProvider.java index 5629aa3..3c4a944 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 @@ -115,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(); diff --git a/src/org/cakephp/netbeans/CakePhpModuleCustomizerExtender.java b/src/org/cakephp/netbeans/CakePhpModuleCustomizerExtender.java index 1d7b1dc..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,19 +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); + Boolean enabled = CakePreferences.isEnabled(phpModule); + isEnabled = enabled == null ? false : enabled; } @Override @@ -83,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 @@ -103,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(); } @@ -119,15 +136,15 @@ 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(); if (newAutoCreateState != originalAutoCreateState) { CakePreferences.setAutoCreateView(phpModule, newAutoCreateState); } - if (isProjectDir != getPanel().isUseProjectDirectory()) { - CakePreferences.setUseProjectDirectory(phpModule, !isProjectDir); + if (isEnabled != getPanel().isEnabledCakePhp()) { + CakePreferences.setEnabled(phpModule, !isEnabled); } if (isShowPopupForOneItem != getPanel().isShowPopupForOneItem()) { CakePreferences.setShowPopupForOneItem(phpModule, !isShowPopupForOneItem); @@ -150,12 +167,45 @@ 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); + component.setEnabledCakePhp(isEnabled); } 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..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,19 +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); - } - Set files = getOpenedFiles(config, targetDirectory); - return files; + // create database file + createDBFile(phpModule); + + return getInitialFiles(config, targetDirectory); } /** @@ -202,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); } @@ -395,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(); } @@ -452,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 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..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(); } @@ -400,13 +407,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..eed2cb2 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,10 +94,18 @@ public synchronized CakePhpModule create(PhpModule phpModule) { if (impl == null) { return null; } - FileObject console = impl.getDirectory(DIR_TYPE.APP, FILE_TYPE.CONSOLE); - if (console == null) { + + // check app directory + String appPath = CakePreferences.getAppDirectoryPath(phpModule); + FileObject sourceDirectory = phpModule.getSourceDirectory(); + if (sourceDirectory == null) { + return null; + } + FileObject app = sourceDirectory.getFileObject(appPath); + if (app == null) { return null; } + // create module class module = new CakePhpModule(phpModule, impl); modules.put(phpModule, module); diff --git a/src/org/cakephp/netbeans/module/CakePhpModuleImpl.java b/src/org/cakephp/netbeans/module/CakePhpModuleImpl.java index 0a3d180..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; @@ -58,7 +59,7 @@ * * @author junichi11 */ -public abstract class CakePhpModuleImpl{ +public abstract class CakePhpModuleImpl { protected PhpModule phpModule; protected static String PHP_EXT = "php"; @@ -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) { @@ -287,10 +293,10 @@ protected FileObject getAppDirectory() { } protected void setAppDirectory() { - // custom 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; @@ -320,6 +326,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); 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/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(); +} diff --git a/src/org/cakephp/netbeans/ui/customizer/Bundle.properties b/src/org/cakephp/netbeans/ui/customizer/Bundle.properties index 659ecca..cb63550 100755 --- a/src/org/cakephp/netbeans/ui/customizer/Bundle.properties +++ b/src/org/cakephp/netbeans/ui/customizer/Bundle.properties @@ -1,11 +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 3e2309a..c876ca1 100755 --- a/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.form +++ b/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.form @@ -25,7 +25,7 @@ - + @@ -44,22 +44,26 @@ - + - - - - - - - - + + + + + + + + + + + + @@ -77,7 +81,9 @@ - + + + @@ -99,8 +105,6 @@ - - @@ -118,16 +122,6 @@ - - - - - - - - - - @@ -197,5 +191,12 @@ + + + + + + + diff --git a/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.java b/src/org/cakephp/netbeans/ui/customizer/CakePhpCustomizerPanel.java index 707bcad..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,30 +67,44 @@ public class CakePhpCustomizerPanel extends javax.swing.JPanel { */ public CakePhpCustomizerPanel() { initComponents(); + init(); + setFieldsEnabled(enabledCheckBox.isSelected()); } - public boolean isAutoCreateView() { - return autoCreateViewCheckBox.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 void setAutoCreateView(boolean isAuto) { - autoCreateViewCheckBox.setSelected(isAuto); + public boolean isEnabledCakePhp() { + return enabledCheckBox.isSelected(); } - public boolean isUseProjectDirectory() { - return useProjectDirectoryCheckBox.isSelected(); + public void setEnabledCakePhp(boolean isEnabled) { + enabledCheckBox.setSelected(isEnabled); } - public void setUseProjectDirectory(boolean isCheck) { - useProjectDirectoryCheckBox.setSelected(isCheck); - setEnabledCakePhpDirectory(); + public boolean isAutoCreateView() { + return autoCreateViewCheckBox.isSelected(); } - public String getCakePhpDirTextField() { + public void setAutoCreateView(boolean isAuto) { + autoCreateViewCheckBox.setSelected(isAuto); + } + + public String getCakePhpDirPath() { return cakePhpDirTextField.getText(); } - public void setCakePhpDirTextField(String cakePhpDir) { + public void setCakePhpDirPath(String cakePhpDir) { cakePhpDirTextField.setText(cakePhpDir); } @@ -126,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); } /** @@ -141,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(); @@ -154,16 +174,10 @@ 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 - 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 @@ -182,6 +196,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( @@ -194,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() @@ -212,17 +228,19 @@ 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) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cakePhpDirTextField)) .addGroup(layout.createSequentialGroup() .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(ignoreTmpCheckBox)) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(cakePhpDirLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cakePhpDirTextField))))) .addContainerGap()))) ); layout.setVerticalGroup( @@ -233,6 +251,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) @@ -251,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; @@ -271,12 +285,37 @@ 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; 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; + } +}