From: Wolfgang M. M. <wol...@us...> - 2004-06-02 11:30:35
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2956/src/org/exist/client Modified Files: ClientFrame.java Log Message: Added support for moving collections or resources, and reindexing collections. Index: ClientFrame.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/client/ClientFrame.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ClientFrame.java 3 May 2004 13:05:04 -0000 1.18 --- ClientFrame.java 2 Jun 2004 11:30:24 -0000 1.19 *************** *** 52,55 **** --- 52,56 ---- import java.util.Enumeration; import java.util.Properties; + import java.util.Vector; import javax.swing.BorderFactory; *************** *** 97,101 **** --- 98,104 ---- import org.exist.storage.serializers.EXistOutputKeys; import org.exist.xmldb.CollectionImpl; + import org.exist.xmldb.CollectionManagementServiceImpl; import org.exist.xmldb.EXistResource; + import org.exist.xmldb.IndexQueryService; import org.exist.xmldb.UserManagementService; import org.gnu.readline.Readline; *************** *** 169,172 **** --- 172,176 ---- setJMenuBar(createMenuBar()); + // create the toolbar JToolBar toolbar = new JToolBar(); URL url = getClass().getResource("icons/Up24.gif"); *************** *** 276,279 **** --- 280,284 ---- toolbar.add(button); + // the split pane separates the resource view table from the shell JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT); split.setResizeWeight(0.5); *************** *** 308,311 **** --- 313,317 ---- statusbar = new JLabel(); + statusbar.setMinimumSize(new Dimension(400, 15)); statusbar.setBorder(BorderFactory .createBevelBorder(BevelBorder.LOWERED)); *************** *** 350,353 **** --- 356,377 ---- fileMenu.add(item); + item = new JMenuItem("Move", KeyEvent.VK_M); + item.setAccelerator(KeyStroke.getKeyStroke("control M")); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + moveAction(e); + } + }); + fileMenu.add(item); + + item = new JMenuItem("Reindex collection", KeyEvent.VK_R); + item.setAccelerator(KeyStroke.getKeyStroke("control R")); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + reindexAction(e); + } + }); + fileMenu.add(item); + item = new JMenuItem("Resource properties"); item.setAccelerator(KeyStroke.getKeyStroke("control P")); *************** *** 693,700 **** "Are you sure you want to remove the selected " + "resources?", "Confirm deletion", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { - final JFrame parent = this; Runnable removeTask = new Runnable() { public void run() { ! ProgressMonitor monitor = new ProgressMonitor(parent, "Remove Progress", "", 1, rows.length); monitor.setMillisToDecideToPopup(500); --- 717,723 ---- "Are you sure you want to remove the selected " + "resources?", "Confirm deletion", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { Runnable removeTask = new Runnable() { public void run() { ! ProgressMonitor monitor = new ProgressMonitor(ClientFrame.this, "Remove Progress", "", 1, rows.length); monitor.setMillisToDecideToPopup(500); *************** *** 737,740 **** --- 760,862 ---- } + private void moveAction(ActionEvent ev) { + final int[] rows = fileman.getSelectedRows(); + final Object[] res = new Object[rows.length]; + for (int i = 0; i < rows.length; i++) { + res[i] = resources.getValueAt(rows[i], 3); + } + String[] collections = null; + try { + Collection root = client.getCollection("/db"); + Vector collectionsVec = getCollections(root, new Vector()); + collections = new String[collectionsVec.size()]; + collectionsVec.toArray(collections); + } catch (XMLDBException e) { + showErrorMessage(e.getMessage(), e); + return; + } + Object val = JOptionPane.showInputDialog(this, "Select target collection", "Move", JOptionPane.QUESTION_MESSAGE, + null, collections, collections[0]); + if(val == null) + return; + final String destinationPath = (String)val; + Runnable moveTask = new Runnable() { + public void run() { + try { + CollectionManagementServiceImpl service = (CollectionManagementServiceImpl) + client.current.getService("CollectionManagementService", "1.0"); + for(int i = 0; i < res.length; i++) { + setStatus("Moving " + res[i].toString() + " to " + destinationPath + "..."); + if(res[i] instanceof InteractiveClient.CollectionName) + service.move(res[i].toString(), destinationPath, null); + else + service.moveResource(res[i].toString(), destinationPath, null); + } + client.reloadCollection(); + } catch (XMLDBException e) { + showErrorMessage(e.getMessage(), e); + } + setStatus("Move completed."); + } + }; + new Thread(moveTask).start(); + } + + private Vector getCollections(Collection root, Vector collectionsList) + throws XMLDBException { + collectionsList.addElement(root.getName()); + String[] childCollections= root.listChildCollections(); + Collection child; + for (int i= 0; i < childCollections.length; i++) { + child= root.getChildCollection(childCollections[i]); + getCollections(child, collectionsList); + } + return collectionsList; + } + + private void reindexAction(ActionEvent ev) { + final int[] rows = fileman.getSelectedRows(); + Object[] res; + if(rows.length == 0) { + res = new Object[1]; + res[0] = new InteractiveClient.CollectionName(client.path); + } else { + res = new Object[rows.length]; + for (int i = 0; i < rows.length; i++) { + res[i] = resources.getValueAt(rows[i], 3); + if(!(res[i] instanceof InteractiveClient.CollectionName)) { + JOptionPane.showMessageDialog(this, "Only collections can be reindexed.", "Error", JOptionPane.ERROR_MESSAGE); + return; + } + } + } + + if (JOptionPane.showConfirmDialog(this, + "Are you sure you want to reindex the selected collections \nand all resources below them?", + "Confirm reindex", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { + final Object collections[] = res; + Runnable reindexThread = new Runnable() { + public void run() { + ClientFrame.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + IndexQueryService service; + try { + service = (IndexQueryService) + client.current.getService("IndexQueryService", "1.0"); + for(int i = 0; i < collections.length; i++) { + InteractiveClient.CollectionName next = (InteractiveClient.CollectionName)collections[i]; + setStatus("Reindexing collection " + next + "..."); + service.reindexCollection(next.toString()); + } + setStatus("Reindex completed."); + } catch (XMLDBException e) { + showErrorMessage(e.getMessage(), e); + } + ClientFrame.this.setCursor(Cursor.getDefaultCursor()); + } + }; + new Thread(reindexThread).start(); + } + } + private void uploadAction(ActionEvent ev) { String dir = properties.getProperty("working-dir", System |