001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.project;
020:
021: import java.io.File;
022: import java.util.Collection;
023: import java.util.Iterator;
024:
025: import javax.swing.JTabbedPane;
026:
027: import com.jeta.open.i18n.I18N;
028: import com.jeta.open.rules.JETARule;
029: import com.jeta.open.rules.RuleResult;
030: import com.jeta.swingbuilder.store.ProjectModel;
031:
032: /**
033: * Validator for the ProjectSettingsView
034: *
035: * @author Jeff Tassin
036: */
037: public class ProjectSettingsRule implements JETARule {
038: /**
039: * Validates the ProjectSettingsView.
040: *
041: * @param params
042: * a 1 element array that contains a ProjectSettingsView object.
043: */
044: public RuleResult check(Object[] params) {
045: ProjectSettingsView view = (ProjectSettingsView) params[0];
046: Collection paths = view.getPaths();
047: if (paths.size() == 0) {
048: return new RuleResult(
049: I18N
050: .getLocalizedMessage("One or more source paths is required"));
051: }
052:
053: JTabbedPane tab = view
054: .getTabbedPane(ProjectSettingsNames.ID_PROJECT_FILES_TAB);
055: ProjectModel pmodel = view.getModel();
056: String msg = validateProject(pmodel);
057: if (msg != null) {
058: msg = I18N.getLocalizedMessage("Invalid Paths") + "\n"
059: + msg;
060: tab.setSelectedIndex(0);
061: return new RuleResult(msg);
062: }
063:
064: msg = validateClassPath(pmodel);
065: if (msg != null) {
066: msg = I18N.getLocalizedMessage("Invalid Classes Path")
067: + "\n" + msg;
068: tab.setSelectedIndex(1);
069: return new RuleResult(msg);
070: }
071:
072: File rootDir = view.getProjectRootDir();
073: if (rootDir == null || !rootDir.isDirectory()
074: || !rootDir.exists()) {
075: return new RuleResult(
076: I18N
077: .getLocalizedMessage("Invalid project path. Please verify\nthat the project directory exists."));
078: }
079:
080: return RuleResult.SUCCESS;
081: }
082:
083: public static String validateProject(ProjectModel pmodel) {
084: StringBuffer error_buff = null;
085: /** validate that all paths exist */
086: File rootDir = pmodel.getProjectRootDir();
087:
088: Collection paths = pmodel.getSourcePaths();
089: Iterator iter = paths.iterator();
090: while (iter.hasNext()) {
091: String path = (String) iter.next();
092: File projpath = new File(rootDir, path);
093: if (!projpath.isDirectory()) {
094: projpath = new File(path);
095: if (!projpath.isDirectory()) {
096: if (error_buff == null)
097: error_buff = new StringBuffer();
098: error_buff.append(projpath);
099: error_buff.append("\n");
100: }
101: }
102: }
103:
104: // FIXME: MUST VALIDATE IMPORTED PROJECT LEVEL JAVA BEANS...
105:
106: if (error_buff != null) {
107: return error_buff.toString();
108: } else {
109: return null;
110: }
111: }
112:
113: public static String validateClassPath(ProjectModel pmodel) {
114: if (pmodel.getClassPath() == null
115: || pmodel.getClassPath().length() == 0)
116: return null;
117:
118: StringBuffer error_buff = null;
119: /** validate that all paths exist */
120: File rootDir = pmodel.getProjectRootDir();
121:
122: File classpath = new File(pmodel.getClassPath());
123: if (!classpath.isDirectory()) {
124: classpath = new File(rootDir, pmodel.getClassPath());
125: if (!classpath.isDirectory()) {
126: if (error_buff == null)
127: error_buff = new StringBuffer();
128: error_buff.append(classpath);
129: error_buff.append("\n");
130: }
131: }
132:
133: if (error_buff != null) {
134: return error_buff.toString();
135: } else {
136: return null;
137: }
138: }
139:
140: }
|