001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.modules;
019:
020: import java.awt.Component;
021: import java.util.logging.Level;
022: import java.util.logging.Logger;
023:
024: import de.finix.contelligent.client.ContelligentClient;
025: import de.finix.contelligent.client.gui.ViewRegistry;
026: import de.finix.contelligent.client.util.ExceptionDialog;
027:
028: public class ModuleDescription implements Cloneable {
029:
030: public final static int LAUNCH_MODULE = 0;
031:
032: public final static int LAUNCH_BROWSER = 1;
033:
034: public final static int LAUNCH_EXECUTABLE = 2;
035:
036: public final static int LAUNCH_VIEW = 3;
037:
038: private static Logger logger = Logger
039: .getLogger(ModuleDescription.class.getName());
040:
041: private String executable, name, category, configuration, tooltip,
042: environment;
043:
044: private boolean createTab, createMenuEntry, createToolbarEntry,
045: autoOpenModule;
046:
047: private Component module;
048:
049: private int mode;
050:
051: public ModuleDescription(String executable, String name,
052: String category, String tooltip, boolean createMenuEntry,
053: boolean createToolbarEntry, boolean autoOpenModule,
054: boolean createTab, String configuration, String environment) {
055: this .executable = executable;
056: this .name = name;
057: this .category = category;
058: this .createMenuEntry = createMenuEntry;
059: this .createToolbarEntry = createToolbarEntry;
060: this .autoOpenModule = autoOpenModule;
061: this .tooltip = tooltip;
062: this .createTab = createTab;
063: this .configuration = configuration;
064: this .mode = detectMode();
065: this .environment = environment;
066: }
067:
068: public ModuleDescription(String name, String tooltip) {
069: this .name = name;
070: this .tooltip = tooltip;
071: this .createMenuEntry = false;
072: this .createToolbarEntry = false;
073: this .autoOpenModule = false;
074: this .executable = null;
075: this .category = null;
076: this .createTab = false;
077: this .configuration = null;
078: this .mode = LAUNCH_MODULE;
079: this .environment = ContelligentClient.defaultClientEnvironment;
080: }
081:
082: public Module createModule() {
083: // try to create instance of the given executable
084: try {
085: if (executable
086: .equals("de.finix.contelligent.client.modules.workflow.TaskModule")) {
087: // Obsolete module, ignore this
088: return null;
089: }
090: logger.log(Level.FINEST,
091: "generateModule(): get constructor for '"
092: + executable + "'");
093: Module module = (Module) Class.forName(executable)
094: .newInstance();
095: module.setModuleDescription(this );
096: return module;
097: } catch (ClassNotFoundException cnf) {
098: logger.log(Level.SEVERE,
099: "generateModule(): error while generating client module '"
100: + name + "'", cnf);
101: ExceptionDialog.show(cnf);
102: } catch (InstantiationException ie) {
103: logger.log(Level.SEVERE,
104: "generateModule(): error while generating client module '"
105: + name + "'", ie);
106: ExceptionDialog.show(ie);
107: } catch (IllegalAccessException iae) {
108: logger.log(Level.SEVERE,
109: "generateModule(): error while generating client module '"
110: + name + "'", iae);
111: ExceptionDialog.show(iae);
112: }
113: return null;
114: }
115:
116: public String getName() {
117: return name;
118: }
119:
120: public String getCategory() {
121: if (category == null)
122: return null;
123: return category;
124: }
125:
126: public String getTooltip() {
127: return tooltip;
128: }
129:
130: public String getExecutable() {
131: return executable;
132: }
133:
134: public String getConfiguration() {
135: return configuration;
136: }
137:
138: public boolean createMenuEntry() {
139: return createMenuEntry;
140: }
141:
142: public boolean createToolbarEntry() {
143: return createToolbarEntry;
144: }
145:
146: public boolean autoOpenModule() {
147: return autoOpenModule;
148: }
149:
150: public boolean createTab() {
151: return createTab;
152: }
153:
154: public int getMode() {
155: return mode;
156: }
157:
158: public String getEnvironment() {
159: return environment;
160: }
161:
162: private int detectMode() {
163: // detect moduleType...
164: int mode = LAUNCH_BROWSER;
165: if (ModuleRegistry.getInstance().isImplRegistered(executable)) {
166: mode = LAUNCH_MODULE;
167: } else if (ViewRegistry.getInstance().isImplRegistered(
168: executable)) {
169: mode = LAUNCH_VIEW;
170: } else if (executable != null && executable.trim().length() > 0) {
171: mode = LAUNCH_EXECUTABLE;
172: }
173: return mode;
174: }
175:
176: public Object clone() throws CloneNotSupportedException {
177: return super.clone();
178: }
179: }
|