Java Code Examples for org.eclipse.debug.core.ILaunchManager#getLaunchConfigurations()

The following examples show how to use org.eclipse.debug.core.ILaunchManager#getLaunchConfigurations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NewProjectCreatorTool.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private static void removeLaunchConfig(String launchConfigName) throws Exception {
  ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
  try {
    ILaunchConfiguration[] launchConfigs = manager.getLaunchConfigurations();
    for (ILaunchConfiguration launchConfig : launchConfigs) {
      if (launchConfig.getName().equals(launchConfigName)) {
        launchConfig.delete();
        break;
      }
    }

  } catch (CoreException e) {
    GWTPluginLog.logError(e);
    throw new Exception("Could not remove existing Java launch configuration");
  }
}
 
Example 2
Source File: FatJarPackageWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private LaunchConfigurationElement[] getLaunchConfigurations() {
	ArrayList<ExistingLaunchConfigurationElement> result= new ArrayList<ExistingLaunchConfigurationElement>();

	try {
		ILaunchManager manager= DebugPlugin.getDefault().getLaunchManager();
		ILaunchConfigurationType type= manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
		ILaunchConfiguration[] launchconfigs= manager.getLaunchConfigurations(type);

		for (int i= 0; i < launchconfigs.length; i++) {
			ILaunchConfiguration launchconfig= launchconfigs[i];
			if (!launchconfig.getAttribute(IDebugUIConstants.ATTR_PRIVATE, false)) {
				String projectName= launchconfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
				result.add(new ExistingLaunchConfigurationElement(launchconfig, projectName));
			}
		}
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}

	return result.toArray(new LaunchConfigurationElement[result.size()]);
}
 
Example 3
Source File: LaunchConfigurationUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param typeIds launch configuration type ids that will be searched for, or
 *          empty to match all
 * @throws CoreException
 */
public static List<ILaunchConfiguration> getLaunchConfigurations(
    IProject project, String... typeIds) throws CoreException {
  Set<String> setOfTypeIds = new HashSet<String>(Arrays.asList(typeIds));
  ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
  List<ILaunchConfiguration> launchConfigs = new ArrayList<ILaunchConfiguration>();
  for (ILaunchConfiguration launchConfig : manager.getLaunchConfigurations()) {
    IJavaProject javaProject = getJavaProject(launchConfig);
    boolean typeIdIsOk = setOfTypeIds.isEmpty()
        || setOfTypeIds.contains(launchConfig.getType().getIdentifier());
    if (javaProject != null && project.equals(javaProject.getProject())
        && typeIdIsOk) {
      launchConfigs.add(launchConfig);
    }
  }

  return launchConfigs;
}
 
Example 4
Source File: FixedFatJarExportPage.java    From sarl with Apache License 2.0 6 votes vote down vote up
protected LaunchConfigurationElement[] getLaunchConfigurations() {
	ArrayList<ExistingLaunchConfigurationElement> result= new ArrayList<>();

	try {
		ILaunchManager manager= DebugPlugin.getDefault().getLaunchManager();
		ILaunchConfigurationType type= manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
		ILaunchConfiguration[] launchconfigs= manager.getLaunchConfigurations(type);

		for (int i= 0; i < launchconfigs.length; i++) {
			ILaunchConfiguration launchconfig= launchconfigs[i];
			if (!launchconfig.getAttribute(IDebugUIConstants.ATTR_PRIVATE, false)) {
				String projectName= launchconfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
				result.add(new ExistingLaunchConfigurationElement(launchconfig, projectName));
			}
		}
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}

	return result.toArray(new LaunchConfigurationElement[result.size()]);
}
 
Example 5
Source File: TestabilityLaunchConfigurationHelper.java    From testability-explorer with Apache License 2.0 6 votes vote down vote up
public ILaunchConfiguration getLaunchConfiguration(String projectName) {
  try {
    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType type = launchManager
        .getLaunchConfigurationType(TestabilityConstants.TESTABILITY_LAUNCH_CONFIGURATION_TYPE);
    ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(type);
    for (ILaunchConfiguration launchConfiguration : launchConfigurations) {
      String configProjectName =
          launchConfiguration.getAttribute(TestabilityConstants.CONFIGURATION_ATTR_PROJECT_NAME,
              "");
      if (configProjectName.equals(projectName)
          && isValidToRun(projectName, launchConfiguration)) {
        return launchConfiguration;
      }
    }
  } catch (CoreException e) {
    logger.logException(e);
  }
  return null;
}
 
