0001: // @@
0002: // @@
0003: /*
0004: * Wi.Ser Framework
0005: *
0006: * Version: 1.8.1, 20-September-2007
0007: * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
0008: *
0009: * This library is free software; you can redistribute it and/or
0010: * modify it under the terms of the GNU Lesser General Public
0011: * License as published by the Free Software Foundation; either
0012: * version 2 of the License, or (at your option) any later version.
0013: *
0014: * This library is distributed in the hope that it will be useful,
0015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0017: * Lesser General Public License for more details.
0018: *
0019: * You should have received a copy of the GNU Lesser General Public
0020: * License along with this library located in LGPL.txt in the
0021: * license directory; if not, write to the
0022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0023: * Boston, MA 02111-1307, USA.
0024: *
0025: * If this agreement does not cover your requirements, please contact us
0026: * via email to get detailed information about the commercial license
0027: * or our service offerings!
0028: *
0029: */
0030: // @@
0031: package de.ug2t.channel.ho.client.swing;
0032:
0033: import java.awt.*;
0034: import java.awt.event.*;
0035: import java.util.*;
0036:
0037: import javax.swing.*;
0038: import javax.swing.event.*;
0039: import javax.swing.tree.*;
0040:
0041: import de.ug2t.channel.ho.*;
0042: import de.ug2t.kernel.*;
0043: import de.ug2t.unifiedGui.*;
0044: import de.ug2t.unifiedGui.interfaces.*;
0045: import de.ug2t.unifiedGui.views.*;
0046: import de.ug2t.xmlScript.*;
0047:
0048: // ================================
0049:
0050: final class FlexTreeCellRenderer extends DefaultTreeCellRenderer {
0051: Icon pem_odef = this .openIcon;
0052: Icon pem_cdef = this .closedIcon;
0053: Icon pem_ldef = this .leafIcon;
0054: Font pem_stdFont = this .getFont();
0055: Color pem_defFg = this .getTextNonSelectionColor();
0056: int pem_inRender = 0;
0057:
0058: private HashMap pem_colorBuffer = new HashMap();
0059:
0060: public Icon pcmf_getOpenIcon() {
0061: return (this .openIcon);
0062: };
0063:
0064: public Icon pcmf_getCloseIcon() {
0065: return (this .closedIcon);
0066: };
0067:
0068: public Icon pcmf_getLeafIcon() {
0069: return (this .leafIcon);
0070: };
0071:
0072: public Component getTreeCellEditorComponent(JTree tree,
0073: Object value, boolean selected, boolean expanded,
0074: boolean leaf, int row, boolean hasFocus) {
0075: Component l_ret = this .getMyTreeCellRendererComponent(tree,
0076: value, selected, expanded, leaf, row, hasFocus);
0077: return (l_ret);
0078: }
0079:
0080: public Component getTreeCellRendererComponent(JTree tree,
0081: Object value, boolean selected, boolean expanded,
0082: boolean leaf, int row, boolean hasFocus) {
0083: Component l_ret = this .getMyTreeCellRendererComponent(tree,
0084: value, selected, expanded, leaf, row, hasFocus);
0085: ((EnhJTree) tree).pcmf_addPainter(l_ret);
0086:
0087: return (l_ret);
0088: }
0089:
0090: public Component getMyTreeCellRendererComponent(JTree tree,
0091: Object value, boolean selected, boolean expanded,
0092: boolean leaf, int row, boolean hasFocus) {
0093: this .pem_inRender++;
0094:
0095: KeTreeElement l_node = ((ConvertingTreeNode) value)
0096: .pcmf_getTreeElement();
0097: UnIconValueView l_view = (UnIconValueView) l_node
0098: .pcmf_getView();
0099:
0100: this .openIcon = this .pem_odef;
0101: this .closedIcon = this .pem_cdef;
0102: this .leafIcon = this .pem_ldef;
0103: this .backgroundNonSelectionColor = tree.getBackground();
0104: this .textNonSelectionColor = this .pem_defFg;
0105:
0106: super .setFont(pem_stdFont);
0107:
0108: if (l_view != null) {
0109: if (((UnIconValueView) l_view).pcmf_getBg() != null)
0110: this .setBackgroundNonSelectionColor(HoSwingComponent
0111: .pcmf_createColor(((UnIconValueView) l_view)
0112: .pcmf_getBg()));
0113: else if (l_node instanceof UnComponent)
0114: this .setBackgroundNonSelectionColor(HoSwingComponent
0115: .pcmf_createColor(((UnComponent) l_node)
0116: .pcmf_getBgColor()));
0117:
0118: if (((UnIconValueView) l_view).pcmf_getFg() != null)
0119: this .setTextNonSelectionColor(HoSwingComponent
0120: .pcmf_createColor(((UnIconValueView) l_view)
0121: .pcmf_getFg()));
0122: else if (l_node instanceof UnComponent)
0123: this .setTextNonSelectionColor(HoSwingComponent
0124: .pcmf_createColor(((UnComponent) l_node)
0125: .pcmf_getFgColor()));
0126:
0127: if (l_view.pcmf_getOpenIcon() != null)
0128: this .openIcon = ((JLabel) ((HoSwingImage) l_view
0129: .pcmf_getOpenIcon()).pcmf_getRealSwingObj())
0130: .getIcon();
0131: if (l_view.pcmf_getCloseIcon() != null)
0132: this .closedIcon = ((JLabel) ((HoSwingImage) l_view
0133: .pcmf_getCloseIcon()).pcmf_getRealSwingObj())
0134: .getIcon();
0135: if (l_view.pcmf_getStdIcon() != null)
0136: this .leafIcon = ((JLabel) ((HoSwingImage) l_view
0137: .pcmf_getStdIcon()).pcmf_getRealSwingObj())
0138: .getIcon();
0139:
0140: UnFontDescriptor l_font = l_view.pcmf_getFontDesc();
0141: if (l_font != null)
0142: super .setFont(new Font(l_font.pcmf_getFontName(),
0143: l_font.pcmf_getFontStyle(), l_font
0144: .pcmf_getFontSize()));
0145: }
0146: ;
0147:
0148: Object l_deref = null;
0149: Object l_val = l_node.pcmf_getValue();
0150: if (l_val != null
0151: && (l_deref = KeTools.pcmf_deRefObj(l_val.toString())) instanceof HoSwingComponent)
0152: l_node = (KeTreeElement) l_deref;
0153:
0154: if (l_node instanceof HoSwingComponent
0155: && l_node instanceof HoSwingTreeView == false) {
0156: if (this .pem_inRender < 10) {
0157: Rectangle l_rect = tree.getRowBounds(row);
0158: if (l_rect != null) {
0159: MouseListener[] l_listen = ((HoSwingComponent) l_node)
0160: .pcmf_getRealSwingObj().getMouseListeners();
0161: for (int i = 0; i < l_listen.length; i++)
0162: if (l_listen[i] instanceof HoPopUpEventDispatcher)
0163: ((HoSwingComponent) l_node)
0164: .pcmf_getRealSwingObj()
0165: .removeMouseListener(l_listen[i]);
0166:
0167: if (leaf)
0168: ((HoSwingComponent) l_node)
0169: .pcmf_getRealSwingObj()
0170: .addMouseListener(
0171: new HoPopUpEventDispatcher(
0172: tree,
0173: l_rect.getLocation().y,
0174: this .leafIcon
0175: .getIconWidth()));
0176: else if (expanded)
0177: ((HoSwingComponent) l_node)
0178: .pcmf_getRealSwingObj()
0179: .addMouseListener(
0180: new HoPopUpEventDispatcher(
0181: tree,
0182: l_rect.getLocation().y,
0183: this .openIcon
0184: .getIconWidth()));
0185: else
0186: ((HoSwingComponent) l_node)
0187: .pcmf_getRealSwingObj()
0188: .addMouseListener(
0189: new HoPopUpEventDispatcher(
0190: tree,
0191: l_rect.getLocation().y,
0192: this .closedIcon
0193: .getIconWidth()));
0194: }
0195: }
0196:
0197: FlowLayout l_layout = new FlowLayout(FlowLayout.TRAILING,
0198: 0, 0);
0199: JPanel l_panel = new JPanel(l_layout);
0200: JLabel l_label = new JLabel();
0201: l_label.setFont(super .getFont());
0202: l_label.setHorizontalAlignment(JLabel.LEFT);
0203:
0204: if (l_view != null) {
0205: if (((UnIconValueView) l_view).pcmf_getBg() != null)
0206: l_label
0207: .setBackground(HoSwingComponent
0208: .pcmf_createColor(((UnIconValueView) l_view)
0209: .pcmf_getBg()));
0210: if (((UnIconValueView) l_view).pcmf_getFg() != null)
0211: l_label
0212: .setForeground(HoSwingComponent
0213: .pcmf_createColor(((UnIconValueView) l_view)
0214: .pcmf_getFg()));
0215:
0216: if (l_view.pcmf_getOpenIcon() != null && expanded)
0217: l_label
0218: .setIcon(((JLabel) ((HoSwingImage) l_view
0219: .pcmf_getOpenIcon())
0220: .pcmf_getRealSwingObj()).getIcon());
0221: else if (l_view.pcmf_getCloseIcon() != null
0222: && !expanded)
0223: l_label.setIcon(((JLabel) ((HoSwingImage) l_view
0224: .pcmf_getCloseIcon())
0225: .pcmf_getRealSwingObj()).getIcon());
0226: else if (l_view.pcmf_getStdIcon() != null && leaf)
0227: l_label.setIcon(((JLabel) ((HoSwingImage) l_view
0228: .pcmf_getStdIcon()).pcmf_getRealSwingObj())
0229: .getIcon());
0230:
0231: UnFontDescriptor l_font = l_view.pcmf_getFontDesc();
0232: if (l_font != null)
0233: super .setFont(new Font(l_font.pcmf_getFontName(),
0234: l_font.pcmf_getFontStyle(), l_font
0235: .pcmf_getFontSize()));
0236: }
0237: ;
0238:
0239: ((HoSwingComponent) l_node).pcmf_getRealSwingObj().setFont(
0240: super .getFont());
0241: l_panel.add(l_label);
0242: l_panel.add(((HoSwingComponent) l_node)
0243: .pcmf_getRealSwingObj());
0244:
0245: if (selected) {
0246: // Selected
0247: if ((HoSwingColorBuffer) this .pem_colorBuffer
0248: .get(l_node) == null) {
0249: l_label.setBackground(super
0250: .getBackgroundSelectionColor());
0251: l_label
0252: .setForeground(super
0253: .getTextSelectionColor());
0254:
0255: this .pem_colorBuffer
0256: .put(
0257: l_node,
0258: new HoSwingColorBuffer(
0259: ((HoSwingComponent) l_node)
0260: .pcmf_getRealSwingObj()
0261: .getForeground(),
0262: ((HoSwingComponent) l_node)
0263: .pcmf_getRealSwingObj()
0264: .getBackground(),
0265: ((JComponent) ((HoSwingComponent) l_node)
0266: .pcmf_getRealSwingObj())
0267: .isOpaque()));
0268: ((HoSwingComponent) l_node)
0269: .pcmf_getRealSwingObj()
0270: .setBackground(
0271: super .getBackgroundSelectionColor());
0272: ((HoSwingComponent) l_node).pcmf_getRealSwingObj()
0273: .setForeground(
0274: super .getTextSelectionColor());
0275: ((JComponent) ((HoSwingComponent) l_node)
0276: .pcmf_getRealSwingObj()).setOpaque(true);
0277: }
0278: } else if (!selected) {
0279: // Unselected
0280: l_label.setBackground(super
0281: .getBackgroundNonSelectionColor());
0282: l_label.setForeground(super .getTextNonSelectionColor());
0283:
0284: HoSwingColorBuffer l_cb = (HoSwingColorBuffer) this .pem_colorBuffer
0285: .remove(l_node);
0286: if (l_cb != null) {
0287: ((HoSwingComponent) l_node).pcmf_getRealSwingObj()
0288: .setBackground(l_cb.pcmf_getBg());
0289: ((HoSwingComponent) l_node).pcmf_getRealSwingObj()
0290: .setForeground(l_cb.pcmf_getFg());
0291: ((JComponent) ((HoSwingComponent) l_node)
0292: .pcmf_getRealSwingObj()).setOpaque(l_cb
0293: .pcmf_getOp());
0294: }
0295: }
0296:
0297: l_panel.setOpaque(false);
0298:
0299: tree.setRowHeight(l_panel.getPreferredSize().height > tree
0300: .getRowHeight() ? l_panel.getPreferredSize().height
0301: : tree.getRowHeight());
0302:
0303: this .pem_inRender--;
0304:
0305: return (l_panel);
0306: }
0307:
0308: return super .getTreeCellRendererComponent(tree, value,
0309: selected, expanded, leaf, row, hasFocus);
0310: }
0311:
0312: public void pcmf_resetAllColors() {
0313: Iterator l_it = this .pem_colorBuffer.keySet().iterator();
0314: while (l_it.hasNext()) {
0315: HoSwingComponent l_obj = (HoSwingComponent) l_it.next();
0316: HoSwingColorBuffer l_cb = (HoSwingColorBuffer) this .pem_colorBuffer
0317: .get(l_obj);
0318:
0319: l_obj.pcmf_getRealSwingObj().setBackground(
0320: l_cb.pcmf_getBg());
0321: l_obj.pcmf_getRealSwingObj().setForeground(
0322: l_cb.pcmf_getFg());
0323: ((JComponent) l_obj.pcmf_getRealSwingObj()).setOpaque(l_cb
0324: .pcmf_getOp());
0325: }
0326: }
0327: };
0328:
0329: final class EnhJTree extends JTree {
0330: private Dimension pem_minW = null;
0331: protected FlexTreeCellRenderer pdm_defEdit = new FlexTreeCellRenderer();
0332: private HoSwingTreeView pem_myTree = null;
0333: private ArrayList pem_painters = new ArrayList();
0334:
0335: protected void pcmf_setMyView(HoSwingTreeView xView) {
0336: this .pem_myTree = xView;
0337: };
0338:
0339: public EnhJTree() {
0340: super ();
0341: pem_minW = this .getPreferredScrollableViewportSize();
0342: };
0343:
0344: public EnhJTree(TreeNode xNode) {
0345: super (xNode);
0346: pem_minW = this .getPreferredScrollableViewportSize();
0347: };
0348:
0349: public EnhJTree(TreeModel xModel) {
0350: super (xModel);
0351: pem_minW = this .getPreferredScrollableViewportSize();
0352: };
0353:
0354: public void pcmf_resize() {
0355: // Aktuelle Weite bei bedarf anpassen (nie kleiner als Anfangsweite)
0356: // beibehalten
0357: this .setPreferredSize(null);
0358:
0359: int l_actW = (int) this .getPreferredScrollableViewportSize()
0360: .getWidth();
0361: int l_stW = (int) this .pem_minW.getWidth();
0362:
0363: // Wenn keine eindeutige Höhe vorliegt anhand der ersten Zeile schätzen
0364: if (this .getRowHeight() <= 0) {
0365: this .setPreferredSize(new Dimension(l_actW > l_stW ? l_actW
0366: : l_stW, (int) (this .getRowCount()
0367: * this .getRowBounds(0).getHeight() * 1.2)));
0368: } else {
0369: this .setPreferredSize(new Dimension(l_actW > l_stW ? l_actW
0370: : l_stW, this .getRowCount() * this .getRowHeight()));
0371: }
0372: };
0373:
0374: public TreeCellEditor getCellEditor() {
0375: TreeCellEditor l_edit = new TreeCellEditor() {
0376: private JTree pem_tree = null;
0377: private KeTreeElement pem_obj = null;
0378:
0379: public Component getTreeCellEditorComponent(JTree tree,
0380: Object value, boolean isSelected, boolean expanded,
0381: boolean leaf, int row) {
0382: this .pem_tree = tree;
0383: this .pem_obj = ((ConvertingTreeNode) value)
0384: .pcmf_getTreeElement();
0385: Object l_deref = null;
0386: if (this .pem_obj.pcmf_getValue() != null
0387: && (l_deref = KeTools
0388: .pcmf_deRefObj(this .pem_obj
0389: .pcmf_getValue().toString())) instanceof HoSwingComponent)
0390: this .pem_obj = (KeTreeElement) l_deref;
0391:
0392: if (pem_obj instanceof HoSwingComponent
0393: && pem_obj instanceof HoSwingTreeView == false)
0394: return (((EnhJTree) tree).pdm_defEdit
0395: .getTreeCellEditorComponent(tree, value,
0396: true, expanded, leaf, row, true));
0397: else
0398: return (new FlexTreeCellRenderer()
0399: .getTreeCellEditorComponent(tree, value,
0400: true, expanded, leaf, row, true));
0401: };
0402:
0403: // Add a listener to the list that's notified when the editor starts,
0404: // stops, or cancels editing.
0405: public void addCellEditorListener(CellEditorListener l) {
0406: return;
0407: };
0408:
0409: // Tell the editor to cancel editing and not accept any partially edited
0410: // value.
0411: public void cancelCellEditing() {
0412: this .pem_tree.setCellEditor(null);
0413: return;
0414: };
0415:
0416: // Returns the value contained in the editor
0417: public Object getCellEditorValue() {
0418: return (this .pem_obj.pcmf_getValue());
0419: };
0420:
0421: // Ask the editor if it can start editing using anEvent.
0422: public boolean isCellEditable(EventObject anEvent) {
0423: return (true);
0424: };
0425:
0426: // Remove a listener from the list that's notified
0427: public void removeCellEditorListener(CellEditorListener l) {
0428: return;
0429: };
0430:
0431: // The return value of shouldSelectCell() is a boolean indicating whether
0432: // the editing cell should be selected or not.
0433: public boolean shouldSelectCell(EventObject anEvent) {
0434: return (true);
0435: };
0436:
0437: public boolean stopCellEditing() {
0438: this .pem_tree.setCellEditor(null);
0439: return (true);
0440: };
0441: };
0442: return (l_edit);
0443: };
0444:
0445: public void paint(Graphics g) {
0446: this .pcmf_resize();
0447: super .paint(g);
0448: this .pemf_clearPainters();
0449: }
0450:
0451: public void pcmf_addPainter(Component xPainter) {
0452: this .pem_painters.add(xPainter);
0453:
0454: return;
0455: }
0456:
0457: private void pemf_clearPainters() {
0458: Iterator l_it = this .pem_painters.iterator();
0459: while (l_it.hasNext()) {
0460: Component l_comp = (Component) l_it.next();
0461: Container l_p = l_comp.getParent();
0462: if (l_p != null)
0463: l_p.remove(l_comp);
0464: }
0465: this .pem_painters.clear();
0466: }
0467:
0468: protected void finalize() throws Throwable {
0469: this .pemf_clearPainters();
0470: super .finalize();
0471: }
0472:
0473: protected void pdmf_commitTree() {
0474: synchronized (this .pem_myTree) {
0475: this .pem_myTree.pdm_inSpEvents = true;
0476: }
0477: ;
0478:
0479: KeTreeNode l_node = null;
0480: for (int i = 0; i < this .getRowCount(); i++) {
0481: this .expandRow(i);
0482: l_node = (KeTreeNode) ((ConvertingTreeNode) this
0483: .getPathForRow(i).getLastPathComponent())
0484: .pcmf_getTreeElement();
0485: if (l_node.pcmf_isHidden())
0486: this .collapseRow(i);
0487: }
0488: ;
0489: this .pcmf_resize();
0490:
0491: int l_srows[] = this .getSelectionRows();
0492: if (l_srows != null && l_srows.length > 0)
0493: this .scrollRowToVisible(l_srows[0]);
0494:
0495: synchronized (this .pem_myTree) {
0496: this .pem_myTree.pdm_inSpEvents = false;
0497: }
0498: ;
0499: };
0500:
0501: public void pcmf_commitTree() {
0502: synchronized (this .pem_myTree) {
0503: this .pem_myTree.pdm_inSpEvents = true;
0504: }
0505: ;
0506:
0507: if (this .pem_myTree.pdm_multiSelection == false) {
0508: TreePath l_selection = this .pem_myTree.pdm_swingObj
0509: .getSelectionPath();
0510:
0511: this .pem_myTree.pdm_swingObj.stopEditing();
0512: this .pem_myTree.pdm_model.reload();
0513: this .pdm_defEdit.pcmf_resetAllColors();
0514: pdm_defEdit = new FlexTreeCellRenderer();
0515: this .setCellRenderer(this .pdm_defEdit);
0516:
0517: this .pem_myTree.pdm_swingObj.setSelectionPath(l_selection);
0518: } else {
0519: TreePath l_selection[] = this .pem_myTree.pdm_swingObj
0520: .getSelectionPaths();
0521:
0522: this .pem_myTree.pdm_swingObj.stopEditing();
0523: this .pem_myTree.pdm_model.reload();
0524: this .pdm_defEdit.pcmf_resetAllColors();
0525: pdm_defEdit = new FlexTreeCellRenderer();
0526: this .setCellRenderer(this .pdm_defEdit);
0527:
0528: if (l_selection == null)
0529: this .pem_myTree.pdm_swingObj.setSelectionPath(null);
0530: else
0531: for (int i = 0; i < l_selection.length; i++)
0532: this .pem_myTree.pdm_swingObj
0533: .addSelectionPath(l_selection[i]);
0534: }
0535:
0536: KeTreeNode l_node = null;
0537: for (int i = 0; i < this .getRowCount(); i++) {
0538: this .expandRow(i);
0539: l_node = (KeTreeNode) ((ConvertingTreeNode) this
0540: .getPathForRow(i).getLastPathComponent())
0541: .pcmf_getTreeElement();
0542: if (l_node.pcmf_isHidden())
0543: this .collapseRow(i);
0544: }
0545: ;
0546:
0547: this .pcmf_resize();
0548: this .repaint();
0549:
0550: synchronized (this .pem_myTree) {
0551: this .pem_myTree.pdm_inSpEvents = false;
0552: }
0553: ;
0554: };
0555: };
0556:
0557: // ================================
0558:
0559: public final class HoSwingTreeView extends HoSwingComponent implements
0560: IUnTreeView {
0561: protected EnhJTree pdm_swingObj = null;
0562: protected boolean pdm_multiSelection = false;
0563: protected HoGenericDataContainer pdm_container = null;
0564:
0565: private JScrollPane pem_pane = null;
0566: private TreeSelectionModel pem_selMod = null;
0567: private ConvertingTreeNode pem_rootNode = null;
0568: protected DefaultTreeModel pdm_model = null;
0569: protected KeTreeNode pdm_toggled = null;
0570: protected boolean pdm_inSpEvents = false;
0571:
0572: public void pcmf_commitTree() {
0573: this .pdm_swingObj.pcmf_commitTree();
0574: };
0575:
0576: public boolean pcmf_setMultiSelection(boolean xMulti) {
0577: boolean l_old = this .pdm_multiSelection;
0578:
0579: if (xMulti == true && this .pdm_container != null) {
0580: this .pdm_multiSelection = xMulti;
0581: this .pem_selMod
0582: .setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
0583: this .pdm_swingObj.setEditable(false);
0584: } else {
0585: this .pdm_multiSelection = false;
0586: this .pdm_swingObj.setEditable(true);
0587: this .pem_selMod
0588: .setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
0589: }
0590:
0591: return (l_old);
0592: };
0593:
0594: public boolean pcmf_setMultiSelection(HoGenericDataContainer xCont) {
0595: boolean l_old = this .pdm_multiSelection;
0596:
0597: if (xCont != null) {
0598: this .pdm_multiSelection = true;
0599: this .pdm_container = xCont;
0600: this .pem_selMod
0601: .setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
0602: this .pdm_swingObj.setEditable(false);
0603: }
0604:
0605: return (l_old);
0606: };
0607:
0608: public boolean pcmf_isMultiSelection() {
0609: return (this .pdm_multiSelection);
0610: }
0611:
0612: public HoSwingTreeView(String xName, KeTreeNode xRoot,
0613: IUnApplication xAppl) throws Exception {
0614: super (xName, xAppl);
0615:
0616: if (xRoot != null)
0617: pem_rootNode = new ConvertingTreeNode(xRoot);
0618: else
0619: pem_rootNode = new ConvertingTreeNode(this );
0620:
0621: this .pdm_model = new DefaultTreeModel(pem_rootNode);
0622: this .pdm_swingObj = new EnhJTree(pdm_model);
0623: ((EnhJTree) this .pdm_swingObj).pcmf_setMyView(this );
0624: this .pem_pane = new JScrollPane(this .pdm_swingObj);
0625: super .pdm_realSwingCmp = this .pem_pane;
0626: this .pcmf_setEventOnChange(true);
0627:
0628: this .pem_pane.getViewport().setScrollMode(
0629: JViewport.BACKINGSTORE_SCROLL_MODE);
0630:
0631: this .pem_selMod = this .pdm_swingObj.getSelectionModel();
0632: this .pcmf_setLocalValue(this .pem_rootNode.pcmf_getTreeElement()
0633: .pcmf_getValue());
0634: this .pem_selMod
0635: .setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
0636: this .pdm_swingObj.setEditable(true);
0637: this .pdm_swingObj.setScrollsOnExpand(true);
0638: this .pdm_swingObj
0639: .setCellRenderer(this .pdm_swingObj.pdm_defEdit);
0640: ((HoSwingClient) xAppl).pcmf_addKeyDispatcher(this );
0641:
0642: this .pemf_addScrollListeners();
0643:
0644: final MouseAdapter l_mouseAd = new HoMouseAdapter() {
0645: public void mousePressed(MouseEvent e) {
0646: if (e.getModifiers() == InputEvent.BUTTON3_MASK
0647: && !e.isControlDown())
0648: HoSwingTreeView.this .pdm_swingObj
0649: .setSelectionRow(HoSwingTreeView.this .pdm_swingObj
0650: .getRowForLocation(e.getX(), e
0651: .getY()));
0652: else if (e.getModifiers() == (InputEvent.BUTTON3_MASK | InputEvent.CTRL_MASK)
0653: && HoSwingTreeView.this .pdm_multiSelection)
0654: HoSwingTreeView.this .pdm_swingObj
0655: .addSelectionRow(HoSwingTreeView.this .pdm_swingObj
0656: .getRowForLocation(e.getX(), e
0657: .getY()));
0658:
0659: return;
0660: }
0661: };
0662: this .pdm_swingObj.addMouseListener(l_mouseAd);
0663:
0664: final TreeExpansionListener l_el = new TreeExpansionListener() {
0665: public void treeExpanded(TreeExpansionEvent event) {
0666: synchronized (HoSwingTreeView.this ) {
0667: if (HoSwingTreeView.this .pdm_inSpEvents)
0668: return;
0669: }
0670: try {
0671: String l_objName = HoSwingTreeView.this
0672: .pcmf_getObjName();
0673:
0674: HoSwingTreeView.this .pdm_swingObj.pcmf_resize();
0675:
0676: ConvertingTreeNode l_exObj = (ConvertingTreeNode) event
0677: .getPath().getLastPathComponent();
0678: if (l_exObj == null)
0679: return;
0680:
0681: KeTreeElement l_node = l_exObj
0682: .pcmf_getTreeElement();
0683: if (l_node instanceof KeTreeNode)
0684: ((KeTreeNode) l_node).pcmf_unhide();
0685:
0686: HoSwingTreeView.this .pdm_toggled = (KeTreeNode) l_exObj
0687: .pcmf_getTreeElement();
0688: HoSwingTreeView.this .pcmf_setRefresh();
0689: HoSwingTreeView.this .pcmf_dispatchEvent();
0690:
0691: if (HoSwingTreeView.this .pem_session
0692: .pcmf_isDisabled())
0693: return;
0694:
0695: // Werte setzen um diese zum Server zu übertragen
0696: ((HoSwingPage) HoSwingTreeView.this .pcmf_getAppl()
0697: .pcmf_getActive()).pcmf_setSubmitValue(
0698: l_objName, "O" + l_node.pcmf_getObjName());
0699: // HoSwingTreeView.this.pcmf_addSyncedWidgets((HoSwingPage)HoSwingTreeView.this.pcmf_getAppl().pcmf_getActive(),
0700: // HoSwingTreeView.this);
0701: if (HoSwingTreeView.this .pcmf_getUnComponent()
0702: .pcmf_isSubmit() == true)
0703: ((HoSwingPage) HoSwingTreeView.this
0704: .pcmf_getAppl().pcmf_getActive())
0705: .pcmf_submit();
0706: } catch (Exception e) {
0707: KeLog.pcmf_logException("ug2t", this , e);
0708: }
0709: };
0710:
0711: public void treeCollapsed(TreeExpansionEvent event) {
0712: synchronized (HoSwingTreeView.this ) {
0713: if (HoSwingTreeView.this .pdm_inSpEvents)
0714: return;
0715: }
0716: try {
0717: String l_objName = HoSwingTreeView.this
0718: .pcmf_getObjName();
0719:
0720: HoSwingTreeView.this .pdm_swingObj.pcmf_resize();
0721:
0722: ConvertingTreeNode l_exObj = (ConvertingTreeNode) event
0723: .getPath().getLastPathComponent();
0724: if (l_exObj == null)
0725: return;
0726:
0727: KeTreeElement l_node = l_exObj
0728: .pcmf_getTreeElement();
0729: if (l_node instanceof KeTreeNode)
0730: ((KeTreeNode) l_node).pcmf_hide();
0731:
0732: HoSwingTreeView.this .pdm_toggled = (KeTreeNode) l_exObj
0733: .pcmf_getTreeElement();
0734: HoSwingTreeView.this .pcmf_setRefresh();
0735: HoSwingTreeView.this .pcmf_dispatchEvent();
0736:
0737: if (HoSwingTreeView.this .pem_session
0738: .pcmf_isDisabled())
0739: return;
0740:
0741: // Werte setzen um diese zum Server zu übertragen
0742: ((HoSwingPage) HoSwingTreeView.this .pcmf_getAppl()
0743: .pcmf_getActive()).pcmf_setSubmitValue(
0744: l_objName, "C" + l_node.pcmf_getObjName());
0745: // HoSwingTreeView.this.pcmf_addSyncedWidgets((HoSwingPage)HoSwingTreeView.this.pcmf_getAppl().pcmf_getActive(),
0746: // HoSwingTreeView.this);
0747: if (HoSwingTreeView.this .pcmf_getUnComponent()
0748: .pcmf_isSubmit() == true)
0749: ((HoSwingPage) HoSwingTreeView.this
0750: .pcmf_getAppl().pcmf_getActive())
0751: .pcmf_submit();
0752: } catch (Exception e) {
0753: KeLog.pcmf_logException("ug2t", this , e);
0754: }
0755: };
0756: };
0757:
0758: this .pdm_swingObj.addTreeExpansionListener(l_el);
0759:
0760: final TreeSelectionListener l_f = new TreeSelectionListener() {
0761: public void valueChanged(TreeSelectionEvent e) {
0762: synchronized (HoSwingTreeView.this ) {
0763: // No Client side event dispatching if session is disabled - for
0764: // selection events!
0765: if (HoSwingTreeView.this .pdm_inSpEvents
0766: || HoSwingTreeView.this .pem_session
0767: .pcmf_isDisabled())
0768: return;
0769: }
0770: try {
0771: HoSwingTreeView.this .pdm_swingObj.pcmf_resize();
0772: String l_objName = HoSwingTreeView.this
0773: .pcmf_getObjName();
0774: // Lokale Listener aufrufen, Werte setzen
0775: if (HoSwingTreeView.this .pdm_multiSelection == false) {
0776: TreePath l_selection = HoSwingTreeView.this .pdm_swingObj
0777: .getSelectionPath();
0778: if (l_selection == null) {
0779: HoSwingTreeView.this .pdm_swingObj
0780: .clearSelection();
0781: return;
0782: }
0783: ;
0784:
0785: ConvertingTreeNode l_selObj = (ConvertingTreeNode) l_selection
0786: .getLastPathComponent();
0787:
0788: HoSwingTreeView.this
0789: .pcmf_setLocalValue(l_selObj
0790: .pcmf_getTreeElement());
0791: } else {
0792: TreePath l_selection[] = HoSwingTreeView.this .pdm_swingObj
0793: .getSelectionPaths();
0794: if (l_selection == null) {
0795: HoSwingTreeView.this .pdm_swingObj
0796: .clearSelection();
0797: return;
0798: }
0799: ;
0800:
0801: ConvertingTreeNode l_selObj = null;
0802:
0803: ArrayList l_values = new ArrayList();
0804: for (int i = 0; i < l_selection.length; i++) {
0805: l_selObj = (ConvertingTreeNode) l_selection[i]
0806: .getLastPathComponent();
0807: l_values
0808: .add(l_selObj.pcmf_getTreeElement());
0809: }
0810: HoSwingTreeView.this .pdm_container
0811: .pcmf_setRemoteValueObjects_C2S(l_values);
0812:
0813: HoSwingTreeView.this
0814: .pcmf_setLocalValue(HoSwingTreeView.this .pdm_container);
0815: }
0816: HoSwingTreeView.this .pcmf_setRefresh();
0817: HoSwingTreeView.this .pcmf_dispatchEvent();
0818:
0819: // Werte setzen um diese zum Server zu übertragen
0820: ((HoSwingPage) HoSwingTreeView.this .pcmf_getAppl()
0821: .pcmf_getActive())
0822: .pcmf_setSubmitValue(
0823: l_objName,
0824: "M"
0825: + ((KeRegisteredObject) HoSwingTreeView.this
0826: .pcmf_getValue())
0827: .pcmf_getObjName());
0828: HoSwingTreeView.this .pcmf_addSyncedWidgets(
0829: (HoSwingPage) HoSwingTreeView.this
0830: .pcmf_getAppl().pcmf_getActive(),
0831: HoSwingTreeView.this );
0832: if (HoSwingTreeView.this .pcmf_getUnComponent()
0833: .pcmf_isSubmit() == true)
0834: ((HoSwingPage) HoSwingTreeView.this
0835: .pcmf_getAppl().pcmf_getActive())
0836: .pcmf_submit();
0837:
0838: HoSwingTreeView.this .pdm_swingObj.repaint();
0839: } catch (Exception ex) {
0840: KeLog.pcmf_logException("ug2t", this , ex);
0841: }
0842: ;
0843: };
0844: };
0845: this .pem_selMod.addTreeSelectionListener(l_f);
0846:
0847: return;
0848: };
0849:
0850: private void pemf_addScrollListeners() {
0851: AdjustmentListener l_listen = new AdjustmentListener() {
0852: private int pem_x = 0;
0853: private int pem_y = 0;
0854: private HoDelayedCall pem_call = null;
0855:
0856: public void adjustmentValueChanged(AdjustmentEvent e) {
0857: if (this .pem_x == HoSwingTreeView.this .pem_pane
0858: .getHorizontalScrollBar().getValue()
0859: && this .pem_y == HoSwingTreeView.this .pem_pane
0860: .getVerticalScrollBar().getValue())
0861: return;
0862:
0863: if (pem_session != null) {
0864: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
0865: "");
0866:
0867: if (HoSwingTreeView.this .pem_session
0868: .pcmf_isInTransaction()) {
0869: ScXmlScript.pcmf_createPBody(l_remCall);
0870: } else {
0871: ScXmlScript.pcmf_createxScriptString(l_remCall,
0872: null);
0873: ScXmlScript.pcmf_addProc(l_remCall, null);
0874: }
0875: ;
0876:
0877: this .pem_x = HoSwingTreeView.this .pem_pane
0878: .getHorizontalScrollBar().getValue();
0879: this .pem_y = HoSwingTreeView.this .pem_pane
0880: .getVerticalScrollBar().getValue();
0881:
0882: ScXmlScript.pcmf_addCall(l_remCall, null,
0883: HoSwingTreeView.this .pcmf_getObjName(),
0884: "pcmf_setScrollInfo");
0885: ScXmlScript.pcmf_addCallPar(l_remCall, Integer
0886: .toString(this .pem_x), "false", "int");
0887: ScXmlScript.pcmf_addCallPar(l_remCall, Integer
0888: .toString(this .pem_y), "false", "int");
0889: ScXmlScript.pcmf_endAll(l_remCall);
0890:
0891: if (this .pem_call == null
0892: || this .pem_call.pcmf_isReady())
0893: this .pem_call = new HoDelayedCall(l_remCall
0894: .toString(),
0895: HoSwingTreeView.this .pem_session,
0896: IUnComponent.EVENT_LATENCY_SCROLL,
0897: HoSwingTreeView.this , false);
0898: else
0899: this .pem_call.pcmf_refreshCall(l_remCall
0900: .toString());
0901: }
0902: ;
0903: }
0904: };
0905: this .pem_pane.getHorizontalScrollBar().addAdjustmentListener(
0906: l_listen);
0907: this .pem_pane.getVerticalScrollBar().addAdjustmentListener(
0908: l_listen);
0909: }
0910:
0911: public void pcmf_setValues(HoGenericDataContainer xValues) {
0912: this .pcmf_setValue(xValues);
0913: }
0914:
0915: public void pcmf_setEditable(boolean xEditable) {
0916: this .pdm_swingObj.setEditable(xEditable);
0917: }
0918:
0919: public void pcmf_setValue(Object xValue) {
0920: this .pcmf_commitTree();
0921:
0922: this .pdm_swingObj.clearSelection();
0923:
0924: if (xValue != null) {
0925: if (this .pdm_multiSelection == false) {
0926: KeTreeElement l_element = null;
0927:
0928: if (xValue instanceof KeTreeElement)
0929: l_element = (KeTreeElement) xValue;
0930: else
0931: l_element = (KeTreeElement) KeRegisteredObject
0932: .pcmf_getObjByName(xValue.toString());
0933:
0934: this .pcmf_getUnComponent()
0935: .pcmf_setLocalValue(l_element);
0936:
0937: ArrayList l_el = new ArrayList();
0938: l_el.add(this .pem_rootNode.pcmf_getTreeElement());
0939: ((KeTreeNode) this .pem_rootNode.pcmf_getTreeElement())
0940: .pcmf_deepSubNodeVector(l_el);
0941:
0942: int l_idx = l_el.indexOf(l_element);
0943: for (int i = 0; i < l_idx; i++)
0944: this .pdm_swingObj.expandRow(i);
0945:
0946: this .pdm_swingObj.setSelectionRow(l_idx);
0947: this .pdm_swingObj.scrollRowToVisible(l_idx);
0948: } else {
0949: KeTreeElement l_element = null;
0950: Object l_obj = null;
0951:
0952: if (xValue instanceof KeTreeElement) {
0953: l_obj = xValue;
0954: this .pcmf_getUnComponent().pcmf_setLocalValue(
0955: l_element);
0956: } else if (xValue instanceof HoGenericDataContainer) {
0957: l_obj = xValue;
0958: this .pcmf_getUnComponent()
0959: .pcmf_setLocalValue(l_obj);
0960: } else {
0961: l_obj = KeRegisteredObject.pcmf_getObjByName(xValue
0962: .toString());
0963: this .pcmf_getUnComponent()
0964: .pcmf_setLocalValue(l_obj);
0965: }
0966: if (l_obj instanceof HoGenericDataContainer) {
0967: int l_idx = 0;
0968: ArrayList l_el = new ArrayList();
0969: l_el.add(this .pem_rootNode.pcmf_getTreeElement());
0970: ((KeTreeNode) this .pem_rootNode
0971: .pcmf_getTreeElement())
0972: .pcmf_deepSubNodeVector(l_el);
0973:
0974: ArrayList l_values = ((HoGenericDataContainer) l_obj)
0975: .pcmf_getValueArray();
0976: Iterator l_it = l_values.iterator();
0977: Object l_mobj = null;
0978: int l_selRow = 0;
0979: int l_selRows[] = new int[l_values.size()];
0980: while (l_it.hasNext()) {
0981: l_mobj = l_it.next();
0982:
0983: if (l_mobj instanceof KeTreeElement)
0984: l_element = (KeTreeElement) l_mobj;
0985: else
0986: l_element = (KeTreeElement) KeRegisteredObject
0987: .pcmf_getObjByName(l_mobj
0988: .toString());
0989:
0990: l_idx = l_el.indexOf(l_element);
0991: for (int i = 0; i < l_idx; i++)
0992: this .pdm_swingObj.expandRow(i);
0993:
0994: l_selRows[l_selRow++] = l_idx;
0995: }
0996: this .pdm_swingObj.setSelectionRows(l_selRows);
0997: this .pdm_swingObj.scrollRowToVisible(l_idx);
0998: } else {
0999: l_element = (KeTreeElement) l_obj;
1000: ArrayList l_el = new ArrayList();
1001: l_el.add(this .pem_rootNode.pcmf_getTreeElement());
1002: ((KeTreeNode) this .pem_rootNode
1003: .pcmf_getTreeElement())
1004: .pcmf_deepSubNodeVector(l_el);
1005:
1006: int l_idx = l_el.indexOf(l_element);
1007: for (int i = 0; i < l_idx; i++)
1008: this .pdm_swingObj.expandRow(i);
1009:
1010: this .pdm_swingObj.setSelectionRow(l_idx);
1011: this .pdm_swingObj.scrollRowToVisible(l_idx);
1012: }
1013: }
1014: }
1015:
1016: this .pcmf_commitTree();
1017:
1018: return;
1019: };
1020:
1021: public void pcmf_disable() {
1022: this .pdm_swingObj.setEnabled(false);
1023: super .pcmf_disable();
1024: return;
1025: };
1026:
1027: public void pcmf_enable() {
1028: this .pdm_swingObj.setEnabled(true);
1029: super .pcmf_enable();
1030: return;
1031: };
1032:
1033: public void pcmf_setFgColor(String xCol) {
1034: try {
1035: this .pdm_swingObj.setForeground(HoSwingComponent
1036: .pcmf_createColor(xCol));
1037:
1038: super .pcmf_setFgColor(xCol);
1039: } catch (Exception e) {
1040: KeLog.pcmf_logException("ug2t", this , e);
1041: }
1042: ;
1043:
1044: return;
1045: };
1046:
1047: public void pcmf_setBgColor(String xCol) {
1048: try {
1049: this .pdm_swingObj.setBackground(HoSwingComponent
1050: .pcmf_createColor(xCol));
1051:
1052: super .pcmf_setBgColor(xCol);
1053: } catch (Exception e) {
1054: KeLog.pcmf_logException("ug2t", this , e);
1055: }
1056: ;
1057:
1058: return;
1059: };
1060:
1061: public void pcmf_repaint() {
1062: synchronized (this ) {
1063: this .pdm_inSpEvents = true;
1064: }
1065: ;
1066:
1067: if (this .pdm_multiSelection == false) {
1068: TreePath l_selection = this .pdm_swingObj.getSelectionPath();
1069:
1070: this .pdm_swingObj.stopEditing();
1071: this .pdm_model.reload();
1072:
1073: this .pdm_swingObj.setSelectionPath(l_selection);
1074: } else {
1075: TreePath l_selection[] = this .pdm_swingObj
1076: .getSelectionPaths();
1077:
1078: this .pdm_swingObj.stopEditing();
1079: this .pdm_model.reload();
1080:
1081: if (l_selection == null)
1082: this .pdm_swingObj.setSelectionPath(null);
1083: else
1084: for (int i = 0; i < l_selection.length; i++)
1085: this .pdm_swingObj.addSelectionPath(l_selection[i]);
1086: }
1087:
1088: synchronized (this ) {
1089: this .pdm_inSpEvents = false;
1090: }
1091: ;
1092:
1093: this .pdm_swingObj.pdmf_commitTree();
1094: this .pdm_swingObj.repaint();
1095:
1096: return;
1097: };
1098:
1099: public KeTreeNode pcmf_setRoot(KeTreeNode xRoot) {
1100: KeTreeNode l_node = (KeTreeNode) this .pem_rootNode
1101: .pcmf_getTreeElement();
1102:
1103: if (xRoot != null)
1104: pem_rootNode = new ConvertingTreeNode(xRoot);
1105: else
1106: pem_rootNode = new ConvertingTreeNode(this );
1107:
1108: this .pdm_model = new DefaultTreeModel(pem_rootNode);
1109: this .pdm_swingObj.setModel(pdm_model);
1110: this .pem_pane.getViewport().setViewPosition(new Point(0, 0));
1111:
1112: this .pcmf_setLocalValue(this .pem_rootNode.pcmf_getTreeElement()
1113: .pcmf_getValue());
1114:
1115: return (l_node);
1116: };
1117:
1118: public java.awt.Container pcmf_getSwingWidget() {
1119: return (this .pdm_swingObj);
1120: };
1121:
1122: public KeTreeNode pcmf_getRoot() {
1123: return ((KeTreeNode) this .pem_rootNode.pcmf_getTreeElement());
1124: };
1125:
1126: public HoGenericDataContainer pcmf_getValues() {
1127: Object l_obj = super .pcmf_getValue();
1128: if (l_obj instanceof HoGenericDataContainer)
1129: return (((HoGenericDataContainer) l_obj));
1130: else
1131: return (null);
1132: }
1133:
1134: public void pcmf_scrollXRel(int xPx) {
1135: int l_x = this .pem_pane.getHorizontalScrollBar().getValue();
1136: l_x += xPx;
1137: this .pem_pane.getHorizontalScrollBar().setValue(l_x);
1138: }
1139:
1140: public void pcmf_scrollXAbs(int xPx) {
1141: this .pem_pane.getHorizontalScrollBar().setValue(xPx);
1142: }
1143:
1144: public void pcmf_scrollYRel(int xPy) {
1145: int l_y = this .pem_pane.getVerticalScrollBar().getValue();
1146: l_y += xPy;
1147: this .pem_pane.getVerticalScrollBar().setValue(l_y);
1148: }
1149:
1150: public void pcmf_scrollYAbs(int xPy) {
1151: this .pem_pane.getVerticalScrollBar().setValue(xPy);
1152: }
1153:
1154: public int pcmf_getXScroll() {
1155: return (this .pem_pane.getHorizontalScrollBar().getValue());
1156: }
1157:
1158: public int pcmf_getYScroll() {
1159: return (this .pem_pane.getVerticalScrollBar().getValue());
1160: }
1161:
1162: public KeTreeNode pcmf_getToggled() {
1163: return (this .pdm_toggled);
1164: }
1165:
1166: public KeTreeNode pcmf_addNode(String xName, KeTreeNode xNode) {
1167: if (xNode instanceof IUnContextMenu)
1168: this .pdm_realSwingCmp
1169: .add(((HoSwingComponent) xNode).pdm_realSwingCmp);
1170:
1171: if (xNode instanceof IUnEventChannel)
1172: this .pdmf_addChannelListener((IUnEventChannel) xNode);
1173:
1174: return (super .pcmf_addNodeLocal(xName, xNode));
1175: };
1176:
1177: public KeTreeElement pcmf_addElement(String xName,
1178: KeTreeElement xNode) {
1179: if (xNode instanceof IUnContextMenu)
1180: this .pdm_realSwingCmp
1181: .add(((HoSwingComponent) xNode).pdm_realSwingCmp);
1182:
1183: if (xNode instanceof IUnEventChannel) {
1184: this .pdmf_addChannelListener((IUnEventChannel) xNode);
1185: return (this );
1186: }
1187: ;
1188:
1189: return (super .pcmf_addElementLocal(xName, xNode));
1190: };
1191:
1192: public void pcmf_setCommitHandler(IKeExecutable xHandler) {
1193: throw (new UnsupportedOperationException());
1194: }
1195:
1196: public void pcmf_clearCommitHandler() {
1197: throw (new UnsupportedOperationException());
1198: }
1199:
1200: }
|