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.explorer;
019:
020: import java.awt.Color;
021:
022: import javax.swing.ImageIcon;
023: import javax.swing.JTree;
024: import javax.swing.tree.DefaultMutableTreeNode;
025: import javax.swing.tree.DefaultTreeCellRenderer;
026:
027: import de.finix.contelligent.client.base.ComponentFactory;
028: import de.finix.contelligent.client.base.ComponentNotFoundException;
029: import de.finix.contelligent.client.base.ComponentReference;
030: import de.finix.contelligent.client.base.ContelligentComponent;
031: import de.finix.contelligent.client.gui.View;
032: import de.finix.contelligent.client.gui.directory.NodeNavigation;
033: import de.finix.contelligent.client.gui.directory.ProgressIndicator;
034: import de.finix.contelligent.client.i18n.Resources;
035:
036: class ExplorerCellRenderer extends DefaultTreeCellRenderer {
037:
038: private View view;
039:
040: public ExplorerCellRenderer(View view) {
041: super ();
042: this .view = view;
043: }
044:
045: public java.awt.Component getTreeCellRendererComponent(JTree tree,
046: Object value, boolean selected, boolean expanded,
047: boolean leaf, int row, boolean hasFocus) {
048:
049: super .getTreeCellRendererComponent(tree, value, selected,
050: expanded, leaf, row, hasFocus);
051:
052: setOpaque(false);
053: setIcon(closedIcon);
054:
055: if (((DefaultMutableTreeNode) value).getUserObject() instanceof ProgressIndicator) {
056: ProgressIndicator indicator = ((ProgressIndicator) ((DefaultMutableTreeNode) value)
057: .getUserObject());
058: setIcon(indicator.getIcon());
059: setText(indicator.getName());
060: return this ;
061: }
062: if (((DefaultMutableTreeNode) value).getUserObject() instanceof NodeNavigation) {
063: NodeNavigation navigation = ((NodeNavigation) ((DefaultMutableTreeNode) value)
064: .getUserObject());
065: setIcon(navigation.getIcon());
066: setText(navigation.getText());
067: return this ;
068: }
069: if (((DefaultMutableTreeNode) value).getUserObject() instanceof ComponentReference) {
070: try {
071: ContelligentComponent component = ((ComponentReference) ((DefaultMutableTreeNode) value)
072: .getUserObject()).getComponent();
073: if (component.isValid()) {
074: DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree
075: .getLastSelectedPathComponent();
076: if (selectedNode != null
077: && ((DefaultMutableTreeNode) selectedNode)
078: .getUserObject() instanceof ComponentReference) {
079: ContelligentComponent selectedComponent = ((ComponentReference) selectedNode
080: .getUserObject()).getComponent();
081: }
082:
083: ImageIcon icon = component.getSmallIcon();
084:
085: if (icon != null) {
086: if (!component.canWrite()) {
087: icon = Resources.mergeIcons(icon,
088: Resources.workAlias);
089: }
090: if (ComponentFactory.getInstance()
091: .isLockedPrivate(component)) {
092: if (ComponentFactory.getInstance()
093: .isLockedByMe(component)) {
094: icon = Resources.mergeIcons(icon,
095: Resources.lockedByMeIcon);
096: } else {
097: icon = Resources
098: .mergeIcons(
099: icon,
100: Resources.lockedBySomeoneElseIcon);
101: }
102: } else if (ComponentFactory.getInstance()
103: .isLockedInWf(component)) {
104: icon = Resources.mergeIcons(icon,
105: Resources.lockedByWfIcon);
106: } else if (ComponentFactory.getInstance()
107: .isLocked(component)) {
108: icon = Resources.mergeIcons(icon,
109: Resources.lockedBySomeoneElseIcon);
110: }
111: if (component.isReadOnly()) {
112: setForeground(Color.LIGHT_GRAY);
113: }
114: setIcon(icon);
115: }
116: } else {
117: setIcon(Resources.componentNotFoundIcon);
118: }
119: } catch (ComponentNotFoundException e) {
120: // this node references a component that does not exists
121: // anymore!
122: ((DefaultMutableTreeNode) value).setUserObject("");
123: setIcon(Resources.componentNotFoundIcon);
124: }
125: } else {
126: setText("error");
127: setIcon(Resources.componentNotFoundIcon);
128: }
129: return this;
130: }
131: }
|