Example 6
Source File: RustLaunchDelegateTools.java    From corrosion with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Finds or creates a new launch configuration that matches the given search
 * terms
 *
 * @param resource
 * @param launchConfigurationType
 * @return The matching launch configuration or a new launch configuration
 *         working copy or null if unable to make a new one
 */
public static ILaunchConfiguration getLaunchConfiguration(IResource resource, String launchConfigurationType) {
	ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
	ILaunchConfigurationType configType = launchManager.getLaunchConfigurationType(launchConfigurationType);
	try {
		ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(configType);
		final String projectName = resource.getProject().getName();
		String launchConfigProjectAttribute;
		if (launchConfigurationType.equals(CORROSION_DEBUG_LAUNCH_CONFIG_TYPE)) {
			launchConfigProjectAttribute = ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME;
		} else {
			launchConfigProjectAttribute = RustLaunchDelegateTools.PROJECT_ATTRIBUTE;
		}
		for (ILaunchConfiguration iLaunchConfiguration : launchConfigurations) {
			if (iLaunchConfiguration.getAttribute(launchConfigProjectAttribute, "") //$NON-NLS-1$
					.equals(projectName)) {
				return iLaunchConfiguration;
			}
		}
		String configName = launchManager.generateLaunchConfigurationName(projectName);
		return configType.newInstance(null, configName);
	} catch (CoreException e) {
		CorrosionPlugin.logError(e);
	}
	return null;
}
 
Example 7
Source File: WebAppLaunchUtil.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static ILaunchConfiguration findConfigurationByName(String name) {
  try {
    String configTypeStr = WebAppLaunchConfiguration.TYPE_ID;
    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType typeid = launchManager.getLaunchConfigurationType(configTypeStr);
    ILaunchConfiguration[] configs = launchManager.getLaunchConfigurations(typeid);

    for (ILaunchConfiguration config : configs) {
      if (config.getName().equals(name)) {
        return config;
      }
    }
  } catch (CoreException e) {
    CorePluginLog.logError(e);
  }
  return null;
}
 
Example 8
Source File: TLCModelFactory.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * @see Model#getByName(String)
 */
public static Model getByName(final String fullQualifiedModelName) {
	Assert.isNotNull(fullQualifiedModelName);
	Assert.isLegal(fullQualifiedModelName.contains(Model.SPEC_MODEL_DELIM), "Not a full-qualified model name.");
	
       final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
       final ILaunchConfigurationType launchConfigurationType = launchManager
               .getLaunchConfigurationType(TLCModelLaunchDelegate.LAUNCH_CONFIGURATION_TYPE);

	try {
		final ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(launchConfigurationType);
		for (int i = 0; i < launchConfigurations.length; i++) {
			// Can do equals here because of full qualified name.
			final ILaunchConfiguration launchConfiguration = launchConfigurations[i];
			if (fullQualifiedModelName.equals(launchConfiguration.getName())) {
				return launchConfiguration.getAdapter(Model.class);
			}
		}
	} catch (CoreException shouldNeverHappen) {
		shouldNeverHappen.printStackTrace();
	}
	
	return null;
}
 
