Beispiel #1
0
 /**
  * Remove me
  *
  * @return was removed
  */
 public boolean removeDisplayComponent() {
   if (GuiUtils.askYesNo("Remove Display", "Are you sure you want to remove: " + toString())) {
     DisplayGroup displayGroup = getDisplayGroup();
     if (displayGroup != null) {
       displayGroup.removeDisplayComponent(this);
     }
     getDisplayControl().removeDisplayComponent(this);
     return true;
   } else {
     return false;
   }
 }
 private void doDeleteRequest(Node node) {
   if (node == null) {
     return;
   }
   Element ele = (Element) node;
   String tagName = ele.getTagName();
   if (tagName.equals("folder")) {
     if (!GuiUtils.askYesNo(
         "Verify Delete Folder",
         "Do you want to delete the folder "
             + "\""
             + ele.getAttribute("name")
             + "\"?"
             + "\nNOTE: All parameter sets it contains will be deleted.")) return;
     XmlUtil.removeChildren(ele);
   } else if (tagName.equals("default")) {
     if (!GuiUtils.askYesNo(
         "Verify Delete", "Do you want to delete " + "\"" + ele.getAttribute(ATTR_NAME) + "\"?"))
       return;
   } else {
     return;
   }
   removeNode(ele);
 }
 private void doRename(Element node) {
   if (imageDefaults == null) {
     imageDefaults = getImageDefaults();
   }
   if (!node.hasAttribute(ATTR_NAME)) return;
   JLabel label = new JLabel("New name: ");
   JTextField nameFld = new JTextField("", 20);
   JComponent contents =
       GuiUtils.doLayout(
           new Component[] {
             GuiUtils.rLabel("New name: "), nameFld,
           },
           2,
           GuiUtils.WT_N,
           GuiUtils.WT_N);
   contents = GuiUtils.center(contents);
   contents = GuiUtils.inset(contents, 10);
   if (!GuiUtils.showOkCancelDialog(
       null, "Rename \"" + node.getAttribute("name") + "\"", contents, null)) return;
   String newName = nameFld.getText().trim();
   String tagName = node.getTagName();
   Element root = imageDefaultsRoot;
   if (tagName.equals("default")) {
     root = (Element) node.getParentNode();
   }
   Element exists = XmlUtil.findElement(root, tagName, ATTR_NAME, newName);
   if (!(exists == null)) {
     if (!GuiUtils.askYesNo(
         "Name Already Exists",
         "Do you want to replace " + node.getAttribute("name") + " with" + "\"" + newName + "\"?"))
       return;
   }
   node.removeAttribute(ATTR_NAME);
   node.setAttribute(ATTR_NAME, newName);
   makeXmlTree();
   try {
     imageDefaults.writeWritable();
   } catch (Exception e) {
     logger.error("write error!", e);
   }
   imageDefaults.setWritableDocument(imageDefaultsDocument, imageDefaultsRoot);
 }
  /**
   * Make the adapters for the given list of files
   *
   * @param files Data files
   * @throws Exception When bad things happen
   */
  private void makeAdapters(List files) throws Exception {
    adapters = new ArrayList<RadarAdapter>();
    Hashtable<String, RadarAdapter> oldAdapterMap = fileToAdapter;
    fileToAdapter = new Hashtable<String, RadarAdapter>();

    int cnt = 0;

    final List<String> badFiles = new ArrayList<String>();
    final List<Exception> badExceptions = new ArrayList<Exception>();

    final List<RadarAdapter> goodAdapters = new ArrayList<RadarAdapter>();
    final List<String> goodFiles = new ArrayList<String>();
    visad.util.ThreadManager threadManager =
        new visad.util.ThreadManager("radar data initialization");
    LogUtil.message("Initializing radar files");
    for (Iterator iter = files.iterator(); iter.hasNext(); ) {
      final String filename = iter.next().toString();
      RadarAdapter adapter = (RadarAdapter) oldAdapterMap.get(filename);
      cnt++;
      if (adapter == null) {
        threadManager.addRunnable(
            new visad.util.ThreadManager.MyRunnable() {
              public void run() throws Exception {
                try {
                  RadarAdapter myAdapter = makeRadarAdapter(filename);
                  synchronized (goodAdapters) {
                    goodAdapters.add(myAdapter);
                    goodFiles.add(filename);
                  }
                } catch (Exception e) {
                  synchronized (badExceptions) {
                    badExceptions.add(e);
                    badFiles.add(filename);
                  }
                }
              }
            });
      } else {
        goodAdapters.add(adapter);
        goodFiles.add(filename);
      }
    }

    //        threadManager.debug = true;
    threadManager.runInParallel(getDataContext().getIdv().getMaxDataThreadCount());
    LogUtil.message("");

    for (int i = 0; i < goodAdapters.size(); i++) {
      adapters.add(goodAdapters.get(i));
      fileToAdapter.put(goodFiles.get(i), goodAdapters.get(i));
    }

    if (!badFiles.isEmpty()) {
      StringBuffer buf = new StringBuffer();
      if (badFiles.size() < files.size()) {
        buf.append("<html>");
        buf.append("There were problems reading these files:");
        buf.append("<ul>");
        for (Iterator iterator = badFiles.iterator(); iterator.hasNext(); ) {
          buf.append("<li>");
          buf.append((String) iterator.next());
          buf.append("</li>");
        }
        buf.append("</ul>");
        buf.append("<p>Continue loading good data?<p></html>");
        boolean ok = ucar.unidata.util.GuiUtils.askYesNo("Error reading data", buf.toString());

        badExceptions.get(0).printStackTrace();
        if (ok) {
          files.removeAll(badFiles);
        } else {
          throw new VisADException("error reading files");
        }
      } else {
        throw badExceptions.get(0);
      }
    }
    // clean up any old adapters
    for (String source : oldAdapterMap.keySet()) {
      if (fileToAdapter.get(source) == null) {
        ((RadarAdapter) oldAdapterMap.get(source)).doRemove();
      }
    }
    oldAdapterMap = null;
  }