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.link;
019:
020: import java.awt.BorderLayout;
021: import java.awt.Color;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import java.awt.event.FocusAdapter;
025: import java.awt.event.FocusEvent;
026: import java.util.logging.Logger;
027:
028: import javax.swing.JComponent;
029: import javax.swing.JLabel;
030: import javax.swing.JPanel;
031: import javax.swing.JTextField;
032:
033: import de.finix.contelligent.client.base.ComponentFactory;
034: import de.finix.contelligent.client.base.ComponentNotFoundException;
035: import de.finix.contelligent.client.base.ContelligentComponent;
036: import de.finix.contelligent.client.event.ContelligentEvent;
037: import de.finix.contelligent.client.gui.AbstractComponentEditor;
038: import de.finix.contelligent.client.gui.ComponentRenderer;
039: import de.finix.contelligent.client.gui.GUI;
040: import de.finix.contelligent.client.gui.GUIFactory;
041: import de.finix.contelligent.client.gui.UnsupportedGUIException;
042: import de.finix.contelligent.client.i18n.Resources;
043: import de.finix.contelligent.client.util.dnd.JTextFieldDND;
044:
045: public class ResolverEditor extends AbstractComponentEditor {
046:
047: private static Logger logger = Logger
048: .getLogger(ResolverEditor.class.getName());
049:
050: private JTextField linkTarget;
051:
052: private JLabel linkTargetLabel;
053:
054: private JPanel rendererPanel;
055:
056: private int type;
057:
058: public void init() {
059: linkTarget = new JTextFieldDND();
060: linkTargetLabel = new JLabel();
061: rendererPanel = new JPanel(new BorderLayout());
062: rendererPanel.setOpaque(false);
063:
064: update();
065:
066: linkTarget.setEditable(isEditable());
067: JPanel linkPanel = new JPanel(new BorderLayout());
068: linkPanel.setOpaque(false);
069: linkPanel.add(linkTarget, BorderLayout.CENTER);
070: linkPanel.add(linkTargetLabel, BorderLayout.WEST);
071: add(linkPanel, BorderLayout.NORTH);
072: add(rendererPanel, BorderLayout.CENTER);
073:
074: addFocusListener(new FocusAdapter() {
075: public void focusGained(FocusEvent e) {
076: ResolverEditor.this .getView().setActions(
077: ResolverEditor.this .getActions());
078: }
079: });
080:
081: linkTarget.addActionListener(new ActionListener() {
082: public void actionPerformed(ActionEvent e) {
083: ResolverEditor.this .updateComponent();
084: ResolverEditor.this .update();
085: ResolverEditor.this .notifyListeners();
086: }
087: });
088: }
089:
090: public void setType(int type) {
091: this .type = type;
092: }
093:
094: public int getType() {
095: return type;
096: }
097:
098: public void update() {
099: String relativePath = null;
100:
101: ContelligentComponent linkedComponent = null;
102: GUI[] gui = null;
103: ComponentRenderer linkedRenderer = null;
104: JLabel noRenderer = null;
105:
106: relativePath = getComponent().getPropertyValue(
107: ContelligentComponent.RELATIVE_PATH);
108: linkTarget.setText(relativePath);
109:
110: rendererPanel.removeAll();
111:
112: // load linked component
113: try {
114: linkedComponent = ComponentFactory.getInstance()
115: .getComponent(getComponent().getPath(),
116: relativePath);
117: if (linkedComponent != getComponent()) {
118: linkTargetLabel.setIcon(Resources.mergeIcons(
119: linkedComponent.getSmallIcon(),
120: Resources.linkAlias));
121:
122: gui = GUIFactory.getInstance().getGUI(linkedComponent,
123: getView());
124: linkedRenderer = gui[0].getRenderer(getType());
125: rendererPanel.add((JComponent) linkedRenderer,
126: BorderLayout.CENTER);
127: }
128: } catch (UnsupportedGUIException e) {
129: noRenderer = new JLabel(Resources
130: .getLocalString("no_preview_error"));
131: noRenderer.setOpaque(true);
132: noRenderer.setBackground(Color.white);
133: rendererPanel.add(noRenderer, BorderLayout.CENTER);
134: } catch (ComponentNotFoundException cnfe) {
135: linkTargetLabel.setIcon(Resources.componentNotFoundIcon);
136: noRenderer = new JLabel(Resources
137: .getLocalString("invalid_link_error"));
138: noRenderer.setOpaque(true);
139: noRenderer.setBackground(Color.white);
140: noRenderer.setForeground(Color.red);
141: rendererPanel.add(noRenderer, BorderLayout.CENTER);
142: }
143: rendererPanel.validate();
144: rendererPanel.repaint();
145: }
146:
147: protected void updateComponent() {
148: getComponent().setPropertyValue(
149: ContelligentComponent.RELATIVE_PATH,
150: linkTarget.getText());
151: }
152:
153: protected void componentChanged(ContelligentEvent event) {
154: update();
155: }
156:
157: protected void childComponentAdded(ContelligentEvent event) {
158: }
159:
160: protected void childComponentRemoved(ContelligentEvent event) {
161: }
162:
163: protected void childComponentChanged(ContelligentEvent event) {
164: }
165:
166: protected void descendentComponentChanged(ContelligentEvent event) {
167: }
168:
169: public void setEditable(boolean editable) {
170: super.setEditable(editable);
171: if (linkTarget != null) {
172: linkTarget.setEditable(isEditable());
173: linkTarget.setDragEnabled(isEditable());
174: }
175: }
176: }
|