Example 9
Source File: LaunchShortcut.java    From dartboard with Eclipse Public License 2.0 5 votes vote down vote up
private void launchProject(IProject project, String mode) {
	if (project == null) {
		MessageDialog.openError(PlatformUIUtil.getActiveShell(), Messages.Launch_ConfigurationRequired_Title,
				Messages.Launch_ConfigurationRequired_Body);
		return;
	}

	ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();

	ILaunchConfigurationType type = manager.getLaunchConfigurationType(Constants.LAUNCH_CONFIGURATION_ID);

	try {
		// Find last launch configuration for selected project.
		ILaunchConfiguration launchConfiguration = null;
		for (ILaunchConfiguration conf : manager.getLaunchConfigurations(type)) {
			if (conf.getAttribute(Constants.LAUNCH_SELECTED_PROJECT, "").equalsIgnoreCase(project.getName())) { //$NON-NLS-1$
				launchConfiguration = conf;
			}
		}

		if (launchConfiguration != null) {
			DebugUITools.launch(launchConfiguration, mode);
		} else {
			ILaunchConfigurationWorkingCopy copy = type.newInstance(null, manager.generateLaunchConfigurationName(
					LaunchConfigurationsMessages.CreateLaunchConfigurationAction_New_configuration_2));

			copy.setAttribute(Constants.LAUNCH_SELECTED_PROJECT, project.getName());
			copy.setAttribute(Constants.LAUNCH_MAIN_CLASS, project.getPersistentProperty(StagehandGenerator.QN_ENTRYPOINT));

			int result = DebugUITools.openLaunchConfigurationDialog(PlatformUIUtil.getActiveShell(), copy,
					Constants.LAUNCH_GROUP, null);

			if (result == Window.OK) {
				copy.doSave();
			}
		}
	} catch (CoreException e) {
		LOG.log(DartLog.createError("Could not save new launch configuration", e)); //$NON-NLS-1$
	}
}
 
Example 10
Source File: GwtSuperDevModeCodeServerLaunchUtil.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds and returns an <b>existing</b> configuration to re-launch for the given URL, or
 * <code>null</code> if there is no existing configuration.
 *
 * @return a configuration to use for launching the given type or <code>null
 *         </code> if none
 * @throws CoreException
 */
private static ILaunchConfiguration findLaunchConfiguration(IProject project) throws CoreException {
  ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
  ILaunchConfigurationType typeid =
      launchManager.getLaunchConfigurationType(GwtSuperDevModeLaunchConfiguration.TYPE_ID);
  ILaunchConfiguration[] configs = launchManager.getLaunchConfigurations(typeid);

  return searchMatchingConfigWithProject(project, configs);
}
 
Example 11
Source File: HybridProjectLaunchShortcut.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new launch configuration for the given project if one does not exists.
 * 
 * @param project
 * @return
 * @throws CoreException
 */
private ILaunchConfiguration findOrCreateLaunchConfiguration(IProject project) throws CoreException{
	ILaunchManager lm = getLaunchManager();
	ILaunchConfigurationType configType = getLaunchConfigurationType();
	ILaunchConfiguration[] confs = lm.getLaunchConfigurations(configType);
	for (ILaunchConfiguration configuration : confs) {
		if(isCorrectLaunchConfiguration(project, configuration)){
			return configuration;
		}
	}
	return createLaunchConfiguration(project);
}
 
Example 12
Source File: LaunchPipelineShortcut.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private ILaunchConfiguration[] getDataflowLaunchConfigurations() {
  ILaunchManager launchManager = getLaunchManager();
  ILaunchConfigurationType launchConfigurationType =
      getDataflowLaunchConfigurationType(launchManager);
  try {
    return launchManager.getLaunchConfigurations(launchConfigurationType);
  } catch (CoreException e) {
    // TODO: handle
    DataflowUiPlugin.logError(e,
        "Exception while trying to retrieve Dataflow launch configurations");
  }
  return new ILaunchConfiguration[0];
}
 
Example 13
Source File: AbstractLaunchShortcut.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * COPIED/MODIFIED from AntLaunchShortcut
 * Returns a list of existing launch configuration for the given file.
 */
protected List<ILaunchConfiguration> findExistingLaunchConfigurations(FileOrResource[] file) {
    ILaunchManager manager = org.eclipse.debug.core.DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType type = manager.getLaunchConfigurationType(getLaunchConfigurationType());
    List<ILaunchConfiguration> validConfigs = new ArrayList<ILaunchConfiguration>();
    if (type == null) {
        return validConfigs;
    }

    try {
        ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);

        //let's see if we can find it with a location relative or not.
        String defaultLocation = LaunchConfigurationCreator.getDefaultLocation(file, true);
        String defaultLocation2 = LaunchConfigurationCreator.getDefaultLocation(file, false);

        for (int i = 0; i < configs.length; i++) {
            String configPath = configs[i].getAttribute(Constants.ATTR_LOCATION, "");
            if (defaultLocation.equals(configPath) || defaultLocation2.equals(configPath)) {
                validConfigs.add(configs[i]);
            }
        }
    } catch (CoreException e) {
        reportError("Unexpected error", e);
    }
    return validConfigs;
}
 
