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.plaf.basic.*;
0040: import javax.swing.table.*;
0041:
0042: import de.ug2t.channel.ho.*;
0043: import de.ug2t.kernel.*;
0044: import de.ug2t.unifiedGui.interfaces.*;
0045: import de.ug2t.xmlScript.*;
0046:
0047: // ===============================
0048:
0049: public final class HoSwingTable extends HoSwingComponent implements
0050: IUnTable, IUnMultiSelectComponent {
0051: protected HoSwingEnhJTable pdm_swingObj = null;
0052: private JScrollPane pem_pane = null;
0053: private String pem_sep = "^";
0054: private Vector pem_rows = null;
0055: private Vector pem_header = null;
0056: private DefaultTableModel pem_model = null;
0057: private ListSelectionModel pem_selMod = null;
0058: protected boolean pdm_multiSelection = false;
0059: protected HoGenericDataContainer pdm_container = null;
0060: private int pem_locked = -1;
0061: private boolean pdm_inSpEvents = false;
0062:
0063: public boolean pcmf_setMultiSelection(boolean xMulti) {
0064: boolean l_old = this .pdm_multiSelection;
0065:
0066: if (xMulti == true && this .pdm_container != null) {
0067: this .pdm_multiSelection = xMulti;
0068: this .pdm_swingObj
0069: .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
0070: } else {
0071: this .pdm_multiSelection = false;
0072: this .pdm_swingObj
0073: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
0074: }
0075:
0076: return (l_old);
0077: };
0078:
0079: public boolean pcmf_setMultiSelection(HoGenericDataContainer xCont) {
0080: boolean l_old = this .pdm_multiSelection;
0081:
0082: if (xCont != null) {
0083: this .pdm_multiSelection = true;
0084: this .pdm_container = xCont;
0085: this .pdm_swingObj
0086: .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
0087: }
0088:
0089: return (l_old);
0090: };
0091:
0092: public boolean pcmf_isMultiSelection() {
0093: return (this .pdm_multiSelection);
0094: }
0095:
0096: public ArrayList pcmf_getCol(int xCol) {
0097: Iterator l_it = this .pem_rows.iterator();
0098: ArrayList l_ret = new ArrayList(this .pcmf_getColCount());
0099: l_ret.add(this .pem_header.get(xCol));
0100: while (l_it.hasNext())
0101: l_ret.add(((ArrayList) l_it.next()).get(xCol));
0102:
0103: return (l_ret);
0104: }
0105:
0106: private void pemf_lockColumn(int xCol) {
0107: if (xCol == -1) {
0108: this .pem_pane.setRowHeader(null);
0109: return;
0110: }
0111:
0112: if (this .pdm_swingObj.getColumnCount() < xCol
0113: || this .pdm_swingObj.getRowCount() == 0)
0114: return;
0115:
0116: String l_name = this .pdm_swingObj.getColumnName(xCol);
0117: TableColumn l_c = this .pdm_swingObj.getColumn(l_name);
0118: DefaultTableColumnModel l_tc = new DefaultTableColumnModel();
0119:
0120: if (l_c != null) {
0121: l_c.setModelIndex(0);
0122: l_tc.addColumn(l_c);
0123: int l_width = l_tc.getTotalColumnWidth();
0124: HoSwingEnhJTable l_t1 = new HoSwingEnhJTable(
0125: new DefaultTableModel(this .pdm_swingObj
0126: .getRowCount(), 1), l_tc);
0127: l_t1.setRowSelectionAllowed(false);
0128:
0129: TableModel l_model = this .pdm_swingObj.getModel();
0130: int l_len = l_model.getRowCount();
0131: for (int i = 0; i < l_len; i++) {
0132: l_t1.getModel().setValueAt(l_model.getValueAt(i, xCol),
0133: i, 0);
0134: l_t1.setRowHeight(i, this .pdm_swingObj.getRowHeight(i));
0135: }
0136: this .pdm_swingObj.removeColumn(l_c);
0137: this .pem_pane.setRowHeaderView(l_t1);
0138:
0139: Component l_comp = null;
0140: Object l_head = l_c.getHeaderValue();
0141: l_head = KeTools.pcmf_deRefObj(l_head.toString());
0142: if (l_head instanceof HoSwingComponent)
0143: l_comp = ((HoSwingComponent) l_head)
0144: .pcmf_getRealSwingObj();
0145: else
0146: l_comp = new JButton(l_head.toString());
0147:
0148: this .pem_pane.setCorner(JScrollPane.UPPER_LEFT_CORNER,
0149: l_comp);
0150: this .pem_pane.getRowHeader().setPreferredSize(
0151: new Dimension(l_width, 0));
0152: }
0153: }
0154:
0155: public HoSwingTable(String xName, boolean xSel, IUnApplication xAppl)
0156: throws Exception {
0157: super (xName, xAppl);
0158:
0159: this .pem_model = new DefaultTableModel();
0160: this .pem_rows = new Vector();
0161: this .pdm_swingObj = new HoSwingEnhJTable(this .pem_model);
0162: this .pem_pane = new JScrollPane(this .pdm_swingObj);
0163: super .pdm_realSwingCmp = this .pem_pane;
0164:
0165: this .pem_pane.getViewport().setScrollMode(
0166: JViewport.BACKINGSTORE_SCROLL_MODE);
0167:
0168: this .pdm_swingObj
0169: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
0170: this .pdm_swingObj
0171: .setDefaultEditor(java.lang.Object.class, null);
0172: this .pem_selMod = this .pdm_swingObj.getSelectionModel();
0173: this .pdm_swingObj.setRowSelectionAllowed(xSel);
0174: this .pdm_swingObj.setColumnSelectionAllowed(false);
0175: this .pcmf_setLocalValue("0");
0176: this .pdm_swingObj.getTableHeader().setDefaultRenderer(
0177: new HoSwingFlexTableCellRenderer());
0178: this .pdm_swingObj.getTableHeader().setUI(
0179: new BasicTableHeaderUI());
0180:
0181: class HeadPopUpListener extends HoMouseAdapter {
0182: public void mousePressed(MouseEvent e) {
0183: if (e.getButton() == MouseEvent.BUTTON2
0184: || e.getButton() == MouseEvent.BUTTON3) {
0185: HoSwingTable.this .pdm_swingObj.dispatchEvent(e);
0186: }
0187: return;
0188: }
0189: }
0190:
0191: this .pdm_swingObj.getTableHeader().addMouseListener(
0192: new HeadPopUpListener());
0193: this .pdm_realSwingCmp.addMouseListener(new HeadPopUpListener());
0194:
0195: this .pdm_swingObj
0196: .setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
0197: ((HoSwingClient) xAppl).pcmf_addKeyDispatcher(this );
0198:
0199: this .pemf_addScrollListeners();
0200:
0201: // Steuerelemente im Header mit events bedienen
0202: final MouseMotionListener l_ml = new MouseMotionListener() {
0203: private void pcmf_handle(MouseEvent e, boolean xDragged) {
0204: JTableHeader l_head = HoSwingTable.this .pdm_swingObj
0205: .getTableHeader();
0206:
0207: JComponent l_comp = (JComponent) e.getSource();
0208: Rectangle l_rect = l_comp.getBounds();
0209:
0210: e.translatePoint(l_rect.x, l_rect.y);
0211: e.setSource(l_head);
0212:
0213: MouseMotionListener l_listen[] = l_head
0214: .getMouseMotionListeners();
0215: for (int i = 0; i < l_listen.length; i++) {
0216: if (!(l_listen[i] instanceof HoMouseAdapter)) {
0217: if (xDragged) {
0218: l_listen[i].mouseDragged(e);
0219: } else
0220: l_listen[i].mouseMoved(e);
0221: }
0222: }
0223:
0224: if (!l_comp.hasFocus())
0225: l_head.paintImmediately(l_head.getBounds());
0226:
0227: e.translatePoint(-l_rect.x, -l_rect.y);
0228: e.setSource(l_comp);
0229:
0230: return;
0231: }
0232:
0233: public void mouseDragged(MouseEvent e) {
0234: this .pcmf_handle(e, true);
0235: }
0236:
0237: public void mouseMoved(MouseEvent e) {
0238: this .pcmf_handle(e, false);
0239: }
0240: };
0241:
0242: final MouseListener l_m = new HoMouseAdapter() {
0243: private void pemf_handle(MouseEvent e, boolean xFocus) {
0244: JTableHeader l_head = HoSwingTable.this .pdm_swingObj
0245: .getTableHeader();
0246: TableColumnModel l_mod = l_head.getColumnModel();
0247:
0248: int l_col = l_mod.getColumnIndexAtX((int) e.getPoint()
0249: .getX());
0250: if (l_col < 0)
0251: return;
0252:
0253: Object l_obj = l_mod.getColumn(l_col).getHeaderValue();
0254:
0255: l_obj = KeTools.pcmf_deRefObj(l_obj.toString());
0256: if (l_obj instanceof IUnComponent
0257: && l_head.getCursor() != Cursor
0258: .getPredefinedCursor(Cursor.E_RESIZE_CURSOR)) {
0259: if (xFocus)
0260: ((JComponent) ((HoSwingComponent) l_obj)
0261: .pcmf_getRealSwingObj())
0262: .requestFocusInWindow();
0263:
0264: if (((HoSwingComponent) l_obj)
0265: .pcmf_getRealSwingObj().getParent() != l_head) {
0266: l_head.remove(((HoSwingComponent) l_obj)
0267: .pcmf_getRealSwingObj());
0268: Rectangle l_rect = l_head.getHeaderRect(l_col);
0269: l_head.add(((HoSwingComponent) l_obj)
0270: .pcmf_getRealSwingObj());
0271: ((HoSwingComponent) l_obj)
0272: .pcmf_getRealSwingObj().setBounds(
0273: l_rect);
0274: ((HoSwingComponent) l_obj)
0275: .pcmf_getRealSwingObj()
0276: .removeMouseMotionListener(l_ml);
0277: ((HoSwingComponent) l_obj)
0278: .pcmf_getRealSwingObj()
0279: .addMouseMotionListener(l_ml);
0280: }
0281: }
0282: return;
0283: }
0284:
0285: public void mousePressed(MouseEvent e) {
0286: this .pemf_handle(e, true);
0287: }
0288:
0289: public void mouseEntered(MouseEvent e) {
0290: this .pemf_handle(e, false);
0291: }
0292: };
0293:
0294: // final MouseListener l_m = new HoMouseAdapter()
0295: // {
0296: // private Container pcmf_getHeaderWdg(MouseEvent e)
0297: // {
0298: // JTableHeader l_head = HoSwingTable.this.pdm_swingObj.getTableHeader();
0299: // TableColumnModel l_mod = l_head.getColumnModel();
0300: //
0301: // int l_col = l_mod.getColumnIndexAtX((int) e.getPoint().getX());
0302: // if (l_col < 0)
0303: // return (null);
0304: //
0305: // Object l_obj = l_mod.getColumn(l_col).getHeaderValue();
0306: //
0307: // l_obj = KeTools.pcmf_deRefObj(l_obj.toString());
0308: // if (l_obj instanceof IUnInputComponent)
0309: // {
0310: // e.translatePoint(-e.getX() + 1, -e.getY() + 1);
0311: // ((HoSwingComponent) l_obj).pcmf_getRealSwingObj().setSize(10, 10);
0312: // e.setSource(((HoSwingComponent) l_obj).pcmf_getRealSwingObj());
0313: // l_head.repaint();
0314: // return (((HoSwingComponent) l_obj).pcmf_getRealSwingObj());
0315: // }
0316: // else
0317: // return (null);
0318: // }
0319: //
0320: // public void mouseClicked(MouseEvent e)
0321: // {
0322: // Container l_cont = this.pcmf_getHeaderWdg(e);
0323: // if (l_cont == null)
0324: // return;
0325: //
0326: // MouseListener l_listen[] = l_cont.getMouseListeners();
0327: // for (int i = 0; i < l_listen.length; i++)
0328: // l_listen[i].mouseClicked(e);
0329: // }
0330: //
0331: // public void mousePressed(MouseEvent e)
0332: // {
0333: // Container l_cont = this.pcmf_getHeaderWdg(e);
0334: // if (l_cont == null)
0335: // return;
0336: //
0337: // MouseListener l_listen[] = l_cont.getMouseListeners();
0338: // for (int i = 0; i < l_listen.length; i++)
0339: // l_listen[i].mousePressed(e);
0340: // }
0341: //
0342: // public void mouseReleased(MouseEvent e)
0343: // {
0344: // Container l_cont = this.pcmf_getHeaderWdg(e);
0345: // if (l_cont == null)
0346: // return;
0347: //
0348: // MouseListener l_listen[] = l_cont.getMouseListeners();
0349: // for (int i = 0; i < l_listen.length; i++)
0350: // l_listen[i].mouseReleased(e);
0351: // }
0352: //
0353: // public void mouseEntered(MouseEvent e)
0354: // {
0355: // Container l_cont = this.pcmf_getHeaderWdg(e);
0356: // if (l_cont == null)
0357: // return;
0358: //
0359: // MouseListener l_listen[] = l_cont.getMouseListeners();
0360: // for (int i = 0; i < l_listen.length; i++)
0361: // l_listen[i].mouseEntered(e);
0362: // }
0363: //
0364: // public void mouseExited(MouseEvent e)
0365: // {
0366: // Container l_cont = this.pcmf_getHeaderWdg(e);
0367: // if (l_cont == null)
0368: // return;
0369: //
0370: // MouseListener l_listen[] = l_cont.getMouseListeners();
0371: // for (int i = 0; i < l_listen.length; i++)
0372: // l_listen[i].mouseExited(e);
0373: // }
0374: // };
0375:
0376: final ListSelectionListener l_f = new ListSelectionListener() {
0377: public void valueChanged(ListSelectionEvent e) {
0378: if (HoSwingTable.this .pdm_swingObj.pcmf_hasSpans())
0379: HoSwingTable.this .pdm_swingObj.repaint();
0380:
0381: if (e.getValueIsAdjusting())
0382: return;
0383:
0384: synchronized (HoSwingTable.this ) {
0385: if (HoSwingTable.this .pdm_inSpEvents)
0386: return;
0387: }
0388:
0389: try {
0390: // No Client side event dispatching if session is disabled !
0391: if (HoSwingTable.this .pem_session.pcmf_isDisabled())
0392: return;
0393:
0394: String l_objName = HoSwingTable.this
0395: .pcmf_getObjName();
0396:
0397: // Lokale Listener aufrufen
0398:
0399: if (HoSwingTable.this .pdm_multiSelection == false) {
0400: int l_selection = HoSwingTable.this .pdm_swingObj
0401: .getSelectedRow();
0402: if (l_selection == -1) {
0403: HoSwingTable.this .pdm_swingObj
0404: .clearSelection();
0405: return;
0406: }
0407: ;
0408:
0409: HoSwingTable.this .pcmf_setLocalValue(Integer
0410: .toString(l_selection));
0411: HoSwingTable.this .pcmf_setRefresh();
0412: HoSwingTable.this .pcmf_dispatchEvent();
0413:
0414: ((HoSwingPage) HoSwingTable.this .pcmf_getAppl()
0415: .pcmf_getActive()).pcmf_setSubmitValue(
0416: l_objName, HoSwingTable.this
0417: .pcmf_getValue().toString());
0418: } else {
0419: int l_selection[] = HoSwingTable.this .pdm_swingObj
0420: .getSelectedRows();
0421: if (l_selection == null) {
0422: HoSwingTable.this .pdm_swingObj
0423: .addRowSelectionInterval(0, 0);
0424: return;
0425: }
0426: ;
0427:
0428: ArrayList l_values = new ArrayList();
0429: for (int i = 0; i < l_selection.length; i++)
0430: l_values.add(Integer
0431: .toString(l_selection[i]));
0432:
0433: HoSwingTable.this .pdm_container
0434: .pcmf_setRemoteValues_C2S(l_values);
0435:
0436: HoSwingTable.this
0437: .pcmf_setLocalValue(HoSwingTable.this .pdm_container);
0438: HoSwingTable.this .pcmf_setRefresh();
0439: HoSwingTable.this .pcmf_dispatchEvent();
0440:
0441: ((HoSwingPage) HoSwingTable.this .pcmf_getAppl()
0442: .pcmf_getActive()).pcmf_setSubmitValue(
0443: l_objName,
0444: ((KeRegisteredObject) HoSwingTable.this
0445: .pcmf_getValue())
0446: .pcmf_getObjName());
0447: }
0448:
0449: // Werte setzen um diese zum Server zu übertragen
0450: HoSwingTable.this .pcmf_addSyncedWidgets(
0451: (HoSwingPage) HoSwingTable.this
0452: .pcmf_getAppl().pcmf_getActive(),
0453: HoSwingTable.this );
0454: if (HoSwingTable.this .pcmf_getUnComponent()
0455: .pcmf_isSubmit() == true)
0456: ((HoSwingPage) HoSwingTable.this .pcmf_getAppl()
0457: .pcmf_getActive()).pcmf_submit();
0458: } catch (Exception ex) {
0459: KeLog.pcmf_logException("ug2t", this , ex);
0460: }
0461: ;
0462: };
0463: };
0464:
0465: final MouseListener l_rc = new HoMouseAdapter() {
0466: public void mousePressed(MouseEvent e) {
0467: if (SwingUtilities.isRightMouseButton(e)) {
0468: int row = HoSwingTable.this .pdm_swingObj
0469: .rowAtPoint(e.getPoint());
0470: int column = HoSwingTable.this .pdm_swingObj
0471: .columnAtPoint(e.getPoint());
0472:
0473: if (HoSwingTable.this .pdm_swingObj.getCellEditor() != null
0474: && HoSwingTable.this .pdm_swingObj
0475: .getSelectedRow() != row)
0476: HoSwingTable.this .pdm_swingObj.getCellEditor()
0477: .stopCellEditing();
0478:
0479: if (e.getModifiers() == (InputEvent.BUTTON3_MASK | InputEvent.CTRL_MASK)
0480: && HoSwingTable.this .pdm_swingObj
0481: .getSelectionModel()
0482: .getSelectionMode() == ListSelectionModel.MULTIPLE_INTERVAL_SELECTION)
0483: HoSwingTable.this .pdm_swingObj
0484: .addRowSelectionInterval(row, row);
0485: else
0486: HoSwingTable.this .pdm_swingObj.changeSelection(
0487: row, column, false, false);
0488: }
0489: }
0490: };
0491:
0492: this .pem_selMod.addListSelectionListener(l_f);
0493: this .pdm_swingObj.getTableHeader().addMouseListener(l_m);
0494: this .pdm_swingObj.addMouseListener(l_rc);
0495:
0496: return;
0497: };
0498:
0499: private void pemf_addScrollListeners() {
0500: AdjustmentListener l_listen = new AdjustmentListener() {
0501: private int pem_x = 0;
0502: private int pem_y = 0;
0503: private HoDelayedCall pem_call = null;
0504:
0505: public void adjustmentValueChanged(AdjustmentEvent e) {
0506: if (this .pem_x == HoSwingTable.this .pem_pane
0507: .getHorizontalScrollBar().getValue()
0508: && this .pem_y == HoSwingTable.this .pem_pane
0509: .getVerticalScrollBar().getValue())
0510: return;
0511:
0512: if (pem_session != null) {
0513: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
0514: "");
0515:
0516: if (HoSwingTable.this .pem_session
0517: .pcmf_isInTransaction()) {
0518: ScXmlScript.pcmf_createPBody(l_remCall);
0519: } else {
0520: ScXmlScript.pcmf_createxScriptString(l_remCall,
0521: null);
0522: ScXmlScript.pcmf_addProc(l_remCall, null);
0523: }
0524: ;
0525:
0526: this .pem_x = HoSwingTable.this .pem_pane
0527: .getHorizontalScrollBar().getValue();
0528: this .pem_y = HoSwingTable.this .pem_pane
0529: .getVerticalScrollBar().getValue();
0530:
0531: ScXmlScript.pcmf_addCall(l_remCall, null,
0532: HoSwingTable.this .pcmf_getObjName(),
0533: "pcmf_setScrollInfo");
0534: ScXmlScript.pcmf_addCallPar(l_remCall, Integer
0535: .toString(this .pem_x), "false", "int");
0536: ScXmlScript.pcmf_addCallPar(l_remCall, Integer
0537: .toString(this .pem_y), "false", "int");
0538: ScXmlScript.pcmf_endAll(l_remCall);
0539:
0540: if (this .pem_call == null
0541: || this .pem_call.pcmf_isReady())
0542: this .pem_call = new HoDelayedCall(l_remCall
0543: .toString(),
0544: HoSwingTable.this .pem_session,
0545: IUnComponent.EVENT_LATENCY_SCROLL,
0546: HoSwingTable.this , false);
0547: else
0548: this .pem_call.pcmf_refreshCall(l_remCall
0549: .toString());
0550: }
0551: ;
0552: }
0553: };
0554: this .pem_pane.getHorizontalScrollBar().addAdjustmentListener(
0555: l_listen);
0556: this .pem_pane.getVerticalScrollBar().addAdjustmentListener(
0557: l_listen);
0558: }
0559:
0560: // Aufbau einer Tabelle über rechnerferne Aufrufe
0561: public void pcmf_setSepRow(String xSep) {
0562: this .pem_sep = xSep;
0563: return;
0564: };
0565:
0566: public void pcmf_clearModel() {
0567: if (pem_rows != null)
0568: this .pem_rows.clear();
0569: if (pem_header != null)
0570: this .pem_header.clear();
0571:
0572: this .pdm_swingObj.pcmf_clearColorBuffer();
0573:
0574: return;
0575: };
0576:
0577: public void pcmf_lockColumn(int xCol, boolean xLock) {
0578: if (!xLock)
0579: xCol = -1;
0580:
0581: this .pem_locked = xCol;
0582: }
0583:
0584: public void pcmf_addRow(String xRow) {
0585: if (this .pem_header == null || this .pem_header.size() == 0) {
0586: this .pcmf_setHeader(xRow);
0587: return;
0588: }
0589: ;
0590:
0591: StringTokenizer l_tok = new StringTokenizer(xRow, this .pem_sep,
0592: false);
0593: Vector l_row = new Vector();
0594:
0595: Object l_obj = null;
0596: while (l_tok.hasMoreTokens()) {
0597: l_obj = l_tok.nextToken();
0598: l_obj = KeTools.pcmf_deRefObj(l_obj.toString());
0599: l_row.addElement(l_obj);
0600: }
0601: ;
0602:
0603: this .pem_rows.addElement(l_row);
0604:
0605: return;
0606: };
0607:
0608: public void pcmf_setHeader(String xRow) {
0609: StringTokenizer l_tok = new StringTokenizer(xRow, this .pem_sep,
0610: false);
0611: Vector l_row = new Vector();
0612:
0613: Object l_obj = null;
0614: while (l_tok.hasMoreTokens()) {
0615: l_obj = l_tok.nextToken();
0616: // Header werden erst im Renderer dereferenziert, damit Objekte durch die
0617: // Standardklassen geschleust werden können !!
0618: // l_obj = KeTools.pcmf_deRefObj (l_obj.toString());
0619: l_row.addElement(l_obj);
0620: }
0621: ;
0622:
0623: this .pem_header = l_row;
0624:
0625: return;
0626: };
0627:
0628: public void pcmf_hideRow(int xRow) {
0629: this .pdm_swingObj.setRowHeight(xRow, 0);
0630: };
0631:
0632: public boolean pcmf_isHiddenRow(int xRow) {
0633: throw (new UnsupportedOperationException());
0634: }
0635:
0636: public void pcmf_unHideRow(int xRow) {
0637: Dimension l_dim = null;
0638: int hight = 0;
0639: int l_maxH = 0;
0640: Iterator l_cit = ((Vector) this .pem_rows.get(xRow)).iterator();
0641: while (l_cit.hasNext()) {
0642: Object l_obj = l_cit.next();
0643: if (l_obj instanceof HoSwingComponent) {
0644: l_dim = ((HoSwingComponent) l_obj)
0645: .pcmf_getRealSwingObj().getPreferredSize();
0646: hight = (int) l_dim.getHeight();
0647: if (hight > l_maxH)
0648: l_maxH = hight + 1;
0649: }
0650: }
0651: ;
0652: this .pdm_swingObj
0653: .setRowHeight(xRow, l_maxH == 0 ? this .pdm_swingObj
0654: .getRowHeight() : l_maxH);
0655: };
0656:
0657: public void pcmf_commitTable() {
0658: synchronized (this ) {
0659: this .pdm_inSpEvents = true;
0660: }
0661: ;
0662:
0663: int l_len = 0;
0664: int l_width = 0;
0665: this .pemf_lockColumn(-1);
0666: this .pem_model.setDataVector(this .pem_rows, this .pem_header);
0667: this .pem_model.newDataAvailable(new TableModelEvent(
0668: this .pem_model));
0669:
0670: this .pdm_swingObj.pcmf_clearColorBuffer();
0671:
0672: if (this .pem_header != null) {
0673: for (int i = 0; i < this .pem_header.size(); i++) {
0674: Object l_obj = KeTools.pcmf_deRefObj(this .pem_header
0675: .elementAt(i).toString());
0676: TableColumn l_col = this .pdm_swingObj.getColumnModel()
0677: .getColumn(i);
0678:
0679: if (l_obj instanceof HoSwingComponent) {
0680: Container l_cont = ((HoSwingComponent) l_obj)
0681: .pcmf_getRealSwingObj();
0682:
0683: l_len = (int) l_cont.getMinimumSize().getWidth();
0684: l_col.setMinWidth(l_len);
0685: l_len = (int) l_cont.getMaximumSize().getWidth();
0686: l_col.setMaxWidth(l_len);
0687: l_len = (int) l_cont.getPreferredSize().getWidth();
0688: l_col.setPreferredWidth(l_len);
0689: } else {
0690: l_len = this .pem_header.elementAt(i).toString()
0691: .length();
0692:
0693: l_col.setMinWidth(8 + l_len * 8);
0694: l_col.setMaxWidth(4096);
0695: }
0696: l_width += l_col.getMinWidth();
0697: }
0698: if (l_width > this .pdm_swingObj.getWidth()
0699: && this .pdm_swingObj.getWidth() > 0)
0700: this .pdm_swingObj
0701: .setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
0702: else
0703: this .pdm_swingObj
0704: .setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
0705: }
0706:
0707: Iterator l_rit = this .pem_rows.iterator();
0708: Iterator l_cit = null;
0709: int l_rcnt = 0;
0710: int l_maxH = 0;
0711: Object l_obj = null;
0712: Dimension l_dim = null;
0713:
0714: while (l_rit.hasNext()) {
0715: l_cit = ((Vector) l_rit.next()).iterator();
0716: while (l_cit.hasNext()) {
0717: l_obj = l_cit.next();
0718: if (l_obj instanceof HoSwingComponent) {
0719: int hight;
0720: l_dim = ((HoSwingComponent) l_obj)
0721: .pcmf_getRealSwingObj().getPreferredSize();
0722: hight = (int) l_dim.getHeight();
0723: if (hight > l_maxH)
0724: l_maxH = hight + 1;
0725: }
0726: }
0727: ;
0728:
0729: if (l_maxH > 0)
0730: this .pdm_swingObj.setRowHeight(l_rcnt, l_maxH);
0731:
0732: l_maxH = 0;
0733: l_rcnt++;
0734: }
0735: this .pemf_lockColumn(this .pem_locked);
0736:
0737: synchronized (this ) {
0738: this .pdm_inSpEvents = false;
0739: }
0740: ;
0741:
0742: this .pdm_swingObj.repaint();
0743:
0744: return;
0745: };
0746:
0747: // ===========================================
0748:
0749: public void pcmf_relockCol() {
0750: if (this .pem_locked != -1)
0751: this .pcmf_commitTable();
0752:
0753: this .pcmf_setValue(this .pcmf_getValue());
0754: }
0755:
0756: public void pcmf_setValues(HoGenericDataContainer xValues) {
0757: this .pcmf_setValue(xValues);
0758: }
0759:
0760: public void pcmf_setValue(Object xValue) {
0761: if (xValue == null)
0762: xValue = "";
0763:
0764: if (xValue instanceof HoGenericDataContainer) {
0765: this .pdm_swingObj.clearSelection();
0766:
0767: ArrayList l_vect = ((HoGenericDataContainer) xValue)
0768: .pcmf_getValueArray();
0769: Iterator l_it = l_vect.iterator();
0770: int l_row;
0771:
0772: while (l_it.hasNext()) {
0773: l_row = Integer.parseInt(l_it.next().toString());
0774: this .pdm_swingObj.addRowSelectionInterval(l_row, l_row);
0775: }
0776: } else {
0777: String l_string = xValue.toString();
0778: if (!(l_string.equals("null") || l_string.trim().equals(""))) {
0779: int l_row = Integer.parseInt(l_string);
0780: this .pdm_swingObj.setRowSelectionInterval(l_row, l_row);
0781: } else
0782: this .pdm_swingObj.clearSelection();
0783: }
0784:
0785: this .pcmf_getUnComponent().pcmf_setLocalValue(xValue);
0786:
0787: return;
0788: };
0789:
0790: public void pcmf_setSpacing(int xSpace) {
0791: this .pdm_swingObj.setIntercellSpacing(new Dimension(xSpace,
0792: xSpace));
0793: return;
0794: };
0795:
0796: public void pcmf_setPadding(int xPad) {
0797: this .pdm_swingObj.setRowMargin(xPad);
0798:
0799: return;
0800: };
0801:
0802: public void pcmf_setTableBorder(int xBorder) {
0803: this .pdm_swingObj.setShowGrid(xBorder == 0 ? false : true);
0804:
0805: return;
0806: };
0807:
0808: public int pcmf_getSpacing() {
0809: return ((int) this .pdm_swingObj.getIntercellSpacing()
0810: .getWidth());
0811: };
0812:
0813: public int pcmf_getPadding() {
0814: return ((int) this .pdm_swingObj.getRowMargin());
0815: };
0816:
0817: public int pcmf_getTableBorder() {
0818: return (this .pdm_swingObj.getShowHorizontalLines()
0819: && this .pdm_swingObj.getShowVerticalLines() ? 1 : 0);
0820: };
0821:
0822: public void pcmf_setClass(String xClass) {
0823: return;
0824: };
0825:
0826: public Iterator pcmf_getRows() {
0827: Vector l_rows = new Vector(this .pem_header);
0828: l_rows.addAll(this .pem_rows);
0829:
0830: return (l_rows.iterator());
0831: };
0832:
0833: public void pcmf_refresh(Collection xRows) {
0834: Vector l_header = null;
0835: Vector l_row = null;
0836: Vector l_rows = new Vector();
0837:
0838: Iterator l_it = xRows.iterator();
0839:
0840: l_header = new Vector((Collection) l_it.next());
0841: while (l_it.hasNext()) {
0842: l_row = new Vector((Collection) l_it.next());
0843: l_rows.addElement(l_row);
0844: }
0845: ;
0846:
0847: this .pem_header = l_header;
0848: this .pem_rows = l_rows;
0849:
0850: this .pcmf_commitTable();
0851:
0852: return;
0853: };
0854:
0855: public void pcmf_addRow(Collection xRow) {
0856: this .pem_rows.addElement(new Vector(xRow));
0857:
0858: return;
0859: };
0860:
0861: public void pcmf_addRow(Collection xRow, int xIdx) {
0862: this .pem_rows.add(xIdx, new Vector(xRow));
0863:
0864: return;
0865: };
0866:
0867: public void pcmf_addRow(String xRow, int xIdx) {
0868: if (this .pem_header == null || this .pem_header.size() == 0) {
0869: this .pcmf_setHeader(xRow);
0870: return;
0871: }
0872: ;
0873:
0874: StringTokenizer l_tok = new StringTokenizer(xRow, this .pem_sep,
0875: false);
0876: Vector l_row = new Vector();
0877:
0878: Object l_obj = null;
0879: while (l_tok.hasMoreTokens()) {
0880: l_obj = l_tok.nextToken();
0881: l_obj = KeTools.pcmf_deRefObj(l_obj.toString());
0882: l_row.addElement(l_obj);
0883: }
0884: ;
0885:
0886: this .pem_rows.add(xIdx, l_row);
0887:
0888: return;
0889: };
0890:
0891: public Collection pcmf_removeRow(int xIdx) {
0892: Collection l_ret = null;
0893: if (xIdx == 0) {
0894: l_ret = this .pem_header;
0895: this .pem_header = (Vector) this .pem_rows.get(0);
0896: this .pem_rows.removeElementAt(0);
0897: } else {
0898: l_ret = (Collection) this .pem_rows.elementAt(xIdx - 1);
0899: this .pem_rows.removeElementAt(xIdx - 1);
0900: }
0901: ;
0902: return (l_ret);
0903: };
0904:
0905: public Object pcmf_getCellValue(int xRow, int xCol) {
0906: Object l_ret = null;
0907:
0908: if (xRow == 0)
0909: l_ret = this .pem_header.elementAt(xCol);
0910: else
0911: l_ret = ((Vector) this .pem_rows.elementAt(xRow - 1))
0912: .elementAt(xCol);
0913:
0914: return (l_ret);
0915: }
0916:
0917: public Object pcmf_modCell(int xRow, int xCol, Object xObj) {
0918: Object l_ret = null;
0919:
0920: if (xRow == 0) {
0921: l_ret = this .pem_header.elementAt(xCol);
0922: this .pem_header.setElementAt(xObj, xCol);
0923: } else {
0924: l_ret = ((Vector) this .pem_rows.elementAt(xRow - 1))
0925: .elementAt(xCol);
0926: ((Vector) this .pem_rows.elementAt(xRow - 1)).setElementAt(
0927: xObj, xCol);
0928: }
0929: ;
0930:
0931: return (l_ret);
0932: };
0933:
0934: public Object pcmf_modCell(int xRow, int xCol, String xObj)
0935: throws Exception {
0936: return (this .pcmf_modCell(xRow, xCol, (Object) xObj));
0937: };
0938:
0939: public void pcmf_disable() {
0940: this .pdm_swingObj.setEnabled(false);
0941: super .pcmf_disable();
0942: return;
0943: };
0944:
0945: public void pcmf_enable() {
0946: this .pdm_swingObj.setEnabled(true);
0947: super .pcmf_enable();
0948: return;
0949: };
0950:
0951: public void pcmf_setFgColor(String xCol) {
0952: try {
0953: this .pdm_swingObj.setForeground(HoSwingComponent
0954: .pcmf_createColor(xCol));
0955:
0956: super .pcmf_setFgColor(xCol);
0957: } catch (Exception e) {
0958: KeLog.pcmf_logException("ug2t", this , e);
0959: }
0960: ;
0961:
0962: return;
0963: };
0964:
0965: public void pcmf_setBgColor(String xCol) {
0966: try {
0967: this .pdm_swingObj.setBackground(HoSwingComponent
0968: .pcmf_createColor(xCol));
0969:
0970: super .pcmf_setBgColor(xCol);
0971: } catch (Exception e) {
0972: KeLog.pcmf_logException("ug2t", this , e);
0973: }
0974: ;
0975:
0976: return;
0977: };
0978:
0979: public Collection pcmf_getHeader() {
0980: return (this .pem_header);
0981: };
0982:
0983: public java.awt.Container pcmf_getSwingWidget() {
0984: return (this .pdm_swingObj);
0985: };
0986:
0987: public HoGenericDataContainer pcmf_getValues() {
0988: Object l_obj = super .pcmf_getValue();
0989: if (l_obj instanceof HoGenericDataContainer)
0990: return (((HoGenericDataContainer) l_obj));
0991: else
0992: return (null);
0993: }
0994:
0995: public void pcmf_clearSelection() {
0996: throw (new UnsupportedOperationException());
0997: }
0998:
0999: public void pcmf_setComplete(KeTable xTable) {
1000: throw (new UnsupportedOperationException());
1001: }
1002:
1003: public KeTable pcmf_getComplete() {
1004: throw (new UnsupportedOperationException());
1005: }
1006:
1007: public void pcmf_setRowsOnly(Collection xRows) {
1008: this .pem_rows = new Vector(xRows);
1009: this .pcmf_commitTable();
1010:
1011: return;
1012: }
1013:
1014: public void pcmf_setRowsOnly(KeTable xRows) {
1015: this .pem_rows = new Vector(xRows.pcmf_getTableValues());
1016: this .pcmf_commitTable();
1017:
1018: return;
1019: }
1020:
1021: public void pcmf_setHeader(Collection xHead) {
1022: this .pem_header = new Vector(xHead);
1023: return;
1024: }
1025:
1026: public void pcmf_setCellBgColor(int xRow, int xCol, String xColor) {
1027: KeLog
1028: .pcmf_logNotSupported("pcmf_setCellBgColor(int xRow, int xCol, String xColor)");
1029: }
1030:
1031: public void pcmf_setCellCssClass(int xRow, int xCol, String xClass) {
1032: KeLog
1033: .pcmf_logNotSupported("pcmf_setCellCssClass(int xRow, int xCol, String xClass)");
1034: }
1035:
1036: public void pcmf_setCellFgColor(int xRow, int xCol, String xColor) {
1037: KeLog
1038: .pcmf_logNotSupported("pcmf_setCellFgColor(int xRow, int xCol, String xColor)");
1039: }
1040:
1041: public void pcmf_setCellBorder(int xRow, int xCol, int xDir,
1042: String xColor, int xWidth, int xStyle) {
1043: KeLog
1044: .pcmf_logNotSupported("pcmf_setCellBorder(int xRow, int xCol, int xDir, String xColor, int xWidth, int xStyle)");
1045: }
1046:
1047: public void pcmf_setCellPadding(int xRow, int xCol, int xDir,
1048: int xWidth) {
1049: KeLog
1050: .pcmf_logNotSupported("pcmf_setCellPadding(int xRow, int xCol, int xDir, int xWidth)");
1051: }
1052:
1053: public void pcmf_setCellMargin(int xRow, int xCol, int xDir,
1054: int xWidth) {
1055: KeLog
1056: .pcmf_logNotSupported("pcmf_setCellMargin(int xRow, int xCol, int xDir, int xWidth)");
1057: }
1058:
1059: public void pcmf_setCellAlign(int xRow, int xCol, String xAlign) {
1060: KeLog
1061: .pcmf_logNotSupported("pcmf_setCellAlign(int xRow, int xCol, String xAlign)");
1062: }
1063:
1064: public Collection pcmf_getRowsOnly() {
1065: return (new Vector(this .pem_rows));
1066: }
1067:
1068: public void pcmf_addRows(Collection xRow) {
1069: if (this .pem_header == null) {
1070: this .pcmf_refresh(xRow);
1071: return;
1072: }
1073: if (this .pem_rows == null)
1074: this .pem_rows = new Vector();
1075:
1076: this .pem_rows.addAll(xRow);
1077: this .pcmf_commitTable();
1078:
1079: return;
1080: }
1081:
1082: public void pcmf_scrollXRel(int xPx) {
1083: int l_x = this .pem_pane.getHorizontalScrollBar().getValue();
1084: l_x += xPx;
1085: this .pem_pane.getHorizontalScrollBar().setValue(l_x);
1086: }
1087:
1088: public void pcmf_scrollXAbs(int xPx) {
1089: this .pem_pane.getHorizontalScrollBar().setValue(xPx);
1090: }
1091:
1092: public void pcmf_scrollYRel(int xPy) {
1093: int l_y = this .pem_pane.getVerticalScrollBar().getValue();
1094: l_y += xPy;
1095: this .pem_pane.getVerticalScrollBar().setValue(l_y);
1096: }
1097:
1098: public void pcmf_scrollYAbs(int xPy) {
1099: this .pem_pane.getVerticalScrollBar().setValue(xPy);
1100: }
1101:
1102: public int pcmf_getXScroll() {
1103: return (this .pem_pane.getHorizontalScrollBar().getValue());
1104: }
1105:
1106: public int pcmf_getYScroll() {
1107: return (this .pem_pane.getVerticalScrollBar().getValue());
1108: }
1109:
1110: public ArrayList pcmf_getSelectedTableRow() {
1111: String l_value = this .pcmf_getValue().toString();
1112: int l_idx = Integer.parseInt(l_value);
1113:
1114: return (new ArrayList((Vector) this .pem_rows.get(l_idx)));
1115: }
1116:
1117: public ArrayList pcmf_getSelectedTableRows() {
1118: ArrayList l_ret = new ArrayList();
1119: HoGenericDataContainer l_rows = this .pcmf_getValues();
1120: Iterator l_it = l_rows.pcmf_getValueIt();
1121: int l_idx = 0;
1122:
1123: while (l_it.hasNext()) {
1124: l_idx = Integer.parseInt(l_it.next().toString());
1125: l_ret.add((Vector) this .pem_rows.get(l_idx));
1126: }
1127:
1128: return (l_ret);
1129: }
1130:
1131: public int pcmf_getRowCount() {
1132: return (this .pem_rows.size() + 1);
1133: }
1134:
1135: public int pcmf_getColCount() {
1136: if (this .pem_header == null)
1137: return (0);
1138:
1139: return (this .pem_header.size());
1140: }
1141:
1142: public void pcmf_clearTableBody() {
1143: this .pcmf_setRowsOnly(new Vector());
1144: }
1145:
1146: public Object pcmf_getSelectedObject() {
1147: return (this .pcmf_getSelectedTableRow());
1148: }
1149:
1150: public Object pcmf_setSelectedRow(int xRow) {
1151: this .pcmf_setSelected(xRow);
1152: return (this .pcmf_getSelectedTableRow());
1153: }
1154:
1155: public ArrayList pcmf_setSelectedRows(int[] xRows) {
1156: this .pcmf_setSelected(xRows);
1157: return (this .pcmf_getSelectedTableRows());
1158: }
1159:
1160: public void pcmf_setSelected(int xRow) {
1161: this .pcmf_setValue(Integer.toString(xRow));
1162: }
1163:
1164: public void pcmf_setSelected(int[] xRows) {
1165: HoGenericDataContainer l_cont = this .pcmf_getValues();
1166: for (int i = 0; i < xRows.length; i++) {
1167: l_cont.pcmf_clearValues();
1168: l_cont.pcmf_addValue(Integer.toString(xRows[i]));
1169: }
1170: this .pcmf_setValues(l_cont);
1171: }
1172:
1173: public int pcmf_getSelectedRow() {
1174: try {
1175: return (Integer.parseInt(this .pcmf_getValue().toString()));
1176: } catch (Exception e) {
1177: return (-1);
1178: }
1179: }
1180:
1181: public boolean pcmf_isSelectable() {
1182: return (this .pdm_swingObj.getRowSelectionAllowed());
1183: }
1184:
1185: public KeTreeNode pcmf_addNode(String xName, KeTreeNode xNode) {
1186: if (xNode instanceof IUnContextMenu)
1187: this .pdm_realSwingCmp
1188: .add(((HoSwingComponent) xNode).pdm_realSwingCmp);
1189:
1190: if (xNode instanceof IUnEventChannel)
1191: this .pdmf_addChannelListener((IUnEventChannel) xNode);
1192:
1193: return (super .pcmf_addNodeLocal(xName, xNode));
1194: };
1195:
1196: public KeTreeElement pcmf_addElement(String xName,
1197: KeTreeElement xNode) {
1198: if (xNode instanceof IUnContextMenu)
1199: this .pdm_realSwingCmp
1200: .add(((HoSwingComponent) xNode).pdm_realSwingCmp);
1201:
1202: if (xNode instanceof IUnEventChannel) {
1203: this .pdmf_addChannelListener((IUnEventChannel) xNode);
1204: return (this );
1205: }
1206: ;
1207:
1208: return (super .pcmf_addElementLocal(xName, xNode));
1209: };
1210:
1211: public void pcmf_setSpan(int xRow, int xColumn, int xRowSpan,
1212: int xColumnSpan) {
1213: this .pdm_swingObj.pcmf_setSpan(xRow, xColumn, xRowSpan,
1214: xColumnSpan);
1215: }
1216:
1217: public void pcmf_removeSpan(int xRow, int xColumn) {
1218: this .pdm_swingObj.pcmf_removeSpan(xRow, xColumn);
1219: }
1220:
1221: public void pcmf_removeSelected() {
1222: throw (new UnsupportedOperationException());
1223: }
1224:
1225: public void pcmf_setCommitHandler(IKeExecutable xHandler) {
1226: throw (new UnsupportedOperationException());
1227: }
1228:
1229: public void pcmf_clearCommitHandler() {
1230: throw (new UnsupportedOperationException());
1231: }
1232:
1233: public void pcmf_repaint() {
1234: this .pdm_swingObj.getTableHeader().resizeAndRepaint();
1235: super .pcmf_repaint();
1236: return;
1237: };
1238:
1239: public void pcmf_draw() {
1240: this.pdm_swingObj.getTableHeader().resizeAndRepaint();
1241: super.pcmf_draw();
1242: return;
1243: };
1244: }
|