Dépôt officiel du code source de l'ERP OpenConcerto
/trunk/OpenConcerto/src/org/openconcerto/erp/core/edm/AttachmentPanel.java |
---|
45,6 → 45,7 |
import java.io.IOException; |
import java.sql.SQLException; |
import java.util.ArrayList; |
import java.util.Collection; |
import java.util.Collections; |
import java.util.Comparator; |
import java.util.HashSet; |
65,6 → 66,7 |
public class AttachmentPanel extends JPanel { |
private final SQLRowAccessor rowSource; |
private final Collection<SQLRowAccessor> rowSecondaires; |
private List<ListDataListener> listeners = new ArrayList<>(); |
private int idParent = 1; |
74,8 → 76,14 |
private List<FilePanel> filePanels = new ArrayList<>(); |
public AttachmentPanel(SQLRowAccessor rowSource) { |
this(rowSource, Collections.emptyList()); |
} |
public AttachmentPanel(SQLRowAccessor rowSource, Collection<SQLRowAccessor> rowSecondaires) { |
super(); |
this.rowSource = rowSource; |
this.rowSecondaires = rowSecondaires; |
this.setLayout(new GridBagLayout()); |
this.parents.add(1); |
this.parentsNames.add("Racine"); |
92,13 → 100,17 |
} |
public void fireDataChanged() { |
for (ListDataListener listDataListener : listeners) { |
for (ListDataListener listDataListener : this.listeners) { |
listDataListener.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, 0)); |
} |
} |
public int getAttachementsSize() { |
return this.filePanels.size(); |
} |
public void initUI() { |
filePanels.clear(); |
this.filePanels.clear(); |
this.invalidate(); |
this.removeAll(); |
GridBagConstraints c = new DefaultGridBagConstraints(); |
106,7 → 118,7 |
// Recupération de la liste des fichiers |
// TODO requete dans un SwingWorker |
final SQLTable tableAttachment = rowSource.getTable().getTable("ATTACHMENT"); |
final SQLTable tableAttachment = this.rowSource.getTable().getTable("ATTACHMENT"); |
SQLRowValues rowVals = new SQLRowValues(tableAttachment); |
rowVals.putNulls(tableAttachment.getFieldsName()); |
115,7 → 127,13 |
where = where.and(new Where(tableAttachment.getField("SOURCE_ID"), "=", this.rowSource.getID())); |
where = where.and(new Where(tableAttachment.getField("ID_PARENT"), "=", this.idParent)); |
for (SQLRowAccessor rowSecondaire : this.rowSecondaires) { |
Where whereSec = new Where(tableAttachment.getField("SOURCE_TABLE"), "=", rowSecondaire.getTable().getName()); |
whereSec = whereSec.and(new Where(tableAttachment.getField("SOURCE_ID"), "=", rowSecondaire.getID())); |
where = where.or(whereSec); |
} |
final List<SQLRowValues> rAttachments = fetcher.fetch(where); |
c.fill = GridBagConstraints.BOTH; |
c.anchor = GridBagConstraints.WEST; |
211,7 → 229,7 |
public void actionPerformed(ActionEvent e) { |
AttachmentUtils utils = new AttachmentUtils(); |
try { |
utils.createFolder("Nouveau dossier", rowSource, idParent); |
utils.createFolder("Nouveau dossier", AttachmentPanel.this.rowSource, AttachmentPanel.this.idParent); |
} catch (SQLException e1) { |
JOptionPane.showMessageDialog(null, "Impossible de créer le dossier.", "Erreur", JOptionPane.ERROR_MESSAGE); |
} |
229,12 → 247,17 |
fd.setVisible(true); |
final String fileName = fd.getFile(); |
if (fileName != null) { |
try { |
File inFile = new File(fd.getDirectory(), fileName); |
AttachmentUtils utils = new AttachmentUtils(); |
utils.uploadFile(inFile, rowSource, idParent); |
utils.uploadFile(inFile, AttachmentPanel.this.rowSource, AttachmentPanel.this.idParent); |
initUI(); |
} catch (Exception ex) { |
ex.printStackTrace(); |
JOptionPane.showMessageDialog(AttachmentPanel.this, "Erreur lors de l'ajout du fichier " + fileName + "(" + ex.getMessage() + ")"); |
} |
} |
} |
}); |
ScrollablePanel files = new ScrollablePanel() { |
350,7 → 373,6 |
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); |
Transferable t = dtde.getTransferable(); |
try { |
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { |
@SuppressWarnings("unchecked") |
List<File> fileList = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor); |
362,10 → 384,15 |
if (cancelledByUser) { |
break; |
} |
try { |
if (!f.isDirectory()) { |
utils.uploadFile(f, rowSource, idParent); |
utils.uploadFile(f, AttachmentPanel.this.rowSource, AttachmentPanel.this.idParent); |
} |
} catch (Exception ex) { |
ex.printStackTrace(); |
JOptionPane.showMessageDialog(AttachmentPanel.this, "Erreur lors de l'ajout du fichier " + f.getAbsolutePath() + "(" + ex.getMessage() + ")"); |
} |
} |
initUI(); |
} |
} catch (Exception e) { |
379,7 → 406,7 |
} |
public Set<Attachment> getSelectedAttachments() { |
return selectedAttachments; |
return this.selectedAttachments; |
} |
public void select(Attachment a) { |