Example 14
Source File: DotnetRunDelegate.java    From aCute with Eclipse Public License 2.0 5 votes vote down vote up
private ILaunchConfiguration getLaunchConfiguration(String mode, IResource resource) {
	ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
	ILaunchConfigurationType configType = launchManager
			.getLaunchConfigurationType("org.eclipse.acute.dotnetrun.DotnetRunDelegate"); //$NON-NLS-1$
	try {
		ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(configType);

		String configName;
		if (resource.getLocation().toFile().isFile()) {
			configName = NLS.bind(Messages.DotnetRunDelegate_configuration, resource.getParent().getName() + "." + resource.getName()); //$NON-NLS-1$
		} else {
			configName = NLS.bind(Messages.DotnetRunDelegate_configuration, resource.getName());
		}

		for (ILaunchConfiguration iLaunchConfiguration : launchConfigurations) {
			if (iLaunchConfiguration.getName().equals(configName)
					&& iLaunchConfiguration.getModes().contains(mode)) {
				return iLaunchConfiguration;
			}
		}
		configName = launchManager.generateLaunchConfigurationName(configName);
		ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, configName);
		if (resource.getLocation().toFile().isFile()) {
			resource = resource.getParent();
		}
		wc.setAttribute(PROJECT_FOLDER, resource.getLocation().toString());
		return wc;
	} catch (CoreException e) {
		AcutePlugin.logError(e);
	}
	return null;
}
 
Example 15
Source File: CompilerLaunchShortcut.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
protected ILaunchConfiguration findLaunchConfiguration(IResource resource) throws CoreException {
  ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
  ILaunchConfigurationType typeid = launchManager.getLaunchConfigurationType(CompilerLaunchConfiguration.TYPE_ID);
  ILaunchConfiguration[] configs = launchManager.getLaunchConfigurations(typeid);

  return searchMatchingUrlAndProject(resource.getProject(), configs);
}
 
Example 16
Source File: WebAppLaunchShortcut.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds and returns an <b>existing</b> configuration to re-launch for the given URL, or <code>null</code> if there is
 * no existing configuration.
 *
 * @return a configuration to use for launching the given type or <code>null
 *         </code> if none
 * @throws CoreException
 */
protected ILaunchConfiguration findLaunchConfiguration(IResource resource, String startupUrl, boolean isExternal)
    throws CoreException {

  ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
  ILaunchConfigurationType typeid = launchManager.getLaunchConfigurationType(WebAppLaunchConfiguration.TYPE_ID);
  ILaunchConfiguration[] configs = launchManager.getLaunchConfigurations(typeid);

  return searchMatchingUrlAndProject(startupUrl, resource.getProject(), isExternal, configs);
}
 
Example 17
Source File: LaunchShortcutTest.java    From dartboard with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void launchShortcut__DartProjectNoLaunchConfig__NewLaunchConfigIsCreated() throws Exception {
	String projectName = RandomString.make(8);
	String mainClass = RandomString.make(4) + ".dart";
	ProjectUtil.createDartProject(projectName);

	ProjectExplorer projectExplorer = new ProjectExplorer();
	projectExplorer.open();
	projectExplorer.getProject(projectName).select();

	new ContextMenuItem(new WithMnemonicTextMatcher("Run As"), new RegexMatcher("\\d Run as Dart Program"))
			.select();

	new WaitUntil(new ShellIsActive("Edit Configuration"));
	new LabeledCombo("Project:").setSelection(projectName);
	new LabeledText("Main class:").setText(mainClass);
	new PushButton("Run").click();
	ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();

	// Find last launch configuration for selected project.
	ILaunchConfiguration launchConfiguration = null;
	for (ILaunchConfiguration conf : manager.getLaunchConfigurations()) {
		if (conf.getAttribute(Constants.LAUNCH_SELECTED_PROJECT, "").equalsIgnoreCase(projectName)) { //$NON-NLS-1$
			launchConfiguration = conf;
		}
	}

	assertNotNull(launchConfiguration);
	assertEquals(launchConfiguration.getAttribute("main_class", ""), mainClass);

	// Cleanup
	launchConfiguration.delete();
}
 
