Beispiel #1
0
  /**
   * Sets the current {@link #resourceComponent}. This triggers any updates to the UI
   * asynchronously.
   *
   * <p><b>Note:</b> This method should only be called when the active {@link #editor} changes,
   * i.e., via {@link #setActiveEditor(ICEFormEditor)}.
   *
   * @param component The new ResourceComponent, or null to unset it. This is assumed to be a new
   *     value.
   */
  private void setResourceComponent(ResourceComponent component) {

    // If necessary, clear the contents of the view and unregister from the
    // previous ResourceComponent.
    if (resourceComponent != null) {
      // Unregister from the old ResourceComponent.
      resourceComponent.unregister(this);

      // Clear the related UI pieces.
      if (resourceTreeViewer != null && !resourceTreeViewer.getControl().isDisposed()) {
        textList.clear();
        imageList.clear();
        resourceTreeViewer.refresh();
        resourceTreeViewer.getTree().redraw();
      }

      // Unset the reference to the old ResourceComponent.
      resourceComponent = null;
    }

    // If the new ResourceComponent is valid, update the contents of the
    // view and register for updates from it.
    if (component != null) {
      // Set the component reference
      resourceComponent = component;
      // Register this view with the Component to receive updates
      resourceComponent.register(this);
      // Trigger a UI update.
      update(resourceComponent);
    }

    return;
  }
Beispiel #2
0
  /** This operation populates the ArrayLists for text- and image-based resources. */
  private void sortTreeContent() {

    // Ensure a non-null resourceComponent
    if (resourceComponent != null) {
      // Remove the current list contents
      textList.clear();
      imageList.clear();

      // Re-populate the resource lists
      for (ICEResource i : resourceComponent.getResources()) {
        if (!i.isPictureType()) {
          textList.add(new ResourcePropertySource(i));
        } else if (i.isPictureType()) {
          imageList.add(new ResourcePropertySource(i));
        } else {
          logger.info("ERROR: Unknown resource type.");
        }
      }
    }

    return;
  }
Beispiel #3
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ice.item.Item#update(org.eclipse.ice.item.messaging.Message)
   */
  @Override
  public boolean update(Message message) {

    // Get the message type and string text
    String type = message.getType();
    String text = message.getMessage();

    // Parse the message type
    if ("MESSAGE_POSTED".equals(type)) {

      // If its a message posted, we expect it to
      // be of the format pp_name:time:value
      String[] data = text.split(":");
      String name = data[0];
      Double time = Double.valueOf(data[1]);
      Double value = Double.valueOf(data[2]);

      // We need the jobLaunch directory to create new VizResources
      String directory = mooseLauncher.getJobLaunchDirectory();

      // Get a reference to the VizResource file we are going
      // to create and populate
      File dataFile = new File(directory + System.getProperty("file.separator") + name + ".csv");

      // Get a reference to the ResourceComponent
      ResourceComponent comp = (ResourceComponent) form.getComponent(3);

      try {

        if (!dataFile.exists()) {
          // If the file hasn't been created yet, we need to create
          // it and start filling it with post processor data
          dataFile.createNewFile();

          // Write the new incoming data
          PrintWriter printWriter = new PrintWriter(new FileOutputStream(dataFile, true));
          printWriter.write("Time, " + name + "\n");
          printWriter.write(time + ", " + value + "\n");
          printWriter.close();

          // Create the VizResource, and add it to the
          // ResourceComponent
          ICEResource resource = getResource(dataFile.getAbsolutePath());
          comp.add(resource);

          // Remember the name of the resource for next time
          postProcessorResources.put(name, resource);

        } else {

          // Write the data to the existing resource
          PrintWriter printWriter = new PrintWriter(new FileOutputStream(dataFile, true));
          printWriter.write(time + ", " + value + "\n");

          // Update the ICEResource
          ICEResource r = postProcessorResources.get(name);

          // Here we are faking a VizResource notification
          // by setting the name with its current name
          r.setName(r.getName());

          // Close the writer
          printWriter.close();
        }

      } catch (IOException e) {
        logger.error(getClass().getName() + " Exception!", e);
      }
    }

    return true;
  }
Beispiel #4
0
  /*
   * (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;
            }
          }
        }
      }
    }
  }