public boolean checkInfrastructureReq() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
    IWorkbenchPage page = workbenchWindow.getActivePage();

    IEditorPart editor = page.getActiveEditor();

    IFile modelFile = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (modelFile != null) {
      System.out.println("checkInfrastructureReq()" + modelFile.getLocation().toString());
    }
    ResourceSet resourceSet = new ResourceSetImpl();
    URI uri = URI.createFileURI(modelFile.getLocation().toString());
    System.out.println("uri" + uri.toString());
    org.eclipse.emf.ecore.resource.Resource resource = resourceSet.getResource(uri, true);
    RequestedFederationScenario sourceFedScenario =
        (RequestedFederationScenario) resource.getContents().get(0);

    return (sourceFedScenario.getInfrastructureRequest() != null)
        && (sourceFedScenario.getInfrastructureRequest().getReqOfferedResources().size() > 0);
  }
示例#2
0
  /**
   * It will create a new scenario based on the given one, if the given one is not already saved.
   * The returned scenario will have some (or all if possible) assignments on resource settings
   * resolved. The method calls internally {@link #resolveAssignments(RequestedFederationScenario)}
   *
   * @param The requested scenario
   * @return a new scenario based on the requested, with resolved dependencies (if possible at first
   *     pass)
   */
  public RequestedFederationScenario prepareScenarioRequest(RequestedFederationScenario scenario) {

    RequestedFederationScenario newScenario;
    if (scenario.getRuntimeInfo() == null) {
      newScenario = FederationscenariosFactory.eINSTANCE.createRequestedFederationScenario();
      newScenario = (RequestedFederationScenario) EcoreUtil.copy(scenario);
      RuntimeElement rtinfo = ExperimentRuntimeFactory.eINSTANCE.createRuntimeElement();
      rtinfo.setDescription(
          "Scenario is based on request by:" + scenario.eResource().getURI().path());
      newScenario.setRuntimeInfo(rtinfo);
      for (ResourceRequest resReq :
          newScenario.getInfrastructureRequest().getReqOfferedResources()) {
        RuntimeElement rtInfo = ExperimentRuntimeFactory.eINSTANCE.createRuntimeElement();
        resReq.setRuntimeInfo(rtInfo);
        rtInfo.setStatus(RuntimeElementStatus.NOT_EXISTS);
      }

    } else {
      newScenario = scenario;
    }

    resolveAssignments(newScenario);
    return newScenario;
  }
示例#3
0
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection =
        HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
    if (selection != null & selection instanceof IStructuredSelection) {
      IStructuredSelection strucSelection = (IStructuredSelection) selection;

      for (Object obj : strucSelection.toArray()) {
        System.out.println("Object =" + obj.toString());
        if (obj instanceof ui_TaxonomyTreeItem) {
          if ((((ui_TaxonomyTreeItem) obj).getOfficeElement()
              instanceof RequestedFederationScenario)) {
            // http://nam.ece.upatras.gr/fstoolkit/utils/resourcesmap.php?x[0]=38.288291,21.788884
            String req = "";
            RequestedFederationScenario scenario =
                (RequestedFederationScenario) ((ui_TaxonomyTreeItem) obj).getOfficeElement();

            ArrayList<myMarker> sitelist = new ArrayList<myMarker>();
            for (ResourceRequest resReq :
                scenario.getInfrastructureRequest().getReqOfferedResources()) {
              if (resReq.getRefOfferedResource() != null) {
                System.out.println(
                    "resReq.getRefOfferedResource() = " + resReq.getRefOfferedResource().getName());

                Site site = (Site) resReq.getRefOfferedResource().eContainer();

                if ((site != null) && (!sitelist.contains(site))) {
                  myMarker mymarker = null;
                  for (myMarker m : sitelist) {
                    if (m.site.equals(site)) mymarker = m;
                  }
                  if (mymarker == null) {
                    mymarker = new myMarker();
                    mymarker.site = site;
                    mymarker.descriptions = "";
                    sitelist.add(mymarker);
                  }
                  mymarker.descriptions +=
                      resReq.getName()
                          + " : <i>"
                          + resReq.getRefOfferedResource().getName()
                          + "</i></br>";
                }
              }
            }
            int i = 0;
            for (myMarker mymarker : sitelist) {
              if (mymarker.site.getLocatedAt() != null) {
                ResourcesProvider r = (ResourcesProvider) mymarker.site.eContainer();
                req = req + "x[" + i + "]=" + mymarker.site.getLocatedAt().getGeocoords() + "&";
                req =
                    req
                        + "c["
                        + i
                        + "]=<b>"
                        + r.getName()
                        + "</b><br>"
                        + "<small>"
                        + mymarker.descriptions
                        + "</small>"
                        + "&";
              }
              i++;
            }

            req = req.substring(0, req.length() - 1);
            req = "http://nam.ece.upatras.gr/fstoolkit/utils/resourcesmap.php?" + req;
            System.out.println("req = " + req);

            IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
            IWebBrowser browser;
            try {

              browser =
                  support.createBrowser(
                      IWorkbenchBrowserSupport.AS_VIEW,
                      ((ui_TaxonomyTreeItem) obj).getOfficeElement().getName()
                          + ".webbrowser.fstoolkit",
                      "Map for " + ((ui_TaxonomyTreeItem) obj).getOfficeElement().getName(),
                      "A world map for "
                          + ((ui_TaxonomyTreeItem) obj).getOfficeElement().getName());

              browser.openURL(new URL(req));

            } catch (PartInitException e) {
              e.printStackTrace();
            } catch (MalformedURLException e) {
              e.printStackTrace();
            }
          }
        }
      }
    }
    return null;
  }