Author: fmui
Date: Fri Aug 6 10:33:13 2010
New Revision: 982928
URL: http://svn.apache.org/viewvc?rev=982928&view=rev
Log:
- fixed sorting problem
- added simple drag-and-drop
Modified:
incubator/chemistry/opencmis-swingclient/trunk/pom.xml
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientHelper.java
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/CreateDocumentDialog.java
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/FolderTable.java
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/model/ClientModel.java
Modified: incubator/chemistry/opencmis-swingclient/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/pom.xml?rev=982928&r1=982927&r2=982928&view=diff
==============================================================================
--- incubator/chemistry/opencmis-swingclient/trunk/pom.xml (original)
+++ incubator/chemistry/opencmis-swingclient/trunk/pom.xml Fri Aug 6 10:33:13
2010
@@ -100,8 +100,8 @@
<!-- Project Environment -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <maven.compile.source>1.5</maven.compile.source>
- <maven.compile.target>1.5</maven.compile.target>
+ <maven.compile.source>1.6</maven.compile.source>
+ <maven.compile.target>1.6</maven.compile.target>
</properties>
<build>
Modified:
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientHelper.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientHelper.java?rev=982928&r1=982927&r2=982928&view=diff
==============================================================================
---
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientHelper.java
(original)
+++
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientHelper.java
Fri Aug 6 10:33:13 2010
@@ -122,4 +122,60 @@ public class ClientHelper {
}
}
}
+
+ public static File createTempFile(String filename) {
+ String tempDir = System.getProperty("java.io.tmpdir");
+ File clientTempDir = new File(tempDir, "cmisswingclient");
+ if (!clientTempDir.exists()) {
+ clientTempDir.mkdirs();
+ }
+ clientTempDir.deleteOnExit();
+
+ File tempFile = new File(clientTempDir, filename);
+ tempFile.deleteOnExit();
+
+ return tempFile;
+ }
+
+ public static File createTempFileFromDocument(Document doc) throws
Exception {
+ InputStream inStream = null;
+ OutputStream outStream = null;
+
+ try {
+ ContentStream content = doc.getContentStream();
+ inStream = new BufferedInputStream(content.getStream());
+
+ String filename = doc.getContentStreamFileName();
+ if ((filename == null) || (filename.length() == 0)) {
+ filename = doc.getName();
+ }
+ if ((filename == null) || (filename.length() == 0)) {
+ filename = "document";
+ }
+
+ File tempFile =
ClientHelper.createTempFile(doc.getContentStreamFileName());
+ outStream = new FileOutputStream(tempFile);
+
+ byte[] buffer = new byte[4096];
+ int b;
+ while ((b = inStream.read(buffer)) > -1) {
+ outStream.write(buffer, 0, b);
+ }
+
+ return tempFile;
+ } finally {
+ if (inStream != null) {
+ try {
+ inStream.close();
+ } catch (IOException e) {
+ }
+ }
+ if (outStream != null) {
+ try {
+ outStream.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ }
}
Modified:
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/CreateDocumentDialog.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/CreateDocumentDialog.java?rev=982928&r1=982927&r2=982928&view=diff
==============================================================================
---
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/CreateDocumentDialog.java
(original)
+++
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/CreateDocumentDialog.java
Fri Aug 6 10:33:13 2010
@@ -24,6 +24,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
+import java.io.File;
import javax.swing.JButton;
import javax.swing.JComboBox;
@@ -39,104 +40,106 @@ import org.apache.chemistry.opencmis.swi
public class CreateDocumentDialog extends CreateDialog {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private JTextField nameField;
- private JComboBox typeBox;
- private JTextField filenameField;
- private JComboBox versioningStateBox;
-
- public CreateDocumentDialog(Frame owner, ClientModel model) {
- super(owner, "Create Document", model);
- createGUI();
- }
-
- private void createGUI() {
- final CreateDocumentDialog thisDialog = this;
-
- nameField = new JTextField(60);
- createRow("Name:", nameField, 0);
-
- typeBox = new
JComboBox(getTypes(BaseTypeId.CMIS_DOCUMENT.value()));
- typeBox.setSelectedIndex(0);
- typeBox.addItemListener(new ItemListener() {
- public void itemStateChanged(ItemEvent e) {
- DocumentTypeDefinition type =
(DocumentTypeDefinition) ((ObjectTypeItem) typeBox
-
.getSelectedItem()).getObjectType();
- if (type.isVersionable()) {
-
versioningStateBox.setSelectedItem(VersioningState.MAJOR);
- } else {
-
versioningStateBox.setSelectedItem(VersioningState.NONE);
- }
- }
- });
-
- createRow("Type:", typeBox, 1);
-
- JPanel filePanel = new JPanel(new BorderLayout());
-
- filenameField = new JTextField(30);
- filePanel.add(filenameField, BorderLayout.CENTER);
-
- JButton browseButton = new JButton("Browse");
- browseButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- JFileChooser fileChooser = new JFileChooser();
- int chooseResult =
fileChooser.showDialog(filenameField,
- "Select");
- if (chooseResult ==
JFileChooser.APPROVE_OPTION) {
- if
(fileChooser.getSelectedFile().isFile()) {
-
filenameField.setText(fileChooser.getSelectedFile()
-
.getAbsolutePath());
- if
(nameField.getText().trim().length() == 0) {
-
nameField.setText(fileChooser.getSelectedFile()
-
.getName());
- }
- }
- }
- }
- });
- filePanel.add(browseButton, BorderLayout.LINE_END);
-
- createRow("File:", filePanel, 2);
-
- versioningStateBox = new JComboBox(new Object[] {
VersioningState.NONE,
- VersioningState.MAJOR, VersioningState.MINOR,
- VersioningState.CHECKEDOUT });
- if (((DocumentTypeDefinition) ((ObjectTypeItem) typeBox
-
.getSelectedItem()).getObjectType()).isVersionable()) {
-
versioningStateBox.setSelectedItem(VersioningState.MAJOR);
- } else {
-
versioningStateBox.setSelectedItem(VersioningState.NONE);
- }
- createRow("Versioning State:", versioningStateBox, 3);
-
- JButton createButton = new JButton("Create Document");
- createButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- String name = nameField.getText();
- String type = ((ObjectTypeItem)
typeBox.getSelectedItem())
- .getObjectType().getId();
- String filename = filenameField.getText();
-
- try {
- getClientModel().createDocument(
- name,
- type,
- filename,
- (VersioningState)
versioningStateBox
-
.getSelectedItem());
- getClientModel().reloadFolder();
-
- thisDialog.setVisible(false);
- thisDialog.dispose();
- } catch (Exception e) {
- ClientHelper.showError(null, e);
- }
- }
- });
- createRow("", createButton, 4);
-
- showDialog();
- }
+ private JTextField nameField;
+ private JComboBox typeBox;
+ private JTextField filenameField;
+ private JComboBox versioningStateBox;
+
+ public CreateDocumentDialog(Frame owner, ClientModel model) {
+ this(owner, model, null);
+ }
+
+ public CreateDocumentDialog(Frame owner, ClientModel model, File file) {
+ super(owner, "Create Document", model);
+ createGUI(file);
+ }
+
+ private void createGUI(File file) {
+ final CreateDocumentDialog thisDialog = this;
+
+ nameField = new JTextField(60);
+ createRow("Name:", nameField, 0);
+
+ typeBox = new JComboBox(getTypes(BaseTypeId.CMIS_DOCUMENT.value()));
+ typeBox.setSelectedIndex(0);
+ typeBox.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ DocumentTypeDefinition type = (DocumentTypeDefinition)
((ObjectTypeItem) typeBox.getSelectedItem())
+ .getObjectType();
+ if (type.isVersionable()) {
+ versioningStateBox.setSelectedItem(VersioningState.MAJOR);
+ } else {
+ versioningStateBox.setSelectedItem(VersioningState.NONE);
+ }
+ }
+ });
+
+ createRow("Type:", typeBox, 1);
+
+ JPanel filePanel = new JPanel(new BorderLayout());
+
+ filenameField = new JTextField(30);
+ filePanel.add(filenameField, BorderLayout.CENTER);
+
+ JButton browseButton = new JButton("Browse");
+ browseButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ JFileChooser fileChooser = new JFileChooser();
+ int chooseResult = fileChooser.showDialog(filenameField,
"Select");
+ if (chooseResult == JFileChooser.APPROVE_OPTION) {
+ if (fileChooser.getSelectedFile().isFile()) {
+ setFile(fileChooser.getSelectedFile());
+ }
+ }
+ }
+ });
+ filePanel.add(browseButton, BorderLayout.LINE_END);
+
+ createRow("File:", filePanel, 2);
+
+ versioningStateBox = new JComboBox(new Object[] {
VersioningState.NONE, VersioningState.MAJOR,
+ VersioningState.MINOR, VersioningState.CHECKEDOUT });
+ if (((DocumentTypeDefinition) ((ObjectTypeItem)
typeBox.getSelectedItem()).getObjectType()).isVersionable()) {
+ versioningStateBox.setSelectedItem(VersioningState.MAJOR);
+ } else {
+ versioningStateBox.setSelectedItem(VersioningState.NONE);
+ }
+ createRow("Versioning State:", versioningStateBox, 3);
+
+ JButton createButton = new JButton("Create Document");
+ createButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ String name = nameField.getText();
+ String type = ((ObjectTypeItem)
typeBox.getSelectedItem()).getObjectType().getId();
+ String filename = filenameField.getText();
+
+ try {
+ getClientModel().createDocument(name, type, filename,
+ (VersioningState)
versioningStateBox.getSelectedItem());
+ getClientModel().reloadFolder();
+
+ thisDialog.setVisible(false);
+ thisDialog.dispose();
+ } catch (Exception e) {
+ ClientHelper.showError(null, e);
+ }
+ }
+ });
+ createRow("", createButton, 4);
+
+ if (file != null) {
+ setFile(file);
+ }
+
+ showDialog();
+ }
+
+ private void setFile(File file) {
+ filenameField.setText(file.getAbsolutePath());
+ if (nameField.getText().trim().length() == 0) {
+ nameField.setText(file.getName());
+ }
+ }
}
Modified:
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/FolderTable.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/FolderTable.java?rev=982928&r1=982927&r2=982928&view=diff
==============================================================================
---
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/FolderTable.java
(original)
+++
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/FolderTable.java
Fri Aug 6 10:33:13 2010
@@ -19,19 +19,32 @@
package org.apache.chemistry.opencmis.swingclient;
import java.awt.Cursor;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.GregorianCalendar;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import javax.swing.DropMode;
import javax.swing.ImageIcon;
+import javax.swing.JComponent;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
+import javax.swing.TransferHandler;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
+import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
import org.apache.chemistry.opencmis.client.api.CmisObject;
@@ -44,192 +57,300 @@ import org.apache.chemistry.opencmis.swi
public class FolderTable extends JTable implements FolderListener {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private static final String[] COLUMN_NAMES = { "", "Name", "Type",
- "Content Type", "Size", "Creation Date", "Created by",
- "Modification Date", "Modified by", "Id" };
- private static final int[] COLUMN_WIDTHS = { 24, 200, 150, 150, 80, 200,
- 100, 200, 100, 300 };
-
- private ClientModel model;
-
- private Map<BaseTypeId, ImageIcon> icons;
-
- public FolderTable(final ClientModel model) {
- super();
-
- this.model = model;
-
- setModel(new FolderTableModel());
-
- setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- setAutoResizeMode(AUTO_RESIZE_OFF);
- setAutoCreateRowSorter(true);
-
- for (int i = 0; i < COLUMN_WIDTHS.length; i++) {
- TableColumn column = getColumnModel().getColumn(i);
- column.setPreferredWidth(COLUMN_WIDTHS[i]);
- }
-
- getSelectionModel().addListSelectionListener(
- new ListSelectionListener() {
- public void
valueChanged(ListSelectionEvent e) {
- if (e.getValueIsAdjusting()) {
- return;
- }
-
- int row = getSelectedRow();
- if (row > -1) {
- String id =
model.getCurrentChildren().get(
-
getSelectedRow()).getId();
-
- try {
- setCursor(Cursor
-
.getPredefinedCursor(Cursor.WAIT_CURSOR));
-
model.loadObject(id);
- } catch (Exception ex) {
-
ClientHelper.showError(null, ex);
- return;
- } finally {
- setCursor(Cursor
-
.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
- }
- }
- });
-
- addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- if (e.getClickCount() == 2) {
- doAction();
- }
- }
- });
-
- addKeyListener(new KeyListener() {
- public void keyTyped(KeyEvent e) {
- }
-
- public void keyReleased(KeyEvent e) {
- if (e.getKeyCode() == KeyEvent.VK_ENTER) {
- doAction();
- }
- }
-
- public void keyPressed(KeyEvent e) {
- }
- });
-
- loadIcons();
- }
-
- private void loadIcons() {
- icons = new HashMap<BaseTypeId, ImageIcon>();
- icons.put(BaseTypeId.CMIS_DOCUMENT, ClientHelper
- .getIcon("document.png"));
- icons.put(BaseTypeId.CMIS_FOLDER,
ClientHelper.getIcon("folder.png"));
- icons.put(BaseTypeId.CMIS_RELATIONSHIP, ClientHelper
- .getIcon("relationship.png"));
- icons.put(BaseTypeId.CMIS_POLICY,
ClientHelper.getIcon("policy.png"));
- }
-
- public void folderLoaded(ClientModelEvent event) {
- event.getClientModel().getCurrentChildren();
-
- ((FolderTableModel) getModel()).fireTableDataChanged();
- }
-
- private void doAction() {
- int row = getSelectedRow();
- if ((row > -1) && (row < model.getCurrentChildren().size())) {
- CmisObject object = model.getCurrentChildren().get(row);
-
- if (object instanceof Document) {
- download((Document) object);
- } else if (object instanceof Folder) {
- try {
-
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- model.loadFolder(object.getId(), false);
- } catch (Exception ex) {
- ClientHelper.showError(null, ex);
- return;
- } finally {
-
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
- }
- }
- }
-
- private void download(Document doc) {
- ClientHelper.download(this.getParent(), doc, null);
- }
-
- class FolderTableModel extends AbstractTableModel {
-
- private static final long serialVersionUID = 1L;
-
- public String getColumnName(int columnIndex) {
- return COLUMN_NAMES[columnIndex];
- }
-
- public int getColumnCount() {
- return COLUMN_NAMES.length;
- }
-
- public int getRowCount() {
- return model.getCurrentChildren().size();
- }
-
- public Object getValueAt(int rowIndex, int columnIndex) {
- CmisObject obj =
model.getCurrentChildren().get(rowIndex);
-
- switch (columnIndex) {
- case 0:
- return icons.get(obj.getBaseTypeId());
- case 1:
- return obj.getName();
- case 2:
- return obj.getType().getId();
- case 3:
- if (obj instanceof Document) {
- return ((Document)
obj).getContentStreamMimeType();
- } else {
- return null;
- }
- case 4:
- if (obj instanceof Document) {
- return ((Document)
obj).getContentStreamLength();
- } else {
- return null;
- }
- case 5:
- return (obj.getCreationDate() == null ? null :
ClientHelper
-
.getDateString(obj.getCreationDate()));
- case 6:
- return obj.getCreatedBy();
- case 7:
- return (obj.getLastModificationDate() == null ?
null
- : ClientHelper.getDateString(obj
-
.getLastModificationDate()));
- case 8:
- return obj.getLastModifiedBy();
- case 9:
- return obj.getId();
- }
-
- return "";
- }
-
- @Override
- public Class<?> getColumnClass(int columnIndex) {
- if (columnIndex == 0) {
- return ImageIcon.class;
- } else if (columnIndex == 4) {
- return Long.class;
- }
-
- return String.class;
- }
- }
+ private static final String[] COLUMN_NAMES = { "", "Name", "Type",
"Content Type", "Size", "Creation Date",
+ "Created by", "Modification Date", "Modified by", "Id" };
+ private static final int[] COLUMN_WIDTHS = { 24, 200, 150, 150, 80, 180,
100, 180, 100, 300 };
+ private static final int ID_COLUMN = 9;
+
+ private ClientModel model;
+
+ private Map<BaseTypeId, ImageIcon> icons;
+
+ public FolderTable(final ClientModel model) {
+ super();
+
+ this.model = model;
+
+ setModel(new FolderTableModel());
+
+ setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ setAutoResizeMode(AUTO_RESIZE_OFF);
+ setAutoCreateRowSorter(true);
+
+ setDefaultRenderer(GregorianCalendar.class, new
GregorianCalendarRenderer());
+ setTransferHandler(new FolderTransferHandler());
+ setDragEnabled(true);
+ setDropMode(DropMode.INSERT);
+
+ for (int i = 0; i < COLUMN_WIDTHS.length; i++) {
+ TableColumn column = getColumnModel().getColumn(i);
+ column.setPreferredWidth(COLUMN_WIDTHS[i]);
+ }
+
+ getSelectionModel().addListSelectionListener(new
ListSelectionListener() {
+ public void valueChanged(ListSelectionEvent e) {
+ if (e.getValueIsAdjusting()) {
+ return;
+ }
+
+ int row = getSelectedRow();
+ if (row > -1) {
+ String id = getValueAt(row, ID_COLUMN).toString();
+
+ try {
+
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ model.loadObject(id);
+ } catch (Exception ex) {
+ ClientHelper.showError(null, ex);
+ return;
+ } finally {
+
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+ }
+ });
+
+ addMouseListener(new MouseAdapter() {
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() == 2) {
+ doAction();
+ }
+ }
+ });
+
+ addKeyListener(new KeyListener() {
+ public void keyTyped(KeyEvent e) {
+ }
+
+ public void keyReleased(KeyEvent e) {
+ if (e.getKeyCode() == KeyEvent.VK_ENTER) {
+ doAction();
+ }
+ }
+
+ public void keyPressed(KeyEvent e) {
+ }
+ });
+
+ loadIcons();
+ }
+
+ private void loadIcons() {
+ icons = new HashMap<BaseTypeId, ImageIcon>();
+ icons.put(BaseTypeId.CMIS_DOCUMENT,
ClientHelper.getIcon("document.png"));
+ icons.put(BaseTypeId.CMIS_FOLDER, ClientHelper.getIcon("folder.png"));
+ icons.put(BaseTypeId.CMIS_RELATIONSHIP,
ClientHelper.getIcon("relationship.png"));
+ icons.put(BaseTypeId.CMIS_POLICY, ClientHelper.getIcon("policy.png"));
+ }
+
+ public void folderLoaded(ClientModelEvent event) {
+ event.getClientModel().getCurrentChildren();
+
+ ((FolderTableModel) getModel()).fireTableDataChanged();
+ }
+
+ private void doAction() {
+ int row = getSelectedRow();
+ if ((row > -1) && (row < model.getCurrentChildren().size())) {
+ String id = getValueAt(row, ID_COLUMN).toString();
+ CmisObject object = model.getFromCurrentChildren(id);
+
+ if (object instanceof Document) {
+ download((Document) object);
+ } else if (object instanceof Folder) {
+ try {
+ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ model.loadFolder(object.getId(), false);
+ } catch (Exception ex) {
+ ClientHelper.showError(null, ex);
+ return;
+ } finally {
+
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+ }
+ }
+
+ private void download(Document doc) {
+ ClientHelper.download(this.getParent(), doc, null);
+ }
+
+ class FolderTableModel extends AbstractTableModel {
+
+ private static final long serialVersionUID = 1L;
+
+ public String getColumnName(int columnIndex) {
+ return COLUMN_NAMES[columnIndex];
+ }
+
+ public int getColumnCount() {
+ return COLUMN_NAMES.length;
+ }
+
+ public int getRowCount() {
+ return model.getCurrentChildren().size();
+ }
+
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ CmisObject obj = model.getCurrentChildren().get(rowIndex);
+
+ switch (columnIndex) {
+ case 0:
+ return icons.get(obj.getBaseTypeId());
+ case 1:
+ return obj.getName();
+ case 2:
+ return obj.getType().getId();
+ case 3:
+ if (obj instanceof Document) {
+ return ((Document) obj).getContentStreamMimeType();
+ } else {
+ return null;
+ }
+ case 4:
+ if (obj instanceof Document) {
+ return ((Document) obj).getContentStreamLength();
+ } else {
+ return null;
+ }
+ case 5:
+ return obj.getCreationDate();
+ case 6:
+ return obj.getCreatedBy();
+ case 7:
+ return obj.getLastModificationDate();
+ case 8:
+ return obj.getLastModifiedBy();
+ case ID_COLUMN:
+ return obj.getId();
+ }
+
+ return "";
+ }
+
+ @Override
+ public Class<?> getColumnClass(int columnIndex) {
+ switch (columnIndex) {
+ case 0:
+ return ImageIcon.class;
+ case 4:
+ return Long.class;
+ case 5:
+ case 7:
+ return GregorianCalendar.class;
+ }
+
+ return String.class;
+ }
+ }
+
+ class GregorianCalendarRenderer extends DefaultTableCellRenderer {
+ private static final long serialVersionUID = 1L;
+
+ private SimpleDateFormat sdf;
+
+ public GregorianCalendarRenderer() {
+ super();
+ sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss ZZZ");
+ }
+
+ public void setValue(Object value) {
+ setText((value == null) ? "" : sdf.format(((GregorianCalendar)
value).getTime()));
+ }
+ }
+
+ class FolderTransferHandler extends TransferHandler {
+
+ private static final long serialVersionUID = 1L;
+
+ public FolderTransferHandler() {
+ super();
+ }
+
+ @Override
+ public boolean canImport(TransferSupport support) {
+ if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
{
+ return false;
+ }
+
+ if (!support.isDrop()) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public boolean importData(TransferSupport support) {
+ if (!canImport(support)) {
+ return false;
+ }
+
+ File file = null;
+ try {
+ List<File> fileList = (List<File>)
support.getTransferable().getTransferData(
+ DataFlavor.javaFileListFlavor);
+
+ if ((fileList == null) || (fileList.size() != 1) ||
(fileList.get(0) == null)
+ || !fileList.get(0).isFile()) {
+ return false;
+ }
+
+ file = fileList.get(0);
+ } catch (Exception ex) {
+ ClientHelper.showError(null, ex);
+ return false;
+ }
+
+ new CreateDocumentDialog(null, model, file);
+
+ return true;
+ }
+
+ @Override
+ public int getSourceActions(JComponent c) {
+ return COPY;
+ }
+
+ @Override
+ protected Transferable createTransferable(JComponent c) {
+ int row = getSelectedRow();
+ if ((row > -1) && (row < model.getCurrentChildren().size())) {
+ String id = getValueAt(row, ID_COLUMN).toString();
+ CmisObject object = model.getFromCurrentChildren(id);
+
+ if (object instanceof Document) {
+ Document doc = (Document) object;
+
+ File tempFile = null;
+ try {
+ tempFile =
ClientHelper.createTempFileFromDocument(doc);
+ } catch (Exception e) {
+ ClientHelper.showError(null, e);
+ }
+
+ final File tempTransFile = tempFile;
+
+ return new Transferable() {
+ public boolean isDataFlavorSupported(DataFlavor
flavor) {
+ return flavor == DataFlavor.javaFileListFlavor;
+ }
+
+ public DataFlavor[] getTransferDataFlavors() {
+ return new DataFlavor[] {
DataFlavor.javaFileListFlavor };
+ }
+
+ public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
+ return (List<File>)
Collections.singletonList(tempTransFile);
+ }
+ };
+ }
+ }
+
+ return null;
+ }
+ }
}
Modified:
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/model/ClientModel.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/model/ClientModel.java?rev=982928&r1=982927&r2=982928&view=diff
==============================================================================
---
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/model/ClientModel.java
(original)
+++
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/model/ClientModel.java
Fri Aug 6 10:33:13 2010
@@ -286,6 +286,20 @@ public class ClientModel {
return currentChildren;
}
+ public synchronized CmisObject getFromCurrentChildren(String id) {
+ if((currentChildren == null) || (currentChildren.isEmpty())) {
+ return null;
+ }
+
+ for(CmisObject o: currentChildren) {
+ if(o.getId().equals(id)) {
+ return o;
+ }
+ }
+
+ return null;
+ }
+
private synchronized void setCurrentFolder(Folder folder, List<CmisObject>
children) {
currentFolder = folder;
currentChildren = children;