/**
  * Default constructor.
  *
  * @param cmrRepositoryDefinition {@link CmrRepositoryDefinition}
  */
 public SelectCmrAction(CmrRepositoryDefinition cmrRepositoryDefinition) {
   this.cmrRepositoryDefinition = cmrRepositoryDefinition;
   setText(cmrRepositoryDefinition.getName());
   setImageDescriptor(
       ImageDescriptor.createFromImage(
           ImageFormatter.getCmrRepositoryImage(cmrRepositoryDefinition, true)));
 }
 /** Selects the displayed repository definition. */
 private void selectDisplayedCmrRepositoryDefinition() {
   List<CmrRepositoryDefinition> repositories = cmrRepositoryManager.getCmrRepositoryDefinitions();
   if (CollectionUtils.isNotEmpty(repositories)) {
     // find first online
     for (CmrRepositoryDefinition repositoryDefinition : repositories) {
       if (repositoryDefinition.getOnlineStatus() == OnlineStatus.ONLINE) {
         displayedCmrRepositoryDefinition = repositoryDefinition;
         performUpdate(true);
         selectionProviderAdapter.setSelection(
             new StructuredSelection(displayedCmrRepositoryDefinition));
         return;
       }
     }
     // if no online display first
     displayedCmrRepositoryDefinition = repositories.get(0);
     performUpdate(true);
     selectionProviderAdapter.setSelection(
         new StructuredSelection(displayedCmrRepositoryDefinition));
   }
 }
 /**
  * Caches result set on the CMR for the given storage under given hash.
  *
  * @param cmrRepositoryDefinition {@link CmrRepositoryDefinition} to cache results on.
  * @param storageData {@link StorageData}
  * @param results Results to cache
  * @param hash Hash to use
  */
 private void cacheQueryResultOnCmr(
     CmrRepositoryDefinition cmrRepositoryDefinition,
     StorageData storageData,
     List<E> results,
     int hash) {
   try {
     cmrRepositoryDefinition.getStorageService().cacheStorageData(storageData, results, hash);
   } catch (BusinessException e) { // NOPMD NOCHK
     // ignore also if caching fails
   }
 }
  /** {@inheritDoc} */
  @Override
  public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    CmrRepositoryDefinition cmrRepositoryDefinition = null;
    if (receiver instanceof ICmrRepositoryProvider) {
      cmrRepositoryDefinition = ((ICmrRepositoryProvider) receiver).getCmrRepositoryDefinition();
    } else if (receiver instanceof ICmrRepositoryAndAgentProvider) {
      cmrRepositoryDefinition =
          ((ICmrRepositoryAndAgentProvider) receiver).getCmrRepositoryDefinition();
    } else if (receiver instanceof IStorageDataProvider) {
      cmrRepositoryDefinition = ((IStorageDataProvider) receiver).getCmrRepositoryDefinition();
    } else if (receiver instanceof IInputDefinitionProvider) {
      RepositoryDefinition repository =
          ((IInputDefinitionProvider) receiver).getInputDefinition().getRepositoryDefinition();
      if (repository instanceof CmrRepositoryDefinition) {
        cmrRepositoryDefinition = (CmrRepositoryDefinition) repository;
      } else {
        return false;
      }
    } else if ("anyOnline".equals(property)) {
      for (CmrRepositoryDefinition cmr :
          InspectIT.getDefault().getCmrRepositoryManager().getCmrRepositoryDefinitions()) {
        if (cmr.getOnlineStatus().equals(OnlineStatus.ONLINE)) {
          return true;
        }
      }
      return false;
    } else {
      return false;
    }

    if ("onlineStatus".equals(property)) {
      if ("ONLINE".equals(expectedValue)) {
        return cmrRepositoryDefinition.getOnlineStatus() == OnlineStatus.ONLINE;
      } else if ("OFFLINE".equals(expectedValue)) {
        return cmrRepositoryDefinition.getOnlineStatus() == OnlineStatus.OFFLINE;
      } else if ("CHECKING".equals(expectedValue)) {
        return cmrRepositoryDefinition.getOnlineStatus() == OnlineStatus.CHECKING;
      }
    } else if ("recordingActive".equals(property)) {
      if (expectedValue instanceof Boolean) {
        if (cmrRepositoryDefinition.getOnlineStatus() != OnlineStatus.OFFLINE) {
          boolean recordingActive =
              cmrRepositoryDefinition.getStorageService().getRecordingState() != RecordingState.OFF;
          return ((Boolean) expectedValue).booleanValue() == recordingActive;
        } else {
          return false;
        }
      }
    }
    return false;
  }
 /** {@inheritDoc} */
 @Override
 public void repositoryAdded(CmrRepositoryDefinition cmrRepositoryDefinition) {
   cachedOnlineStatus.put(cmrRepositoryDefinition, cmrRepositoryDefinition.getOnlineStatus());
   SafeExecutor.asyncExec(
       new Runnable() {
         @Override
         public void run() {
           updateFormMenuManager();
         }
       },
       mainForm);
 }
 /** {@inheritDoc} */
 @Override
 public void refresh() {
   // check the status of CMR, if it's online do update, if it's offline just fire update CMR
   // online status job
   if (null != displayedCmrRepositoryDefinition
       && OnlineStatus.OFFLINE != displayedCmrRepositoryDefinition.getOnlineStatus()) {
     performUpdate(true);
   } else if (null != displayedCmrRepositoryDefinition) {
     InspectIT.getDefault()
         .getCmrRepositoryManager()
         .forceCmrRepositoryOnlineStatusUpdate(displayedCmrRepositoryDefinition);
   }
 }
 /** Updates the form title. Sub-classes can extend if needed. */
 protected void updateFormTitle() {
   if (null != displayedCmrRepositoryDefinition) {
     mainForm.setImage(
         ImageFormatter.getCmrRepositoryImage(displayedCmrRepositoryDefinition, true));
     mainForm.setText(displayedCmrRepositoryDefinition.getName());
     mainForm.setToolTipText(
         TextFormatter.getCmrRepositoryDescription(displayedCmrRepositoryDefinition));
     mainForm.setMessage(null);
   } else {
     mainForm.setImage(null);
     mainForm.setText("No repository exists");
     mainForm.setMessage(
         "Repositories can be added from the Repository Manager", IMessageProvider.WARNING);
     mainForm.setToolTipText(null);
   }
 }
 /** Updates the tree input and refreshes the tree. */
 protected void updateFormBody() {
   clearFormBody();
   if (null == displayedCmrRepositoryDefinition) {
     displayMessage(
         "No CMR repository present. Please add the CMR repository via 'Add CMR repository' action.",
         Display.getDefault().getSystemImage(SWT.ICON_INFORMATION));
   } else if (displayedCmrRepositoryDefinition.getOnlineStatus() == OnlineStatus.OFFLINE) {
     displayMessage(
         "Selected CMR repository is currently unavailable.",
         Display.getDefault().getSystemImage(SWT.ICON_WARNING));
   } else if (isShowEnvironments()) {
     List<?> inputList = environmentLeafs;
     if (CollectionUtils.isEmpty(inputList)) {
       displayMessage(
           "No environment exists on selected CMR repository.",
           Display.getDefault().getSystemImage(SWT.ICON_INFORMATION));
     } else {
       createTableColumns();
       tableViewer.getTable().setHeaderVisible(true);
       tableViewer.getTable().setLinesVisible(true);
       tableViewer.getTable().setVisible(true);
       tableViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
       tableViewer.setInput(inputList);
     }
   } else if (isShowProfiles()) {
     List<?> inputList = profileLeafs;
     if (CollectionUtils.isEmpty(inputList)) {
       displayMessage(
           "No profile exists on selected CMR repository.",
           Display.getDefault().getSystemImage(SWT.ICON_INFORMATION));
     } else {
       createTableColumns();
       tableViewer.getTable().setHeaderVisible(true);
       tableViewer.getTable().setLinesVisible(true);
       tableViewer.getTable().setVisible(true);
       tableViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
       tableViewer.setInput(inputList);
     }
   }
   mainForm.getBody().layout();
 }