Java Code Examples for org.eclipse.debug.core.ILaunchConfigurationWorkingCopy#setAttributes()

The following examples show how to use org.eclipse.debug.core.ILaunchConfigurationWorkingCopy#setAttributes() . 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: RunConfigurationConverter.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Converts a {@link RunConfiguration} to an {@link ILaunchConfiguration}. Will throw a {@link WrappedException} in
 * case of error.
 *
 * @see RunConfiguration#readPersistentValues()
 */
public ILaunchConfiguration toLaunchConfiguration(ILaunchConfigurationType type, RunConfiguration runConfig) {
	try {
		final ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager()
				.getLaunchConfigurations(type);

		for (ILaunchConfiguration config : configs) {
			if (equals(runConfig, config))
				return config;
		}

		final IContainer container = null;
		final ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(container, runConfig.getName());

		workingCopy.setAttributes(runConfig.readPersistentValues());

		return workingCopy.doSave();
	} catch (Exception e) {
		throw new WrappedException("could not convert N4JS RunConfiguration to Eclipse ILaunchConfiguration", e);
	}
}
 
Example 2
Source File: TestConfigurationConverter.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts a {@link TestConfiguration} to an {@link ILaunchConfiguration}. Will throw a {@link WrappedException} in
 * case of error.
 *
 * @param failed
 *            may be null, only used in test view to execute failed tests
 * @see TestConfiguration#readPersistentValues()
 */
public ILaunchConfiguration toLaunchConfiguration(ILaunchConfigurationType type, TestConfiguration testConfig,
		List<TestCase> failed) {
	try {
		final ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager()
				.getLaunchConfigurations(type);

		for (ILaunchConfiguration config : configs) {
			if (equals(testConfig, config))
				return config;
		}

		final IContainer container = null;
		final ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(container, testConfig.getName());

		workingCopy.setAttributes(testConfig.readPersistentValues());
		if (failed != null && !failed.isEmpty()) {
			workingCopy.setAttribute(TestConfiguration.TESTCASE_SELECTION,
					failed.stream().map(tc -> {
						String s = tc.getURI().toString();
						return s;
					}).collect(Collectors.toList()));
		}

		return workingCopy.doSave();
	} catch (Exception e) {
		throw new WrappedException("could not convert N4JS TestConfiguration to Eclipse ILaunchConfiguration", e);
	}
}
 
Example 3
Source File: TexLaunchConfigurationTab.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Copies values from this tab into the given 
 * launch configuration.
 * 
 * @param configuration launch configuration
 */
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
    registry.setActiveViewer(choiceCombo.getItem(choiceCombo.getSelectionIndex()));
    registry.setCommand(commandField.getText());
    registry.setArguments(argumentField.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());
    configuration.setAttributes(registry.asMap());
}
 
Example 4
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();
}