private boolean isSelectedConfigurationVersionOkForRuntime() {
   String configVersionStr = getConfigurationVersion().getVersionString();
   String majorMinorConfig = getMajorMinorFromVersion(configVersionStr);
   if (majorMinorConfig != null) {
     float configVersion = convertVersionStringToLong(configVersionStr);
     if (configVersion > -1) {
       if (getRuntimeVersion() != null) {
         String runtimeVersionStr = getRuntimeVersion().toString();
         String majorMinorRuntime = getMajorMinorFromVersion(runtimeVersionStr);
         if (majorMinorRuntime != null) {
           float runtimeVersion = convertVersionStringToLong(majorMinorRuntime);
           boolean isIntegration = false;
           if (_settingsGroup.getSelectedTargetRuntime() != null) {
             String label =
                 _settingsGroup.getSelectedTargetRuntime().getProperty("switchyard.label");
             isIntegration = label.contains("Integration"); // hack
           }
           if (runtimeVersion > -1 && !isIntegration) {
             if (configVersion <= runtimeVersion) {
               return true;
             }
           } else if (isIntegration) {
             if (runtimeVersion > -1) {
               return true;
             }
           }
         }
       }
     }
   }
   return false;
 }
 private void initComponentsTable() {
   _settingsGroup.setCheckedComponents(_switchYardProject.getComponents(), true);
   _settingsGroup
       .getComponentsTable()
       .addCheckStateListener(
           new ICheckStateListener() {
             @Override
             public void checkStateChanged(CheckStateChangedEvent event) {
               if (event.getElement() instanceof ISwitchYardComponentExtension) {
                 if (event.getChecked()) {
                   _switchYardProject.addComponent(
                       (ISwitchYardComponentExtension) event.getElement());
                 } else {
                   _switchYardProject.removeComponent(
                       (ISwitchYardComponentExtension) event.getElement());
                 }
               } else if (event.getElement() instanceof Category) {
                 if (event.getChecked()) {
                   _switchYardProject.addComponents(
                       SwitchYardComponentExtensionManager.instance()
                           .getComponentExtensions((Category) event.getElement()));
                 } else {
                   _switchYardProject.removeComponents(
                       SwitchYardComponentExtensionManager.instance()
                           .getComponentExtensions((Category) event.getElement()));
                 }
               }
             }
           });
 }
  private void initControls() {

    _switchYardProject =
        SwitchYardProjectManager.instance().getSwitchYardProject(getProject()).createWorkingCopy();
    if (_switchYardProject.needsLoading()) {
      BusyIndicator.showWhile(
          getShell().getDisplay(),
          new Runnable() {
            @Override
            public void run() {
              _switchYardProject.load(new NullProgressMonitor());
            }
          });
    }
    try {
      _ifp = ProjectFacetsManager.create(_switchYardProject.getProject());
      _ifpwc = SharedWorkingCopyManager.getWorkingCopy(_ifp);
      _configuredRuntimes = _ifpwc.getTargetedRuntimes();
    } catch (CoreException e) {
      Activator.getDefault().getLog().log(e.getStatus());
    }

    _settingsGroup.setProject(_ifpwc);

    initTargetRuntime();
    initRuntimeVersion();
    initComponentsTable();

    _useSwitchYardDependencyBOMCheckbox.setSelection(pomUsesSwitchYardBOM());

    String errmsg = null;
    if (!pomDefinesSwitchYardVersion()) {
      _settingsGroup.setRuntimeControlEnablement(false);
    } else if (pomUsesSwitchYardBOM()) {
      if (!isSelectedRuntimeVersion2OrHigher()) {
        // only valid versions with BOM dependency support are 2.0+
        errmsg = Messages.ProjectConfigurationWizardPage_errorMessage_bomRequiresVersion2;
      }
    } else if (!isSelectedConfigurationVersionOkForRuntime()) {
      String configVersion = getMajorMinorFromVersion(getRuntimeVersion().toString());
      errmsg =
          "The Configuration Version must be "
              + configVersion
              + " or lower to work with Library Version "
              + getRuntimeVersion().toString()
              + ".";
    }
    setErrorMessage(errmsg);
    getContainer().updateMessage();
  }
 private ArtifactVersion getRuntimeVersion() {
   ISelection runtimeVersionListSelection = _settingsGroup.getRuntimeVersionsList().getSelection();
   if (runtimeVersionListSelection.isEmpty()) {
     return null;
   }
   return (ArtifactVersion) ((IStructuredSelection) runtimeVersionListSelection).getFirstElement();
 }
  @Override
  protected Control createContents(Composite parent) {
    Composite content = new Composite(parent, SWT.NONE);
    content.setLayout(new GridLayout());
    content.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    _settingsGroup =
        new SwitchYardSettingsGroup(content, this, PlatformUI.getWorkbench().getProgressService());
    _settingsGroup.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent e) {
            String errmsg = null;
            if (pomUsesSwitchYardBOM()) {
              boolean isIntegration =
                  _switchYardProject.getIntegrationVersion() != null
                      && _switchYardProject.getKieVersion() != null;
              if (!isIntegration && !isSelectedRuntimeVersion2OrHigher()) {
                // only valid versions with BOM dependency support are 2.0+
                errmsg =
                    "SwitchYard projects using BOM dependencies must use Runtime Version 2.0 or higher.";
              }
            }
            if (!isSelectedConfigurationVersionOkForRuntime()) {
              String configVersion = getMajorMinorFromVersion(getRuntimeVersion().toString());
              errmsg =
                  "The Configuration Version must be "
                      + configVersion
                      + " or lower to work with Library Version "
                      + getRuntimeVersion().toString()
                      + ".";
            }
            setErrorMessage(errmsg);
            getContainer().updateMessage();
          }
        });

    Label label = new Label(content, SWT.RIGHT);
    _useSwitchYardDependencyBOMCheckbox = new Button(content, SWT.CHECK);
    _useSwitchYardDependencyBOMCheckbox.setText("Uses SwitchYard BOM for dependency management");
    GridData cb2GD = new GridData(GridData.FILL_HORIZONTAL);
    _useSwitchYardDependencyBOMCheckbox.setLayoutData(cb2GD);
    label.setEnabled(false);
    _useSwitchYardDependencyBOMCheckbox.setEnabled(false);

    initControls();

    return content;
  }
  private void initRuntimeVersion() {
    ArtifactVersion version = null;
    String versionString = _switchYardProject.getVersion();
    if (versionString != null && versionString.length() > 0) {
      version = new DefaultArtifactVersion(versionString);
    }
    if (version != null) {
      _settingsGroup.getRuntimeVersionsList().setSelection(new StructuredSelection(version), true);
    }
    _settingsGroup
        .getRuntimeVersionsList()
        .getControl()
        .setEnabled(!_switchYardProject.isUsingDependencyManagement());

    boolean integCheckSelected =
        pomDefinesIntegrationVersion() && pomDefinesKieVersion() && pomUsesSwitchYardBOM();
    _settingsGroup.getConfigureIntegrationCheckbox().setSelection(integCheckSelected);

    _settingsGroup
        .getRuntimeVersionsList()
        .addSelectionChangedListener(
            new ISelectionChangedListener() {
              @Override
              public void selectionChanged(SelectionChangedEvent event) {
                ISelection selection = event.getSelection();
                if (selection == null
                    || selection.isEmpty()
                    || !(selection instanceof IStructuredSelection)) {
                  return;
                }
                _switchYardProject.setRuntimeVersion(
                    ((IStructuredSelection) selection).getFirstElement().toString());
              }
            });

    _settingsGroup
        .getIntegrationVersionsList()
        .addSelectionChangedListener(
            new ISelectionChangedListener() {
              @Override
              public void selectionChanged(SelectionChangedEvent event) {
                ISelection selection = event.getSelection();
                if (selection == null
                    || selection.isEmpty()
                    || !(selection instanceof IStructuredSelection)) {
                  return;
                }
                _switchYardProject.setIntegrationVersion(
                    ((IStructuredSelection) selection).getFirstElement().toString());
              }
            });

    _settingsGroup
        .getKieVersionsList()
        .addSelectionChangedListener(
            new ISelectionChangedListener() {
              @Override
              public void selectionChanged(SelectionChangedEvent event) {
                ISelection selection = event.getSelection();
                if (selection == null
                    || selection.isEmpty()
                    || !(selection instanceof IStructuredSelection)) {
                  return;
                }
                _switchYardProject.setKieVersion(
                    ((IStructuredSelection) selection).getFirstElement().toString());
              }
            });
  }
  private void initTargetRuntime() {
    if (_ifpwc == null) {
      _settingsGroup
          .getTargetRuntimesList()
          .setSelection(new StructuredSelection(SwitchYardSettingsGroup.NULL_RUNTIME));
      _settingsGroup.getTargetRuntimesList().getControl().setEnabled(false);
      return;
    } else {
      _ifpwc = SharedWorkingCopyManager.getWorkingCopy(_ifp);
    }
    final IRuntime runtime = _ifpwc.getPrimaryRuntime();
    if (runtime == null) {
      _settingsGroup
          .getTargetRuntimesList()
          .setSelection(new StructuredSelection(SwitchYardSettingsGroup.NULL_RUNTIME));
    } else {
      for (IRuntimeComponent component : runtime.getRuntimeComponents()) {
        if (SWITCHYARD_RUNTIME_ID.equals(component.getRuntimeComponentType().getId())
            || FSW_RUNTIME_ID.equals(component.getRuntimeComponentType().getId())) {
          _settingsGroup
              .getTargetRuntimesList()
              .setSelection(new StructuredSelection(component), true);
        }
      }
    }
    _settingsGroup
        .getTargetRuntimesList()
        .addSelectionChangedListener(
            new ISelectionChangedListener() {
              @Override
              public void selectionChanged(SelectionChangedEvent event) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                if (selection.isEmpty()
                    || selection.getFirstElement() == SwitchYardSettingsGroup.NULL_RUNTIME) {
                  final IRuntime primaryRuntime = _ifpwc.getPrimaryRuntime();
                  if (primaryRuntime != null && !_configuredRuntimes.contains(primaryRuntime)) {
                    _ifpwc.removeTargetedRuntime(primaryRuntime);
                  } else if (primaryRuntime != null
                      && selection.getFirstElement() == SwitchYardSettingsGroup.NULL_RUNTIME) {
                    _ifpwc.removeTargetedRuntime(primaryRuntime);
                  }
                  _settingsGroup
                      .getIntegrationVersionsList()
                      .setSelection(new StructuredSelection(""));
                  _switchYardProject.setIntegrationVersion(null);
                  _settingsGroup.getKieVersionsList().setSelection(new StructuredSelection(""));
                  _switchYardProject.setKieVersion(null);
                } else {
                  final IRuntimeComponent component =
                      (IRuntimeComponent) selection.getFirstElement();
                  final IRuntime runtime = component.getRuntime();
                  if (!_ifpwc.isTargeted(
                      runtime)) { // if it's already targeted, we don't need to add it
                    _ifpwc.addTargetedRuntime(runtime);
                  }
                  _ifpwc.setPrimaryRuntime(runtime);

                  if (component != null) {
                    ArtifactVersion intVersion = _settingsGroup.getIntegVersion(component);
                    if (intVersion != null) {
                      _settingsGroup
                          .getIntegrationVersionsList()
                          .setSelection(new StructuredSelection(intVersion));
                    } else {
                      _settingsGroup
                          .getIntegrationVersionsList()
                          .setSelection(new StructuredSelection(""));
                    }
                    ArtifactVersion kieVersion = _settingsGroup.getKieVersion(component);
                    if (kieVersion != null) {
                      _settingsGroup
                          .getKieVersionsList()
                          .setSelection(new StructuredSelection(kieVersion));
                    } else {
                      _settingsGroup.getKieVersionsList().setSelection(new StructuredSelection(""));
                    }
                  }
                }
              }
            });
  }
 private IProjectFacetVersion getConfigurationVersion() {
   return _settingsGroup.getSelectedConfigurationVersion();
 }