/** * Adds the specified files to the list of import data. * * @param files The files to import. */ private void insertFiles(Map<File, StatusLabel> files) { if (files == null || files.size() == 0) { statusLabel.setText("No files to import."); return; } components = new HashMap<File, FileImportComponent>(); totalFiles = files.size(); String text = "Importing " + totalFiles + " file"; if (totalFiles > 1) text += "s"; statusLabel.setText(text); Entry entry; Iterator i = files.entrySet().iterator(); FileImportComponent c; JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); int index = 0; p.setBorder(BorderFactory.createLineBorder(Color.BLACK)); File f; DatasetData d = dataset; Object node = refNode; if (folderAsContainer) { node = null; d = new DatasetData(); d.setName(file.getName()); } while (i.hasNext()) { entry = (Entry) i.next(); f = (File) entry.getKey(); c = new FileImportComponent(f, folderAsContainer, browsable, group, singleGroup); if (f.isFile()) { c.setLocation(data, d, node); c.setParent(this); } c.showContainerLabel(showContainerLabel); c.setType(getType()); attachListeners(c); c.setStatusLabel((StatusLabel) entry.getValue()); if (index % 2 == 0) c.setBackground(UIUtilities.BACKGROUND_COLOUR_EVEN); else c.setBackground(UIUtilities.BACKGROUND_COLOUR_ODD); components.put((File) entry.getKey(), c); p.add(c); index++; } removeAll(); pane = EditorUtil.createTaskPane(""); pane.setCollapsed(false); setNumberOfImport(); IconManager icons = IconManager.getInstance(); pane.setIcon(icons.getIcon(IconManager.DIRECTORY)); Font font = pane.getFont(); pane.setFont(font.deriveFont(font.getStyle(), font.getSize() - 2)); pane.add(p); double[][] size = {{TableLayout.FILL}, {TableLayout.PREFERRED}}; setLayout(new TableLayout(size)); add(pane, "0, 0"); validate(); repaint(); }
/** * Listens to property fired by the <code>StatusLabel</code>. * * @see PropertyChangeListener#propertyChange(PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent evt) { String name = evt.getPropertyName(); if (StatusLabel.FILES_SET_PROPERTY.equals(name)) { if (isCancelled()) { statusLabel.setText(CANCEL_TEXT); busyLabel.setBusy(false); busyLabel.setVisible(false); return; } Map<File, StatusLabel> files = (Map<File, StatusLabel>) evt.getNewValue(); insertFiles((Map<File, StatusLabel>) evt.getNewValue()); firePropertyChange(IMPORT_FILES_NUMBER_PROPERTY, null, files.size()); } else if (StatusLabel.FILE_IMPORT_STARTED_PROPERTY.equals(name)) { StatusLabel sl = (StatusLabel) evt.getNewValue(); if (sl == statusLabel && busyLabel != null) { busyLabel.setBusy(true); busyLabel.setVisible(true); cancelButton.setVisible(sl.isCancellable()); } } else if (StatusLabel.CANCELLABLE_IMPORT_PROPERTY.equals(name)) { StatusLabel sl = (StatusLabel) evt.getNewValue(); cancelButton.setVisible(sl.isCancellable()); } else if (StatusLabel.FILE_IMPORTED_PROPERTY.equals(name)) { Object[] results = (Object[]) evt.getNewValue(); File f = (File) results[0]; if (f.getAbsolutePath().equals(file.getAbsolutePath())) { setStatus(false, results[1]); if (f.isFile()) { if (hasImportFailed()) firePropertyChange(IMPORT_STATUS_CHANGE_PROPERTY, null, FAILURE); else if (isCancelled()) firePropertyChange(IMPORT_STATUS_CHANGE_PROPERTY, null, PARTIAL); else firePropertyChange(IMPORT_STATUS_CHANGE_PROPERTY, null, SUCCESS); } } } else if (StatusLabel.FILE_RESET_PROPERTY.equals(name)) { file = (File) evt.getNewValue(); fileNameLabel.setText(file.getName()); } else if (ThumbnailLabel.BROWSE_PLATE_PROPERTY.equals(name)) { firePropertyChange(BROWSE_PROPERTY, evt.getOldValue(), evt.getNewValue()); } else if (StatusLabel.CONTAINER_FROM_FOLDER_PROPERTY.equals(name)) { containerFromFolder = (DataObject) evt.getNewValue(); if (containerFromFolder instanceof DatasetData) { containerLabel.setText(TEXT_IMPORTED); browseButton.setText(((DatasetData) containerFromFolder).getName()); containerObject = containerFromFolder; } else if (containerFromFolder instanceof ScreenData) { containerLabel.setText(TEXT_IMPORTED); browseButton.setText(((ScreenData) containerFromFolder).getName()); containerObject = containerFromFolder; } } else if (StatusLabel.NO_CONTAINER_PROPERTY.equals(name)) { containerLabel.setText(""); noContainer = true; } else if (StatusLabel.DEBUG_TEXT_PROPERTY.equals(name)) { firePropertyChange(name, evt.getOldValue(), evt.getNewValue()); } }
/** * Indicates that the file will not be imported. * * @param fire Pass <code>true</code> to fire a property, <code>false</code> otherwise. */ private void cancel(boolean fire) { if (busyLabel.isBusy() && !statusLabel.isCancellable()) return; String s = CANCEL_TEXT; if (file.isDirectory()) { busyLabel.setBusy(true); busyLabel.setVisible(true); s += " waiting on scanning to finish"; } else { busyLabel.setBusy(false); busyLabel.setVisible(false); } statusLabel.setText(s); statusLabel.markedAsCancel(); cancelButton.setEnabled(false); cancelButton.setVisible(false); if (image == null && file.isFile()) firePropertyChange(IMPORT_STATUS_CHANGE_PROPERTY, null, PARTIAL); if (fire) firePropertyChange(CANCEL_IMPORT_PROPERTY, null, this); }