/**
  * Updates the favorites selections from the local configuration
  *
  * @param config the local configuration
  */
 private void updateFavoritesFromConfig(ILaunchConfiguration config) {
   fFavoritesTable.setInput(config);
   fFavoritesTable.setCheckedElements(new Object[] {});
   try {
     List groups = config.getAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, new ArrayList());
     if (groups.isEmpty()) {
       // check old attributes for backwards compatible
       if (config.getAttribute(IDebugUIConstants.ATTR_DEBUG_FAVORITE, false)) {
         groups.add(IDebugUIConstants.ID_DEBUG_LAUNCH_GROUP);
       }
       if (config.getAttribute(IDebugUIConstants.ATTR_RUN_FAVORITE, false)) {
         groups.add(IDebugUIConstants.ID_RUN_LAUNCH_GROUP);
       }
     }
     if (!groups.isEmpty()) {
       List list = new ArrayList();
       Iterator iterator = groups.iterator();
       while (iterator.hasNext()) {
         String id = (String) iterator.next();
         LaunchGroupExtension extension = getLaunchConfigurationManager().getLaunchGroup(id);
         if (extension != null) {
           list.add(extension);
         }
       }
       fFavoritesTable.setCheckedElements(list.toArray());
     }
   } catch (CoreException e) {
     LaunchPlugin.log(e);
   }
 }
 /**
  * Returns whether the given configuration should be launched in the background.
  *
  * @param configuration the configuration
  * @return whether the configuration is configured to launch in the background
  */
 public static boolean isLaunchInBackground(ILaunchConfiguration configuration) {
   boolean launchInBackground = true;
   try {
     launchInBackground =
         configuration.getAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true);
   } catch (CoreException ce) {
     LaunchPlugin.log(ce);
   }
   return launchInBackground;
 }
 /**
  * Update the favorite settings.
  *
  * <p>NOTE: set to <code>null</code> instead of <code>false</code> for backwards compatibility
  * when comparing if content is equal, since 'false' is default and will be missing for older
  * configurations.
  *
  * @param config the configuration to update
  */
 private void updateConfigFromFavorites(ILaunchConfigurationWorkingCopy config) {
   try {
     Object[] checked = fFavoritesTable.getCheckedElements();
     boolean debug = config.getAttribute(IDebugUIConstants.ATTR_DEBUG_FAVORITE, false);
     boolean run = config.getAttribute(IDebugUIConstants.ATTR_RUN_FAVORITE, false);
     if (debug || run) {
       // old attributes
       List groups = new ArrayList();
       int num = 0;
       if (debug) {
         groups.add(
             getLaunchConfigurationManager()
                 .getLaunchGroup(IDebugUIConstants.ID_DEBUG_LAUNCH_GROUP));
         num++;
       }
       if (run) {
         num++;
         groups.add(
             getLaunchConfigurationManager()
                 .getLaunchGroup(IDebugUIConstants.ID_RUN_LAUNCH_GROUP));
       }
       // see if there are any changes
       if (num == checked.length) {
         boolean different = false;
         for (int i = 0; i < checked.length; i++) {
           if (!groups.contains(checked[i])) {
             different = true;
             break;
           }
         }
         if (!different) {
           return;
         }
       }
     }
     config.setAttribute(IDebugUIConstants.ATTR_DEBUG_FAVORITE, (String) null);
     config.setAttribute(IDebugUIConstants.ATTR_RUN_FAVORITE, (String) null);
     List groups = null;
     for (int i = 0; i < checked.length; i++) {
       LaunchGroupExtension group = (LaunchGroupExtension) checked[i];
       if (groups == null) {
         groups = new ArrayList();
       }
       groups.add(group.getIdentifier());
     }
     config.setAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, groups);
   } catch (CoreException e) {
     LaunchPlugin.log(e);
   }
 }
 /**
  * Returns the default encoding for the specified config
  *
  * @param config the configuration to get the encoding for
  * @return the default encoding
  * @since 3.4
  */
 private String getDefaultEncoding(ILaunchConfiguration config) {
   try {
     IResource[] resources = config.getMappedResources();
     if (resources != null && resources.length > 0) {
       IResource res = resources[0];
       if (res instanceof IFile) {
         return ((IFile) res).getCharset();
       } else if (res instanceof IContainer) {
         return ((IContainer) res).getDefaultCharset();
       }
     }
   } catch (CoreException ce) {
     LaunchPlugin.log(ce);
   }
   return ResourcesPlugin.getEncoding();
 }
 private String getDefaultSharedConfigLocation(ILaunchConfiguration config) {
   String path = IInternalDebugCoreConstants.EMPTY_STRING;
   try {
     IResource[] res = config.getMappedResources();
     if (res != null) {
       IProject proj;
       for (int i = 0; i < res.length; i++) {
         proj = res[i].getProject();
         if (proj != null && proj.isAccessible()) {
           return proj.getFullPath().toOSString();
         }
       }
     }
   } catch (CoreException e) {
     LaunchPlugin.log(e);
   }
   return path;
 }
 /**
  * Updates the encoding
  *
  * @param configuration the local configuration
  */
 private void updateEncoding(ILaunchConfiguration configuration) {
   String encoding = null;
   try {
     encoding = configuration.getAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, (String) null);
   } catch (CoreException e) {
     LaunchPlugin.log(e);
   }
   String defaultEncoding = getDefaultEncoding(configuration);
   fDefaultEncodingButton.setText(
       MessageFormat.format(
           LaunchConfigurationsMessages.CommonTab_2, new String[] {defaultEncoding}));
   fDefaultEncodingButton.pack();
   if (encoding != null) {
     fAltEncodingButton.setSelection(true);
     fDefaultEncodingButton.setSelection(false);
     fEncodingCombo.setText(encoding);
     fEncodingCombo.setEnabled(true);
   } else {
     fDefaultEncodingButton.setSelection(true);
     fAltEncodingButton.setSelection(false);
     fEncodingCombo.setEnabled(false);
   }
 }
  /**
   * Updates the console output form the local configuration
   *
   * @param configuration the local configuration
   */
  private void updateConsoleOutput(ILaunchConfiguration configuration) {
    boolean outputToConsole = true;
    String outputFile = null;
    boolean append = false;

    try {
      outputToConsole = configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, true);
      outputFile =
          configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_FILE, (String) null);
      append = configuration.getAttribute(IDebugUIConstants.ATTR_APPEND_TO_FILE, false);
    } catch (CoreException e) {
      LaunchPlugin.log(e);
    }

    fConsoleOutput.setSelection(outputToConsole);
    fAppend.setSelection(append);
    boolean haveOutputFile = outputFile != null;
    if (haveOutputFile) {
      fFileText.setText(outputFile);
    }
    fFileOutput.setSelection(haveOutputFile);
    enableOuputCaptureWidgets(haveOutputFile);
  }