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.gui.category;
019:
020: import java.util.logging.Level;
021: import java.util.logging.Logger;
022:
023: import javax.swing.ImageIcon;
024:
025: import de.finix.contelligent.client.gui.AbstractGUIWithCommonRendererAndEditor;
026: import de.finix.contelligent.client.gui.ComponentEditor;
027: import de.finix.contelligent.client.gui.ComposedGUI;
028: import de.finix.contelligent.client.gui.GUI;
029: import de.finix.contelligent.client.i18n.Resources;
030: import de.finix.contelligent.client.util.ExceptionDialog;
031:
032: public class CategorySensitiveGUI extends
033: AbstractGUIWithCommonRendererAndEditor implements ComposedGUI {
034:
035: private static Logger logger = Logger
036: .getLogger(CategorySensitiveGUI.class.getName());
037:
038: private Class guiClass;
039:
040: private String name;
041:
042: private int displayMode = CategorySensitiveComposedEditor.DISPLAY_MODE_MATRIX;
043:
044: private GUI gui = null;
045:
046: public void init() {
047: setResourceMode(GUI.CONTENT);
048: }
049:
050: protected ComponentEditor createEditor(boolean editable) {
051: CategorySensitiveComposedEditor editor = new CategorySensitiveComposedEditor();
052: editor.setComponent(getComponent());
053: editor.setView(getView());
054: editor.setGUI(this );
055: editor.setGUIClass(guiClass);
056: editor.setDisplayMode(displayMode);
057: editor.setEditable(editable);
058: editor.init();
059: return editor;
060: }
061:
062: public void setGUIClass(Class guiClass) {
063: this .guiClass = guiClass;
064: }
065:
066: public void setDisplayMode(int displayMode) {
067: this .displayMode = displayMode;
068: }
069:
070: public int getDisplayMode() {
071: return displayMode;
072: }
073:
074: public boolean isSupported(int type) {
075: return (type == DEFAULT || type == TABLE);
076: }
077:
078: public ImageIcon getIcon() {
079: if (assureGUIInsctanceCreated()) {
080: return gui.getIcon();
081: }
082: return Resources.htmlGUI;
083: }
084:
085: public boolean hidesSubcomponents() {
086: if (assureGUIInsctanceCreated()) {
087: return gui.hidesSubcomponents();
088: }
089: return false;
090: }
091:
092: public String getName() {
093: if (name == null) {
094: // get name
095: if (assureGUIInsctanceCreated()) {
096: name = gui.getName();
097: }
098: }
099: return name;
100: }
101:
102: private boolean assureGUIInsctanceCreated() {
103: if (gui == null) {
104: try {
105: gui = (GUI) guiClass.newInstance();
106: gui.setComponent(getComponent());
107: gui.setView(getView());
108: } catch (IllegalAccessException iae) {
109: logger.log(Level.SEVERE, "GUI [" + guiClass.getName()
110: + "] not found!", iae);
111: ExceptionDialog.show(iae);
112: return false;
113: } catch (InstantiationException ie) {
114: logger.log(Level.SEVERE, "GUI [" + guiClass.getName()
115: + "] not found!", ie);
116: ExceptionDialog.show(ie);
117: return false;
118: }
119: }
120: return true;
121: }
122: }
|