()
| 74 | } |
| 75 | |
| 76 | protected void initGuiComponents(){ |
| 77 | setLayout(new BorderLayout()); |
| 78 | renderer = new DocumentNameRenderer(); |
| 79 | |
| 80 | docTable = new XJTable(docTableModel); |
| 81 | docTable.setSortable(true); |
| 82 | docTable.setSortedColumn(DocumentTableModel.COL_INDEX); |
| 83 | docTable.setAutoResizeMode(XJTable.AUTO_RESIZE_LAST_COLUMN); |
| 84 | docTable.getColumnModel().getColumn(DocumentTableModel.COL_NAME). |
| 85 | setCellRenderer(renderer); |
| 86 | docTable.setDragEnabled(true); |
| 87 | docTable.setTransferHandler(new TransferHandler() { |
| 88 | // drag and drop to move up and down the table rows |
| 89 | // import selected documents from the resources tree |
| 90 | String source = ""; |
| 91 | @Override |
| 92 | public int getSourceActions(JComponent c) { |
| 93 | return MOVE; |
| 94 | } |
| 95 | @Override |
| 96 | protected Transferable createTransferable(JComponent c) { |
| 97 | int selectedRows[] = docTable.getSelectedRows(); |
| 98 | Arrays.sort(selectedRows); |
| 99 | return new StringSelection("CorpusEditor" |
| 100 | + Arrays.toString(selectedRows)); |
| 101 | } |
| 102 | @Override |
| 103 | protected void exportDone(JComponent c, Transferable data, int action) { |
| 104 | } |
| 105 | @Override |
| 106 | public boolean canImport(JComponent c, DataFlavor[] flavors) { |
| 107 | for(DataFlavor flavor : flavors) { |
| 108 | if(DataFlavor.stringFlavor.equals(flavor)) { |
| 109 | return true; |
| 110 | } |
| 111 | } |
| 112 | return false; |
| 113 | } |
| 114 | @Override |
| 115 | public boolean importData(JComponent c, Transferable t) { |
| 116 | if (!canImport(c, t.getTransferDataFlavors())) { |
| 117 | return false; |
| 118 | } |
| 119 | try { |
| 120 | source = (String)t.getTransferData(DataFlavor.stringFlavor); |
| 121 | if (source.startsWith("ResourcesTree")) { |
| 122 | int insertion = docTable.getSelectedRow(); |
| 123 | List<Document> documents = new ArrayList<Document>(); |
| 124 | source = source.replaceFirst("^ResourcesTree\\[", ""); |
| 125 | source = source.replaceFirst("\\]$", ""); |
| 126 | final String documentsNames[] = source.split(", "); |
| 127 | List<Resource> loadedDocuments; |
| 128 | try { |
| 129 | loadedDocuments = |
| 130 | Gate.getCreoleRegister().getAllInstances("gate.Document"); |
| 131 | } catch(GateException e) { |
| 132 | e.printStackTrace(); |
| 133 | return false; |
no test coverage detected