/** * Returns <code>true</code> if the file has already been marked for re-import, <code>false</code> * otherwise. * * @return See above. */ public List<FileImportComponent> getReImport() { List<FileImportComponent> l = null; if (file.isFile()) { /* if (errorButton != null && errorButton.isVisible()) { if (image instanceof Exception) { l = new ArrayList<FileImportComponent>(); if (!reimported) l.add(this); return l; } } */ if (toReImport && !reimported) { l = new ArrayList<FileImportComponent>(); l.add(this); return l; } } else { if (components != null) { Entry entry; Iterator<FileImportComponent> i = components.values().iterator(); FileImportComponent fc; l = new ArrayList<FileImportComponent>(); List<FileImportComponent> list; while (i.hasNext()) { fc = i.next(); list = fc.getReImport(); if (list != null && list.size() > 0) l.addAll(list); } } } return l; }
/** * Returns the files that failed to import. * * @return See above. */ public List<FileImportComponent> getImportErrors() { List<FileImportComponent> l = null; if (file.isFile()) { if (errorBox != null && errorBox.isVisible()) { if (errorBox.isSelected() && errorBox.isEnabled() && image instanceof Exception) { l = new ArrayList<FileImportComponent>(); l.add(this); return l; } } } else { if (components != null) { Entry entry; Iterator<FileImportComponent> i = components.values().iterator(); FileImportComponent fc; l = new ArrayList<FileImportComponent>(); List<FileImportComponent> list; while (i.hasNext()) { fc = i.next(); list = fc.getImportErrors(); if (list != null && list.size() > 0) l.addAll(list); } } } return l; }
/** * 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(); }
/** * Attaches the listeners to the newly created component. * * @param c The component to handle. */ private void attachListeners(FileImportComponent c) { PropertyChangeListener[] listeners = getPropertyChangeListeners(); if (listeners != null && listeners.length > 0) { for (int j = 0; j < listeners.length; j++) { c.addPropertyChangeListener(listeners[j]); } } }
/** * Implemented as specified by the {@link Importer} interface. * * @see Importer#retryImport() */ public void retryImport() { if (model.getState() == DISCARDED) return; ImporterUIElement element = view.getSelectedPane(); if (element == null) return; List<FileImportComponent> l = element.getFilesToReimport(); if (l == null || l.size() == 0) return; Iterator<FileImportComponent> i = l.iterator(); FileImportComponent fc; ImportableObject object = element.getData(); List<File> files = new ArrayList<File>(); while (i.hasNext()) { fc = i.next(); fc.setReimported(true); files.add(fc.getFile()); } object.reImport(files); importData(object); }
/** * Sets the result of the import. * * @param status Flag indicating the status of the import. * @param image The image. */ public void setStatus(boolean status, Object image) { this.image = image; busyLabel.setBusy(false); busyLabel.setVisible(false); cancelButton.setVisible(false); importCount++; if (parent != null) parent.increaseNumberOfImport(); if (image instanceof ImageData) { ImageData img = (ImageData) image; Exception error = null; try { img.getDefaultPixels(); } catch (Exception e) { error = e; toReImport = true; } if (error != null) { exception = error; fileNameLabel.setForeground(ERROR_COLOR); resultLabel.setVisible(false); errorButton.setToolTipText(UIUtilities.formatExceptionForToolTip(error)); errorButton.setVisible(true); errorBox.setVisible(true); errorBox.addChangeListener(this); deleteButton.setVisible(true); deleteButton.addActionListener(this); } else { imageLabel.setData(img); resultLabel.setText(VIEW_TEXT); resultLabel.setForeground(UIUtilities.HYPERLINK_COLOR); if (browsable) resultLabel.setToolTipText(ThumbnailLabel.IMAGE_LABEL_TOOLTIP); else imageLabel.setToolTipText(""); resultLabel.setVisible(true); fileNameLabel.addMouseListener(adapter); resultLabel.addMouseListener(adapter); addMouseListener(adapter); showContainerLabel = (dataset != null || containerFromFolder != null); if (noContainer) { browseButton.setVisible(false); containerLabel.setVisible(false); } else { browseButton.setVisible(showContainerLabel); containerLabel.setVisible(showContainerLabel); } groupLabel.setVisible(!singleGroup); } } else if (image instanceof ThumbnailData) { ThumbnailData thumbnail = (ThumbnailData) image; groupLabel.setVisible(!singleGroup); if (thumbnail.isValidImage()) { imageLabel.setData(thumbnail); statusLabel.setVisible(false); fileNameLabel.addMouseListener(adapter); addMouseListener(adapter); resultLabel.setText(VIEW_TEXT); resultLabel.setForeground(UIUtilities.HYPERLINK_COLOR); if (browsable) resultLabel.setToolTipText(ThumbnailLabel.IMAGE_LABEL_TOOLTIP); else imageLabel.setToolTipText(""); resultLabel.setVisible(false); if (thumbnail.requirePyramid() != null && thumbnail.requirePyramid().booleanValue()) { imageLabel.setToolTipText(PYRAMID_TEXT); resultLabel.setVisible(true); resultLabel.addMouseListener(adapter); } showContainerLabel = (dataset != null || containerFromFolder != null); if (noContainer) { browseButton.setVisible(false); containerLabel.setVisible(false); } else { browseButton.setVisible(showContainerLabel); containerLabel.setVisible(showContainerLabel); } } else { statusLabel.setVisible(false); fileNameLabel.setForeground(ERROR_COLOR); resultLabel.setText(IMAGE_CREATION_ERROR_TEXT); resultLabel.setToolTipText(UIUtilities.formatExceptionForToolTip(thumbnail.getError())); resultLabel.setVisible(true); errorButton.setVisible(false); errorBox.setVisible(false); groupLabel.setVisible(!singleGroup); } } else if (image instanceof PlateData) { imageLabel.setData((PlateData) image); statusLabel.setVisible(false); groupLabel.setVisible(!singleGroup); if (browsable) { resultLabel.setText(BROWSE_TEXT); resultLabel.setForeground(UIUtilities.HYPERLINK_COLOR); resultLabel.setToolTipText(ThumbnailLabel.PLATE_LABEL_TOOLTIP); resultLabel.setVisible(true); } fileNameLabel.addMouseListener(adapter); resultLabel.addMouseListener(adapter); showContainerLabel = containerObject instanceof ScreenData; if (noContainer || !browsable) { browseButton.setVisible(false); containerLabel.setVisible(false); } else { browseButton.setVisible(showContainerLabel); containerLabel.setVisible(showContainerLabel); } } else if (image instanceof List) { statusLabel.setVisible(false); groupLabel.setVisible(!singleGroup); List list = (List) image; int m = list.size(); imageLabel.setData(list.get(0)); list.remove(0); ThumbnailLabel label = imageLabels.get(0); label.setVisible(true); label.setData(list.get(0)); list.remove(0); if (list.size() > 0) { label = imageLabels.get(1); label.setVisible(true); label.setData(list.get(0)); list.remove(0); int n = statusLabel.getSeriesCount() - m; if (n > 0) { label = imageLabels.get(2); Font f = label.getFont(); label.setFont(f.deriveFont(f.getStyle(), f.getSize() - 2)); label.setVisible(true); String value = "... " + n + " more"; label.setText(value); } } resultLabel.setVisible(true); showContainerLabel = true; if (noContainer) { browseButton.setVisible(false); containerLabel.setVisible(false); } else { browseButton.setVisible(showContainerLabel); containerLabel.setVisible(showContainerLabel); } // control = resultLabel; } else if (image instanceof Boolean) { if (!statusLabel.isMarkedAsCancel()) { cancelButton.setVisible(false); if (statusLabel.isMarkedAsDuplicate()) { statusLabel.setVisible(false); setStatusText(StatusLabel.DUPLICATE); } else { statusLabel.setVisible(false); setStatusText(FILE_NOT_VALID_TEXT); } } else resultLabel.setText(""); } else { if (!status) { statusLabel.setVisible(false); resultLabel.setToolTipText(""); resultLabel.setEnabled(false); if (image == null) setStatusText(null); else if (image instanceof String) { setStatusText((String) image); } else if (image instanceof ImportException) { ImportException ie = (ImportException) image; fileNameLabel.setForeground(ERROR_COLOR); resultLabel.setVisible(false); toReImport = true; errorButton.setToolTipText(UIUtilities.formatExceptionForToolTip(ie)); exception = ie; errorButton.setVisible(false); int s = ie.getStatus(); if (s == ImportException.COMPRESSION) { resultLabel.setVisible(true); resultLabel.setText(COMPRESSION_ERROR_TEXT); resultLabel.setToolTipText(UIUtilities.formatExceptionForToolTip(ie)); } else if (s == ImportException.MISSING_LIBRARY) { resultLabel.setVisible(true); resultLabel.setText(MISSING_LIB_ERROR_TEXT); resultLabel.setToolTipText(UIUtilities.formatExceptionForToolTip(ie)); } else if (s == ImportException.FILE_ON_TAPE) { resultLabel.setVisible(true); resultLabel.setText(FILE_ON_TAPE_ERROR_TEXT); resultLabel.setToolTipText(UIUtilities.formatExceptionForToolTip(ie)); } else if (s == ImportException.NO_SPACE) { resultLabel.setVisible(true); resultLabel.setText(NO_SPACE_ERROR_TEXT); resultLabel.setToolTipText(UIUtilities.formatExceptionForToolTip(ie)); } else { errorButton.setVisible(true); errorBox.setVisible(true); errorBox.addChangeListener(this); } cancelButton.setVisible(false); } } } repaint(); }