⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlbasictablepanel.java

📁 jawe的最新版本,基于Java的图形化工作流编辑器。图形化工作流编辑器 。使用JAVA语言开发
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.enhydra.jawe.base.panel.panels;import java.awt.Color;import java.awt.Component;import java.awt.Dimension;import java.awt.Point;import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.KeyEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Vector;import javax.swing.AbstractAction;import javax.swing.Action;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JViewport;import javax.swing.KeyStroke;import javax.swing.ListSelectionModel;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.table.DefaultTableModel;import javax.swing.table.TableCellRenderer;import javax.swing.table.TableColumn;import org.enhydra.jawe.ButtonPropertyChangedListener;import org.enhydra.jawe.JaWEManager;import org.enhydra.jawe.ResourceManager;import org.enhydra.jawe.base.controller.JaWEActions;import org.enhydra.jawe.base.controller.JaWEController;import org.enhydra.jawe.base.editor.StandardXPDLElementEditor;import org.enhydra.jawe.base.panel.InlinePanel;import org.enhydra.jawe.base.panel.PanelSettings;import org.enhydra.jawe.base.panel.panels.tablesorting.BasicSortingTable;import org.enhydra.shark.xpdl.XMLCollection;import org.enhydra.shark.xpdl.XMLCollectionElement;import org.enhydra.shark.xpdl.XMLComplexElement;import org.enhydra.shark.xpdl.XMLElement;import org.enhydra.shark.xpdl.XMLElementChangeInfo;import org.enhydra.shark.xpdl.XMLElementChangeListener;import org.enhydra.shark.xpdl.XMLUtil;/** * Creates a table panel. * @author Sasa Bojanic * @author Zoran Milakovic * @author Miroslav Popov */public class XMLBasicTablePanel extends XMLBasicPanel implements XMLElementChangeListener {   public static Color FOREIGN_EL_COLOR_BKG = Color.lightGray;   public static Color SPEC_EL_COLOR_BKG = Color.orange;   protected static Dimension miniTableDimension = new Dimension(450, 125);   protected static Dimension smallTableDimension = new Dimension(450, 200);   protected static Dimension mediumTableDimension = new Dimension(550, 200);   protected static Dimension largeTableDimension = new Dimension(650, 200);   /**    * Object which we are replacing from one place to another within    * the list by dragging it.    */   protected XMLElement movingElement;   /**    * Index of the object which we are replacing from one place to another    * within the list by dragging it.    */   protected int movingElementPosition;   /**    * The new index of the object which we are replacing from one place    * to another within the list by dragging it.    */   protected int newMovingElementPosition;   /** Indicates if object is being dragged. */   protected boolean dragging = false;   /**    * Indicates if the code for changing object position within the list    * is executed.    */   protected boolean changing = false;   protected JTable allItems;   protected JPanel toolbox;   protected Vector columnNames;   protected List columnsToShow;   protected InlinePanel ipc;   public XMLBasicTablePanel(         InlinePanel ipc,         XMLCollection myOwner,         List columnsToShow,         List elementsToShow,         String title,         boolean hasBorder,         boolean hasEmptyBorder,         boolean automaticWidth,         boolean miniDimension,         final boolean colors,         final boolean showArrows) {      super(ipc,myOwner, title, true, hasBorder, hasEmptyBorder);      this.ipc=ipc;      myOwner.addListener(this);      myOwner.setNotifyListeners(true);      columnNames = getColumnNames(columnsToShow);      this.columnsToShow = columnsToShow;      allItems = createTable(colors);      setupTable(miniDimension, automaticWidth, showArrows);      fillTableContent(elementsToShow);      toolbox = createToolbar();      JPanel paneAndArrows = new JPanel();      paneAndArrows.setLayout(new BoxLayout(paneAndArrows, BoxLayout.X_AXIS));      paneAndArrows.add(createScrollPane());//      if (showArrows) {//         JPanel p = createArrowPanel();//         paneAndArrows.add(Box.createRigidArea(new Dimension(5, 0)));//         paneAndArrows.add(p);//      }      add(toolbox);      add(Box.createVerticalStrut(3));      add(paneAndArrows);      adjustActions();   }   public JTable getTable() {      return allItems;   }   public XMLElement getSelectedElement() {      int row = allItems.getSelectedRow();      if (row >= 0) {         return (XMLElement) allItems.getValueAt(row, 0);      }      return null;   }   public boolean setSelectedElement(Object el) {      try {         int rc = allItems.getRowCount();         if (rc > 0) {            for (int i = 0; i < rc; i++) {               if (el==allItems.getValueAt(i, 0)) {                  allItems.setRowSelectionInterval(i, i);                  // focus the row                  JViewport viewport = (JViewport) allItems.getParent();                  // This rectangle is relative to the table where the                  // northwest corner of cell (0,0) is always (0,0).                  Rectangle rect = allItems.getCellRect(i, 0, true);                  // The location of the viewport relative to the table                  Point pt = viewport.getViewPosition();                  // Translate the cell location so that it is relative                  // to the view, assuming the northwest corner of the                  // view is (0,0)                  rect.setLocation(rect.x - pt.x, rect.y - pt.y);                  // Scroll the area into view                  viewport.scrollRectToVisible(rect);                  return true;               }            }         }      } catch (Exception ex) {      }      return false;   }   public void setSelectedRow(int row) {      try {         allItems.setRowSelectionInterval(row, row);         adjustActions();      } catch (Exception e) {      }   }   public void addRow(XMLElement e) {      int rowpos = allItems.getRowCount();      DefaultTableModel dtm = (DefaultTableModel) allItems.getModel();      Vector v = getRow(e);      dtm.insertRow(rowpos, v);   }   public void removeRow(int row) {      DefaultTableModel dtm = (DefaultTableModel) allItems.getModel();      dtm.removeRow(row);   }   protected void moveItem(int upOrDown) {      newMovingElementPosition = movingElementPosition;      if (newMovingElementPosition == -1) {         return;      }      if (upOrDown == 0) {            newMovingElementPosition--;      } else {            newMovingElementPosition++;      }      moveItem();   }   protected void moveItem() {      changing = true;      XMLCollection owncol = (XMLCollection) getOwner();      int rowCnt = allItems.getRowCount();      if (movingElement == null || movingElementPosition == -1 || newMovingElementPosition == -1            || newMovingElementPosition == movingElementPosition || (rowCnt - 1) < movingElementPosition            || (rowCnt - 1) < newMovingElementPosition || !owncol.contains(movingElement)) {         changing = false;         return;      }      if (JaWEManager.getInstance().getJaWEController().canRepositionElement(owncol, movingElement)) {         XMLElement currentElementAtPosition = (XMLElement) allItems.getValueAt(newMovingElementPosition, 0);         int newpos = owncol.indexOf(currentElementAtPosition);         DefaultTableModel dtm = (DefaultTableModel) allItems.getModel();         Vector v = getRow(movingElement);         dtm.removeRow(movingElementPosition);         dtm.insertRow(newMovingElementPosition, v);         JaWEController jc = JaWEManager.getInstance().getJaWEController();         jc.startUndouableChange();         owncol.reposition(movingElement, newpos);         List toSelect = new ArrayList();         toSelect.add(movingElement);         jc.endUndouableChange(toSelect);         setSelectedRow(newMovingElementPosition);         movingElementPosition = newMovingElementPosition;      }      changing = false;   }   protected Action newElementAction = new AbstractAction(JaWEActions.NEW_ACTION) {      public void actionPerformed(ActionEvent ae) {         JaWEController jc = JaWEManager.getInstance().getJaWEController();         XMLCollection col = (XMLCollection) getOwner();         XMLElement newEl = JaWEManager.getInstance().getXPDLObjectFactory().createXPDLObject(col, null, false);         boolean isForModal=PanelUtilities.isForModalDialog(newEl);         if (!isForModal && ipc.isModified()) {            int sw=ipc.showModifiedWarning();            if( sw == JOptionPane.CANCEL_OPTION || (sw==JOptionPane.YES_OPTION && ipc.isModified())) {               return;            }         }         boolean updInProg=false;         if (isForModal) {            StandardXPDLElementEditor ed = new StandardXPDLElementEditor();            ed.editXPDLElement(newEl);            boolean statOK=(ed.getStatus()==StandardXPDLElementEditor.STATUS_OK);            boolean canIns=true;            if (statOK) {               canIns=jc.canInsertElement(col, newEl);            }            if (!statOK || !canIns) {               if (!canIns) {                  jc.getJaWEFrame().message(ed.getLanguageDependentString("WarningCannotInsertElement"),JOptionPane.WARNING_MESSAGE);               }               return;            }            updInProg=true;         }         jc.startUndouableChange();         col.add(newEl);         List temp = new ArrayList();         temp.add(newEl);         jc.endUndouableChange(temp);         if (updInProg) {            setSelectedElement(newEl);         }         adjustActions();      }   };   protected Action editElementAction = new AbstractAction(JaWEActions.EDIT_PROPERTIES_ACTION) {      public void actionPerformed(ActionEvent ae) {         XMLElement editElement = getSelectedElement();         if (editElement != null) {            if (ipc.isModified()) {               int sw=ipc.showModifiedWarning();               if( sw == JOptionPane.CANCEL_OPTION || (sw==JOptionPane.YES_OPTION && ipc.isModified())) {                  return;               }            }            JaWEManager.getInstance().getXPDLElementEditor().editXPDLElement(editElement);         }      }   };   protected Action deleteElementAction = new AbstractAction(JaWEActions.DELETE_ACTION) {      public void actionPerformed(ActionEvent ae) {         XMLElement deleteElement = getSelectedElement();         if (deleteElement != null) {            JaWEController jc = JaWEManager.getInstance().getJaWEController();            List sel=new ArrayList();            sel.add(deleteElement.getParent());            if (jc.confirmDelete(sel, deleteElement)) {               XMLCollection parent = (XMLCollection)getOwner();               jc.startUndouableChange();               parent.remove(deleteElement);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -