예제 #1
0
파일: MOOSE.java 프로젝트: nickstanish/ice
  /**
   * This method searches the Model input tree and locates all file Entries and loads them on the
   * Model File DataComponent.
   */
  protected void loadFileEntries() {
    // Walk the tree and get all Entries that may represent a file
    BreadthFirstTreeCompositeIterator iter = new BreadthFirstTreeCompositeIterator(modelTree);
    while (iter.hasNext()) {
      TreeComposite child = iter.next();

      // Make sure we have a valid DataComponent
      if (child.getActiveDataNode() != null && child.isActive()) {
        DataComponent data = (DataComponent) child.getActiveDataNode();
        for (Entry e : data.retrieveAllEntries()) {

          // If the Entry's tag is "false" it is a commented out
          // parameter.
          if (!"false".equals(e.getTag())
              && e.getValue() != null
              && !e.getValue().isEmpty()
              && (e.getName() + " = " + e.getValue())
                  .matches(mooseLauncher.getFileDependenciesSearchString())) {

            Entry clonedEntry = (Entry) e.clone();

            // If this Entry does not have a very descriptive
            // name
            // we should reset its name to the block it belongs
            // to
            if ("file".equals(clonedEntry.getName().toLowerCase())
                || "data_file".equals(clonedEntry.getName().toLowerCase())) {
              clonedEntry.setName(child.getName());
            }

            if (!clonedEntry.getValueType().equals(AllowedValueType.File)) {
              mooseModel.convertToFileEntry(clonedEntry);
            }

            // Setup allowed values correctly
            String extension =
                FilenameUtils.getExtension(
                    project.getFile(clonedEntry.getValue()).getLocation().toOSString());

            // Create a new content provider with the new file
            // in the allowed values list
            IEntryContentProvider prov = new BasicEntryContentProvider();
            ArrayList<String> valueList = clonedEntry.getAllowedValues();

            for (String file : getProjectFileNames(extension)) {
              if (!valueList.contains(file)) {
                valueList.add(file);
              }
            }
            prov.setAllowedValueType(AllowedValueType.File);

            // Finish setting the allowed values and default
            // value
            prov.setAllowedValues(valueList);

            // Set the new provider
            clonedEntry.setContentProvider(prov);

            // Set the value
            clonedEntry.setValue(e.getValue());

            fileEntryTreeMapping.put(clonedEntry.getName(), child);

            clonedEntry.register(this);

            // Add it to the list of model files.
            modelFiles.addEntry(clonedEntry);
          }
        }
      }
    }

    return;
  }
예제 #2
0
파일: MOOSE.java 프로젝트: nickstanish/ice
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ice.item.Item#update(org.eclipse.ice.datastructures.ICEObject
   * .IUpdateable)
   */
  @Override
  public void update(IUpdateable updateable) {

    if (updateable instanceof ResourceComponent) {
      ResourceComponent comp = (ResourceComponent) updateable;
      ResourceComponent ourComp = (ResourceComponent) form.getComponent(3);

      ArrayList<String> names = new ArrayList<String>();

      // Get a list of all our Resource Names:
      for (ICEResource r : ourComp.getResources()) {
        names.add(r.getName());
      }

      for (ICEResource r : comp.getResources()) {
        if (!names.contains(r.getName())) {
          logger.info("Adding Resource to Moose: " + r.getName());
          ourComp.add(r);
        }
      }

    } else if (updateable instanceof TreeComposite) {
      // If this is a tree composite we should reset our variables
      Thread varThread =
          new Thread(
              new Runnable() {

                @Override
                public void run() {
                  new MOOSEFileHandler().setupVariables(modelTree);
                  new MOOSEFileHandler().setupAuxVariables(modelTree);
                }
              });
      varThread.start();

    } else if (updateable instanceof Entry) {

      Entry entry = (Entry) updateable;

      // If we get here, then we have a file Entry that
      // has been changed on the modelFiles component
      // and we need to sync up the tree with it.

      // Grab the DataComponent
      if (fileEntryTreeMapping.containsKey(entry.getName())) {
        DataComponent data =
            (DataComponent) fileEntryTreeMapping.get(entry.getName()).getDataNodes().get(0);

        // If not null, loop over the Entries til we find
        // the file Entry.
        if (data != null) {
          for (Entry e : data.retrieveAllEntries()) {

            // If the Entry's tag is "false" it is a commented
            // out
            // parameter.
            if (!"false".equals(e.getTag())
                && e.getValue() != null
                && !e.getValue().isEmpty()
                && (e.getName() + " = " + e.getValue())
                    .matches(mooseLauncher.getFileDependenciesSearchString())) {

              // Set the value of the tree's file entry.
              e.setValue(entry.getValue());
              break;
            }
          }
        }
      }
    }
  }