@Override public void addFiles(File... files) { final int startIndex = productLocationList.size(); for (File file : files) { productLocationList.add(new ProductLocation(ProductLocationType.FILE, file.getAbsolutePath())); } final int stopIndex = productLocationList.size() - 1; fireIntervalAdded(this, startIndex, stopIndex); }
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { final JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof ProductLocation) { final ProductLocation location = (ProductLocation) value; String path = location.getPath(); if (location.getProductLocationType() != ProductLocationType.FILE) { if (!path.endsWith(File.separator)) { path += File.separator; } } if (location.getProductLocationType() == ProductLocationType.DIRECTORY) { path += "*"; } if (location.getProductLocationType() == ProductLocationType.DIRECTORY_REC) { path += "**"; } label.setText(path); } return label; } });
private static boolean noSourceProductsAvailable(List<ProductLocation> productLocations) { final Map<String, Product> productList = new HashMap<String, Product>(); for (ProductLocation productLocation : productLocations) { productList.putAll(productLocation.getProducts(ProgressMonitor.NULL)); } return productList.isEmpty(); }
private Variable[] getVariables(ProductLocationsPaneModel locationsModel, ProgressMonitor pm) { try { pm.beginTask("Scanning product locations...", locationsModel.getSize()); for (int i = 0; i < locationsModel.getSize(); i++) { final ProductLocation location = locationsModel.getElementAt(i); location.loadProducts(new SubProgressMonitor(pm, 1)); final Collection<Product> products = location.getProducts(ProgressMonitor.NULL).values(); if (!products.isEmpty()) { final Product product = products.iterator().next(); final String[] bandNames = product.getBandNames(); final Variable[] variables = new Variable[bandNames.length]; for (int j = 0; j < bandNames.length; j++) { variables[j] = new Variable(bandNames[j]); } location.closeProducts(); // @todo se - ?? return variables ?? - really a shortcut after the first product? // in this case only the variables of the first product are returned. return variables; } else { location.closeProducts(); } } } finally { pm.done(); } return new Variable[0]; }
final ProductLocationType type = productLocation.getProductLocationType(); final String path = productLocation.getPath(); logger.log(Level.INFO, "Try to load product location type: '" + type + "' at path: '" + path + "'"); addProductLocationMetadata(productLocation); List<String> variables = getEoVariables(); final Map<String, Product> products = productLocation.getProducts(ProgressMonitor.NULL); for (Map.Entry<String, Product> productEntry : products.entrySet()) { final Product product = productEntry.getValue();
@Override public void removeProductLocation(ProductLocation productLocation) { // remove metadata final MetadataElement timeSeriesRootElement = tsProduct.getMetadataRoot().getElement(TIME_SERIES_ROOT_NAME); MetadataElement productLocationsElement = timeSeriesRootElement.getElement(PRODUCT_LOCATIONS); removeAttributeWithValue(PL_PATH, productLocation.getPath(), productLocationsElement); // remove variables for this productLocation updateAutoGrouping(); // TODO ??? final Band[] bands = tsProduct.getBands(); final MetadataElement sourceProductPaths = timeSeriesRootElement.getElement(SOURCE_PRODUCT_PATHS); for (Map.Entry<String, Product> productEntry : productLocation.getProducts(ProgressMonitor.NULL).entrySet()) { final Product product = productEntry.getValue(); removeAttributeWithValue(PL_PATH, productEntry.getKey(), sourceProductPaths); String timeString = formatTimeString(product); productTimeMap.remove(timeString); for (Band band : bands) { if (band.getName().endsWith(timeString)) { tsProduct.removeBand(band); } } } productLocation.closeProducts(); productLocationList.remove(productLocation); fireChangeEvent(new TimeSeriesChangeEvent(TimeSeriesChangeEvent.PROPERTY_PRODUCT_LOCATIONS, productLocationList, this)); }
/** * Returns the live map of products of the product location. * @return the live map of this product location's products. * @param pm a progress monitor */ public Map<String, Product> getProducts(final ProgressMonitor pm) { if (products == null) { loadProducts(pm); } return products; }
public void remove(Product product) { AbstractTimeSeries timeSeries = map.remove(product); if (timeSeries != null) { List<ProductLocation> locationList = timeSeries.getProductLocations(); for (ProductLocation productLocation : locationList) { productLocation.closeProducts(); } timeSeries.dispose(); } }
private static Product getFirstReprojectedSourceProduct(List<ProductLocation> productLocations) { final ProductLocation firstLocation = productLocations.get(0); return firstLocation.getProducts(ProgressMonitor.NULL).values().iterator().next(); }
private void addProductLocationMetadata(ProductLocation productLocation) { MetadataElement productLocationsElement = tsProduct.getMetadataRoot(). getElement(TIME_SERIES_ROOT_NAME). getElement(PRODUCT_LOCATIONS); // @todo - nur produkt pfade, keine Verzeichnisse ProductData productPath = ProductData.createInstance(productLocation.getPath()); ProductData productType = ProductData.createInstance(productLocation.getProductLocationType().toString()); int length = productLocationsElement.getElements().length + TimeSeriesChangeEvent.BAND_TO_BE_REMOVED; MetadataElement elem = new MetadataElement( String.format("%s.%s", PRODUCT_LOCATIONS, Integer.toString(length))); elem.addAttribute(new MetadataAttribute(PL_PATH, productPath, true)); elem.addAttribute(new MetadataAttribute(PL_TYPE, productType, true)); productLocationsElement.addElement(elem); }
@Override public void addDirectory(File directory, boolean recursive) { final ProductLocationType locationType = recursive ? ProductLocationType.DIRECTORY_REC : ProductLocationType.DIRECTORY; productLocationList.add(new ProductLocation(locationType, directory.getPath())); final int index = productLocationList.size() - 1; fireIntervalAdded(this, index, index); }
@Override public List<Band> getBandsForProductLocation(ProductLocation location) { final List<Band> bands = new ArrayList<Band>(); Map<String, Product> products = location.getProducts(ProgressMonitor.NULL); for (Product product : products.values()) { String timeString = formatTimeString(product); // TODO relies on one timecoding per product... thats not good (mz, ts, 2010-07-12) for (Band band : tsProduct.getBands()) { if (band.getName().endsWith(timeString)) { bands.add(band); } } } return bands; }
@Override public void addDirectory(File directory, boolean recursive) { timeSeries.addProductLocation( new ProductLocation(recursive ? ProductLocationType.DIRECTORY_REC : ProductLocationType.DIRECTORY, directory.getAbsolutePath())); final int index = timeSeries.getProductLocations().size() - 1; fireIntervalAdded(this, index, index); }
private List<Product> getCompatibleProducts() { List<Product> result = new ArrayList<Product>(); for (ProductLocation productLocation : timeSeries.getProductLocations()) { for (Product product : productLocation.getProducts(ProgressMonitor.NULL).values()) { for (String variable : timeSeries.getEoVariables()) { if (timeSeries.isProductCompatible(product, variable)) { if (timeSeries.isEoVariableSelected(variable)) { result.add(product); } } } } } return result; }
@Override public void addFiles(File... files) { final int startIndex = timeSeries.getProductLocations().size(); for (File file : files) { timeSeries.addProductLocation(new ProductLocation(ProductLocationType.FILE, file.getAbsolutePath())); } final int stopIndex = timeSeries.getProductLocations().size() - 1; fireIntervalAdded(this, startIndex, stopIndex); }
private List<Product> getAllProducts(ProgressMonitor pm) { List<Product> result = new ArrayList<Product>(); pm.beginTask("Scanning product locations ...", productLocationList.size()); try { for (ProductLocation productLocation : productLocationList) { if (pm.isCanceled()) { break; } for (Product product : productLocation.getProducts(ProgressMonitor.NULL).values()) { result.add(product); } pm.worked(1); } } finally { pm.done(); } return result; }
private void initProductLocations() { MetadataElement tsElem = tsProduct.getMetadataRoot().getElement(TIME_SERIES_ROOT_NAME); MetadataElement productListElem = tsElem.getElement(PRODUCT_LOCATIONS); MetadataElement[] productElems = productListElem.getElements(); productLocationList = new ArrayList<ProductLocation>(productElems.length); final File fileLocation = tsProduct.getProduct().getFileLocation(); for (MetadataElement productElem : productElems) { String path = productElem.getAttributeString(PL_PATH); File productFile; if (fileLocation != null) { final URI resolvedUri = fileLocation.toURI().resolve(path); productFile = new File(resolvedUri); } else { productFile = new File(path); } String type = productElem.getAttributeString(PL_TYPE); productLocationList.add(new ProductLocation(ProductLocationType.valueOf(type), productFile.getAbsolutePath())); } }
@SuppressWarnings({"MethodWithMoreThanThreeNegations"}) private boolean allProductsOnSameGrid() { Product refProduct = null; final List<ProductLocation> productLocations = getAssistantModel().getProductLocationsModel().getProductLocations(); for (ProductLocation productLocation : productLocations) { for (Product product : productLocation.getProducts(ProgressMonitor.NULL).values()) { if (refProduct != null) { if (product != null && !refProduct.isCompatibleProduct(product, 0.1E-4f)) { return false; } } else { if (product != null) { refProduct = product; } } } } return true; }
@Override protected JComponent createCrsComponent() { collocateProductSelector = new SourceProductSelector(getAppContext(), "Product:"); List<Product> products = new ArrayList<Product>(); for (ProductLocation productLocation : assistantModel.getProductLocationsModel().getProductLocations()) { for (Product product : productLocation.getProducts(ProgressMonitor.NULL).values()) { products.add(product); } } collocateProductSelector.setProductFilter(new CollocateProductFilter(products)); collocateProductSelector.addSelectionChangeListener(new AbstractSelectionChangeListener() { @Override public void selectionChanged(SelectionChangeEvent event) { fireCrsChanged(); } }); final JPanel panel = new JPanel(new BorderLayout(2, 2)); panel.add(collocateProductSelector.getProductNameComboBox(), BorderLayout.CENTER); panel.add(collocateProductSelector.getProductFileChooserButton(), BorderLayout.EAST); panel.addPropertyChangeListener("enabled", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { collocateProductSelector.getProductNameComboBox().setEnabled(panel.isEnabled()); collocateProductSelector.getProductFileChooserButton().setEnabled(panel.isEnabled()); final boolean collocate = getRadioButton().isSelected(); getCrsUI().firePropertyChange("collocate", !collocate, collocate); } }); return panel; }
private void reprojectSourceProducts(ProgressMonitor pm) { final ProductLocationsPaneModel productLocationsModel = getAssistantModel().getProductLocationsModel(); final List<ProductLocation> productLocations = productLocationsModel.getProductLocations(); pm.beginTask("Reprojecting...", productLocations.size()); for (ProductLocation productLocation : productLocations) { final Map<String, Product> products = productLocation.getProducts(ProgressMonitor.NULL); final Product crsReferenceProduct = getCrsReferenceProduct(); for (Map.Entry<String, Product> productEntry : products.entrySet()) { final Product product = productEntry.getValue(); if (!product.isCompatibleProduct(crsReferenceProduct, 0.1E-4f)) { Product reprojectedProduct = createProjectedProduct(product, crsReferenceProduct); productEntry.setValue(reprojectedProduct); } } pm.worked(1); } pm.done(); }