Example 18
Source File: CloneForeignModelHandler.java    From tlaplus with MIT License 4 votes vote down vote up
private TreeMap<String, TreeSet<Model>> buildMap() {
       final Spec currentSpec = ToolboxHandle.getCurrentSpec();
       if (currentSpec == null) {
       	return null;
       }
       
	final IProject specProject = currentSpec.getProject();
	final TreeMap<String, TreeSet<Model>> projectModelMap = new TreeMap<>();
	
	try {
		final IWorkspace iws = ResourcesPlugin.getWorkspace();
		final IWorkspaceRoot root = iws.getRoot();
		final IProject[] projects = root.getProjects();
		
		for (final IProject project : projects) {
			if (!specProject.equals(project)) {
				projectModelMap.put(project.getName(), new TreeSet<>(MODEL_SORTER));
			}
		}
		
		final String currentProjectName = specProject.getName();
		final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
		final ILaunchConfigurationType launchConfigurationType
				= launchManager.getLaunchConfigurationType(TLCModelLaunchDelegate.LAUNCH_CONFIGURATION_TYPE);
		final ILaunchConfiguration[] launchConfigurations
				= launchManager.getLaunchConfigurations(launchConfigurationType);
		for (final ILaunchConfiguration launchConfiguration : launchConfigurations) {
			final String projectName = launchConfiguration.getAttribute(IConfigurationConstants.SPEC_NAME, "-l!D!q_-l!D!q_-l!D!q_");
			if (!projectName.equals(currentProjectName)) {
				final TreeSet<Model> models = projectModelMap.get(projectName);
				
				if (models != null) {
					final Model model = launchConfiguration.getAdapter(Model.class);
					
					if (!model.isSnapshot()) {
						models.add(model);
					}
				} else {
					TLCUIActivator.getDefault().logError("Could not generate model map for [" + projectName + "]!");
				}
			}
		}
	} catch (final CoreException e) {
		TLCUIActivator.getDefault().logError("Building foreign model map.", e);
		
		return null;
	}
	
	return projectModelMap;
}
 
Example 19
Source File: ViewerConfigDialog.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Check that the config is valid.
 * Close the dialog is the config is valid.
 */
protected void okPressed() {
    
    if (!validateFields())
        return;
    
    String name = nameField.getText();
    registry.setActiveViewer(nameField.getText());
    registry.setCommand(fileField.getText());
    registry.setArguments(argsField.getText());        
    registry.setDDEViewCommand(ddeViewGroup.command.getText());
    registry.setDDEViewServer(ddeViewGroup.server.getText());
    registry.setDDEViewTopic(ddeViewGroup.topic.getText());
    registry.setDDECloseCommand(ddeCloseGroup.command.getText());
    registry.setDDECloseServer(ddeCloseGroup.server.getText());
    registry.setDDECloseTopic(ddeCloseGroup.topic.getText());
    registry.setFormat(formatChooser.getItem(formatChooser.getSelectionIndex()));
    registry.setInverse(inverseSearchValues[inverseChooser.getSelectionIndex()]);
    registry.setForward(forwardChoice.getSelection());
    
    // Ask user if launch configs should be updated
    try {
        ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
        if (manager != null) {
            ILaunchConfigurationType type = manager.getLaunchConfigurationType(
                TexLaunchConfigurationDelegate.CONFIGURATION_ID);
            if (type != null) {
                ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
                if (configs != null) {
                    // Check all configurations
                    int returnCode = 0;
                    MessageDialogWithToggle md = null;
                    for (int i = 0; i < configs.length ; i++) {
                        ILaunchConfiguration c = configs[i];
                        if (c.getType().getIdentifier().equals(TexLaunchConfigurationDelegate.CONFIGURATION_ID)) {
                            if (c.getAttribute("viewerCurrent", "").equals(name)) {
                                // We've found a config which was based on this viewer 
                                if (0 == returnCode) {
                                    String message = MessageFormat.format(
                                        TexlipsePlugin.getResourceString("preferenceViewerUpdateConfigurationQuestion"),
                                        new Object[] { c.getName() });
                                    md = MessageDialogWithToggle.openYesNoCancelQuestion(getShell(),
                                        TexlipsePlugin.getResourceString("preferenceViewerUpdateConfigurationTitle"), message,
                                        TexlipsePlugin.getResourceString("preferenceViewerUpdateConfigurationAlwaysApply"),
                                        false, null, null);
                                    
                                    if (md.getReturnCode() == MessageDialogWithToggle.CANCEL)
                                        return;
                                    
                                    returnCode = md.getReturnCode();
                                } 
                                    
                                // If answer was yes, update each config with latest values from registry
                                if (returnCode == IDialogConstants.YES_ID) {
                                    ILaunchConfigurationWorkingCopy workingCopy = c.getWorkingCopy();
                                    workingCopy.setAttributes(registry.asMap());

                                    // We need to set at least one attribute using a one-shot setter method
                                    // because the method setAttributes does not mark the config as dirty. 
                                    // A dirty config is required for a doSave to do anything useful. 
                                    workingCopy.setAttribute("viewerCurrent", name);
                                    workingCopy.doSave();
                                }
                                
                                // Reset return-code if we should be asked again
                                if (!md.getToggleState()) {
                                    returnCode = 0;
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (CoreException e) {
        // Something wrong with the config, or could not read attributes, so swallow and skip
    }

    setReturnCode(OK);
    close();
}
 
Example 20
Source File: PreviewAction.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
    *  Launches either the most recent viewer configuration, or if there
    *  is no previous viewers, creates a new viewer launch configuration.
 */
public void run(IAction action) {
       try {      	
       	ILaunchConfiguration config = null;
       	
           
           // Get the output format
           IProject project = TexlipsePlugin.getCurrentProject();
           String outputFormat = TexlipseProperties.getProjectProperty(project,
               TexlipseProperties.OUTPUT_FORMAT);
           
           // Get the preferred viewer for the current output format
           ViewerAttributeRegistry var = new ViewerAttributeRegistry();
           String preferredViewer = var.getPreferredViewer(outputFormat);

           if (null == preferredViewer) {
               BuilderRegistry.printToConsole(TexlipsePlugin.getResourceString("builderErrorOutputFormatNotSet").replaceAll("%s", project.getName()));
               throw new CoreException(TexlipsePlugin.stat("No previewer found for the current output format."));
           }
           
           ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
           ILaunchConfigurationType type = manager.getLaunchConfigurationType(
                   TexLaunchConfigurationDelegate.CONFIGURATION_ID);               
           ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
           if (configs != null) {
               // Try to find a recent viewer launch first
               for (ILaunchConfiguration c : configs) {
                   if (c.getType().getIdentifier().equals(TexLaunchConfigurationDelegate.CONFIGURATION_ID)) {
                       if (c.getAttribute("viewerCurrent", "").equals(preferredViewer)) {
                           config = c;
                           break;
                       }
                   }                
               }
           }
           
           // If there was no available viewer
           if (config == null)
           {
               // Create a new one
               ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null,
                       manager.generateUniqueLaunchConfigurationNameFrom("Preview Document in " + preferredViewer));
               
               // Request another viewer than the topmost in the preferences
               workingCopy.setAttribute("viewerCurrent", preferredViewer);
               
               // For some reason the Eclipse API wants us to init default values
               // for new configurations using the ConfigurationTab dialog.
               TexLaunchConfigurationTab tab = new TexLaunchConfigurationTab();                
               tab.setDefaults(workingCopy);     
               
               config = workingCopy.doSave();
           }
           
           DebugUITools.launch(config, ILaunchManager.RUN_MODE);        
       	
       	
       } catch (CoreException e) {
           TexlipsePlugin.log("Launching viewer", e);
       }
}