Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 283402 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ptp/services/ui/widgets/NewServiceModelWidgetDialog.java (+113 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Mike Kucera (IBM Corporation) - initial API and implementation
10
 *******************************************************************************/ 
11
package org.eclipse.ptp.services.ui.widgets;
12
13
import org.eclipse.ptp.services.core.IServiceConfiguration;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.events.SelectionAdapter;
16
import org.eclipse.swt.events.SelectionEvent;
17
import org.eclipse.swt.graphics.Rectangle;
18
import org.eclipse.swt.layout.GridData;
19
import org.eclipse.swt.layout.GridLayout;
20
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Dialog;
23
import org.eclipse.swt.widgets.Display;
24
import org.eclipse.swt.widgets.Shell;
25
26
/**
27
 * Launches a dialog that contains the NewServiceModelWidget
28
 * with OK and Cancel buttons.
29
 * 
30
 *
31
 *
32
 */
33
public class NewServiceModelWidgetDialog extends Dialog {
34
35
	private Shell shell;
36
	private NewServiceModelWidget serviceModelWidget;
37
	
38
	
39
	public NewServiceModelWidgetDialog(Shell parent, int style) {
40
		super(parent, style);
41
	}
42
43
	public NewServiceModelWidgetDialog(Shell parent) {
44
		super(parent);
45
	}
46
47
	
48
	public void open(IServiceConfiguration config) {
49
 		Shell parent = getParent();
50
 		shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE);
51
 		shell.setText(getText());
52
 		shell.setLayout(new GridLayout(1, false));
53
 		
54
 		serviceModelWidget = new NewServiceModelWidget(shell, SWT.NONE);
55
 		serviceModelWidget.setServiceConfiguration(config);
56
 		GridData data = new GridData(GridData.FILL_BOTH);
57
 		data.minimumHeight = 400;
58
 		serviceModelWidget.setLayoutData(data);
59
 		
60
 		Composite buttonComp = new Composite(shell, SWT.NONE);
61
 		buttonComp.setLayout(new GridLayout(2, true));
62
 		data = new GridData(GridData.FILL_BOTH);
63
 		data.horizontalAlignment = SWT.END;
64
 		buttonComp.setLayoutData(data);
65
 		
66
 		Button okButton = new Button(buttonComp, SWT.PUSH);
67
 		okButton.setText("OK"); //$NON-NLS-1$
68
 		data = new GridData(GridData.FILL_BOTH);
69
 		data.widthHint = 80;
70
 		okButton.setLayoutData(data);
71
 		okButton.addSelectionListener(new SelectionAdapter() {
72
			public void widgetSelected(SelectionEvent e) {
73
				performOk();
74
			}
75
		});
76
 		
77
 		Button cancelButton = new Button(buttonComp, SWT.PUSH);
78
 		cancelButton.setText("Cancel"); //$NON-NLS-1$
79
 		data = new GridData(GridData.FILL_BOTH);
80
 		data.widthHint = 80;
81
 		cancelButton.setLayoutData(data);
82
 		cancelButton.addSelectionListener(new SelectionAdapter() {
83
			public void widgetSelected(SelectionEvent e) {
84
				performCancel();
85
			}
86
		});
87
 		
88
 		
89
 		shell.pack();
90
 		
91
 		// center window
92
 		Rectangle r1 = parent.getBounds();
93
 		Rectangle r2 = shell.getBounds();
94
 		int x = r1.x + (r1.width - r2.width) / 2;
95
 		int y = r1.y + (r1.height - r2.height) / 2;
96
 		shell.setBounds(x, y, r2.width, r2.height);
97
 		
98
 		shell.open();
99
 		Display display = parent.getDisplay();
100
 		while (!shell.isDisposed()) {
101
 			if (!display.readAndDispatch()) display.sleep();
102
 		}
103
	}
104
105
	private void performCancel() {
106
		shell.dispose();
107
	}
108
109
	private void performOk() {
110
		serviceModelWidget.applyChangesToConfiguration();
111
		shell.dispose();
112
	}
113
}
(-)src/org/eclipse/ptp/remote/rse/ui/RSEUIFileManager.java (-2 / +4 lines)
Lines 37-43 Link Here
37
	 * @see org.eclipse.ptp.remote.IRemoteFileManager#browseDirectory(org.eclipse.swt.widgets.Shell, java.lang.String, java.lang.String)
37
	 * @see org.eclipse.ptp.remote.IRemoteFileManager#browseDirectory(org.eclipse.swt.widgets.Shell, java.lang.String, java.lang.String)
38
	 */
38
	 */
39
	public IPath browseDirectory(Shell shell, String message, String filterPath) {
39
	public IPath browseDirectory(Shell shell, String message, String filterPath) {
40
		SystemRemoteFolderDialog dlg = new SystemRemoteFolderDialog(shell, message, connHost);
40
		SystemRemoteFolderDialog dlg = new SystemRemoteFolderDialog(shell, message);
41
		dlg.setDefaultSystemConnection(connHost, true);
41
		dlg.setBlockOnOpen(true);
42
		dlg.setBlockOnOpen(true);
42
		if(dlg.open() == Window.OK) {
43
		if(dlg.open() == Window.OK) {
43
			connHost = dlg.getSelectedConnection();
44
			connHost = dlg.getSelectedConnection();
Lines 55-61 Link Here
55
	 * @see org.eclipse.ptp.remote.IRemoteFileManager#browseFile(org.eclipse.swt.widgets.Shell, java.lang.String, java.lang.String)
56
	 * @see org.eclipse.ptp.remote.IRemoteFileManager#browseFile(org.eclipse.swt.widgets.Shell, java.lang.String, java.lang.String)
56
	 */
57
	 */
57
	public IPath browseFile(Shell shell, String message, String filterPath) {
58
	public IPath browseFile(Shell shell, String message, String filterPath) {
58
		SystemRemoteFileDialog dlg = new SystemRemoteFileDialog(shell, message, connHost);
59
		SystemRemoteFileDialog dlg = new SystemRemoteFileDialog(shell, message);
60
		dlg.setDefaultSystemConnection(connHost, true);
59
		dlg.setBlockOnOpen(true);
61
		dlg.setBlockOnOpen(true);
60
		if(dlg.open() == Window.OK) {
62
		if(dlg.open() == Window.OK) {
61
			connHost = dlg.getSelectedConnection();
63
			connHost = dlg.getSelectedConnection();
(-)src/org/eclipse/ptp/rdt/ui/wizards/RemoteServicesServiceProviderConfigurer.java (-38 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM - Initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.rdt.ui.wizards;
12
13
import org.eclipse.jface.dialogs.Dialog;
14
import org.eclipse.ptp.services.core.IServiceProvider;
15
import org.eclipse.ptp.services.ui.IServiceProviderConfiguration;
16
import org.eclipse.swt.widgets.Shell;
17
18
/**
19
 * Allows the user to select a provider of Remote Services for a RemoteBuildServiceProvider.
20
 * 
21
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
22
 * part of a work in progress. There is no guarantee that this API will work or
23
 * that it will remain the same. Please do not use this API without consulting
24
 * with the RDT team.
25
 * 
26
 * @author crecoskie
27
 * @see org.eclipse.ptp.rdt.ui.serviceproviders.RemoteBuildServiceProvider
28
 * @deprecated
29
 */
30
public class RemoteServicesServiceProviderConfigurer implements IServiceProviderConfiguration {
31
32
33
	public void configureServiceProvider(IServiceProvider provider, Shell parentShell) {
34
		Dialog configDialog = new RemoteServicesProviderSelectionDialog(provider, parentShell);
35
		configDialog.open();
36
	}
37
	
38
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/ConvertToRemoteWizardPage.java (-48 / +64 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-18 Link Here
11
11
12
package org.eclipse.ptp.rdt.ui.wizards;
12
package org.eclipse.ptp.rdt.ui.wizards;
13
13
14
 
15
import java.io.IOException;
14
import java.lang.reflect.InvocationTargetException;
16
import java.lang.reflect.InvocationTargetException;
15
import java.text.MessageFormat;
17
import java.text.MessageFormat;
18
import java.util.HashMap;
16
import java.util.Map;
19
import java.util.Map;
17
20
18
import org.eclipse.cdt.ui.wizards.conversion.ConvertProjectWizardPage;
21
import org.eclipse.cdt.ui.wizards.conversion.ConvertProjectWizardPage;
Lines 25-35 Link Here
25
import org.eclipse.jface.viewers.ISelectionChangedListener;
28
import org.eclipse.jface.viewers.ISelectionChangedListener;
26
import org.eclipse.jface.viewers.IStructuredSelection;
29
import org.eclipse.jface.viewers.IStructuredSelection;
27
import org.eclipse.jface.viewers.SelectionChangedEvent;
30
import org.eclipse.jface.viewers.SelectionChangedEvent;
28
import org.eclipse.ptp.internal.rdt.ui.RDTHelpContextIds;
29
import org.eclipse.ptp.rdt.core.RDTLog;
31
import org.eclipse.ptp.rdt.core.RDTLog;
30
import org.eclipse.ptp.rdt.core.resources.RemoteNature;
32
import org.eclipse.ptp.rdt.core.resources.RemoteNature;
31
import org.eclipse.ptp.rdt.ui.messages.Messages;
33
import org.eclipse.ptp.services.core.IServiceConfiguration;
34
import org.eclipse.ptp.services.core.IServiceModelManager;
32
import org.eclipse.ptp.services.core.IServiceProvider;
35
import org.eclipse.ptp.services.core.IServiceProvider;
36
import org.eclipse.ptp.services.core.ServiceModelManager;
37
import org.eclipse.ptp.services.ui.widgets.NewServiceModelWidget;
38
39
import org.eclipse.ptp.rdt.ui.UIPlugin;
40
import org.eclipse.ptp.rdt.ui.messages.Messages;
33
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.layout.FillLayout;
42
import org.eclipse.swt.layout.FillLayout;
35
import org.eclipse.swt.layout.GridData;
43
import org.eclipse.swt.layout.GridData;
Lines 37-44 Link Here
37
import org.eclipse.swt.widgets.Event;
45
import org.eclipse.swt.widgets.Event;
38
import org.eclipse.swt.widgets.Group;
46
import org.eclipse.swt.widgets.Group;
39
import org.eclipse.swt.widgets.Listener;
47
import org.eclipse.swt.widgets.Listener;
40
import org.eclipse.swt.widgets.Shell;
41
import org.eclipse.ui.PlatformUI;
42
48
43
/**
49
/**
44
 * Converts existing CDT projects to RDT projects.
50
 * Converts existing CDT projects to RDT projects.
Lines 54-74 Link Here
54
    
60
    
55
    private static final String WZ_TITLE = "WizardProjectConversion.title"; //$NON-NLS-1$
61
    private static final String WZ_TITLE = "WizardProjectConversion.title"; //$NON-NLS-1$
56
    private static final String WZ_DESC = "WizardProjectConversion.description"; //$NON-NLS-1$
62
    private static final String WZ_DESC = "WizardProjectConversion.description"; //$NON-NLS-1$
57
    ConvertToRemoteServiceModelWidget fServiceModelWidget;
63
    NewServiceModelWidget fServiceModelWidget;
58
	Group remoteServices;
64
	Group remoteServices;
59
	
65
	
66
	Map<IProject, IServiceConfiguration> projectConfigs = new HashMap<IProject, IServiceConfiguration>();
67
	
60
	/**
68
	/**
61
	 * Constructor for ConvertToRemoteWizardPage.
69
	 * Constructor for ConvertToRemoteWizardPage.
62
	 * @param pageName
70
	 * @param pageName
63
	 */
71
	 */
64
	public ConvertToRemoteWizardPage(String pageName) {
72
	public ConvertToRemoteWizardPage(String pageName) {
65
		super(pageName);
73
		super(pageName);
66
		fServiceModelWidget = new ConvertToRemoteServiceModelWidget();
67
		fServiceModelWidget.setConfigChangeListener(new Listener() {
68
			public void handleEvent(Event event) {
69
				setPageComplete(validatePage());				
70
			}			
71
		});
72
	}
74
	}
73
    
75
    
74
    /**
76
    /**
Lines 102-108 Link Here
102
			b = !project.hasNature(RemoteNature.REMOTE_NATURE_ID);
104
			b = !project.hasNature(RemoteNature.REMOTE_NATURE_ID);
103
			c = !project.hasNature("org.eclipse.rse.ui.remoteSystemsTempNature"); //$NON-NLS-1$
105
			c = !project.hasNature("org.eclipse.rse.ui.remoteSystemsTempNature"); //$NON-NLS-1$
104
		} catch (CoreException e) {
106
		} catch (CoreException e) {
105
			RDTLog.logError(e);	
107
			RDTLog.logError(e);
106
		}
108
		}
107
		return a && b && c; 
109
		return a && b && c; 
108
    }
110
    }
Lines 116-124 Link Here
116
			RemoteNature.addRemoteNature(project, monitor);
118
			RemoteNature.addRemoteNature(project, monitor);
117
			configureServicesForRemoteProject(project);
119
			configureServicesForRemoteProject(project);
118
		} catch (InvocationTargetException e) {
120
		} catch (InvocationTargetException e) {
119
			RDTLog.logError(e);	
121
			RDTLog.logError(e);
120
		} catch (InterruptedException e) {
122
		} catch (InterruptedException e) {
121
			RDTLog.logError(e);	
123
			RDTLog.logError(e);
122
		} finally {
124
		} finally {
123
			monitor.done();
125
			monitor.done();
124
		}
126
		}
Lines 134-142 Link Here
134
			RemoteNature.addRemoteNature(project, monitor);
136
			RemoteNature.addRemoteNature(project, monitor);
135
			configureServicesForRemoteProject(project);
137
			configureServicesForRemoteProject(project);
136
		} catch (InvocationTargetException e) {
138
		} catch (InvocationTargetException e) {
137
			RDTLog.logError(e);	
139
			RDTLog.logError(e);
138
		} catch (InterruptedException e) {
140
		} catch (InterruptedException e) {
139
			RDTLog.logError(e);	
141
			RDTLog.logError(e);
140
		} finally {
142
		} finally {
141
			monitor.done();
143
			monitor.done();
142
		}
144
		}
Lines 147-169 Link Here
147
		remoteServices = new Group(container, SWT.SHADOW_IN);
149
		remoteServices = new Group(container, SWT.SHADOW_IN);
148
		remoteServices.setText(Messages.getString("WizardProjectConversion.servicesTableLabel")); //$NON-NLS-1$
150
		remoteServices.setText(Messages.getString("WizardProjectConversion.servicesTableLabel")); //$NON-NLS-1$
149
		remoteServices.setLayout(new FillLayout());
151
		remoteServices.setLayout(new FillLayout());
150
		remoteServices.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
152
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
153
		data.heightHint = 300;
154
		remoteServices.setLayoutData(data);
151
		
155
		
152
		//create the table for remote services
156
		
153
		fServiceModelWidget.createContents(remoteServices);
157
		fServiceModelWidget = new NewServiceModelWidget(remoteServices, SWT.NONE);
154
		//remove all the services in the table for now and add them back as project gets selected in the project list
155
		fServiceModelWidget.emptyTable();
156
	}
157
158
	public void createControl(Composite parent) {
159
		super.createControl(parent);
160
		tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
158
		tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
161
            public void selectionChanged(SelectionChangedEvent e) {
159
            public void selectionChanged(SelectionChangedEvent e) {
162
            	IProject project = (IProject) ((IStructuredSelection)e.getSelection()).getFirstElement();
160
            	IProject project = (IProject) ((IStructuredSelection)e.getSelection()).getFirstElement();
163
                if (project != null) {
161
                if (project != null) {
164
	            	//update the table with remote services available for the project selected
162
                	changeProject(project);
165
	            	fServiceModelWidget.addServicesToTable(project);
166
	            	remoteServices.setText(MessageFormat.format(Messages.getString("WizardProjectConversion.servicesTableForProjectLabel"), new Object[] {project.getName()}));  //$NON-NLS-1$
167
                }
163
                }
168
            }
164
            }
169
        });		
165
        });		
Lines 171-202 Link Here
171
			public void checkStateChanged(CheckStateChangedEvent e) {				
167
			public void checkStateChanged(CheckStateChangedEvent e) {				
172
				IProject project = (IProject) e.getElement();
168
				IProject project = (IProject) e.getElement();
173
				if (e.getChecked() && project != null) {
169
				if (e.getChecked() && project != null) {
174
	            	//update the table with remote services available for the project selected
170
					changeProject(project);
175
	            	fServiceModelWidget.addServicesToTable(project);
176
	            	remoteServices.setText(MessageFormat.format(Messages.getString("WizardProjectConversion.servicesTableForProjectLabel"), new Object[] {project.getName()}));  //$NON-NLS-1$
177
				}							
171
				}							
178
			}			
172
			}			
179
		});
173
		});
180
		Shell shell = getContainer().getShell();
181
		PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,RDTHelpContextIds.CONVERTING_TO_REMOTE_PROJECT);
182
	}
183
	
184
	private void configureServicesForRemoteProject(IProject project) throws InvocationTargetException,
185
			InterruptedException {
186
		Map<IProject, Map<String,String>> projectToServices = fServiceModelWidget.getProjectToServices();
187
		Map<IProject, Map<String,IServiceProvider>> projectToProviders = fServiceModelWidget.getProjectToProviders();
188
		
174
		
189
		Map<String, String> serviceIDToProviderIDMap = projectToServices.get(project);
190
		Map<String, IServiceProvider> providerIDToProviderMap = projectToProviders.get(project);
191
		
175
		
192
		ConfigureRemoteServices.configure(project, serviceIDToProviderIDMap, providerIDToProviderMap, new NullProgressMonitor());
193
	}
176
	}
194
177
195
	/* (non-Javadoc)
178
	
196
	 * @see org.eclipse.cdt.ui.wizards.conversion.ConvertProjectWizardPage#validatePage()
197
	 */
198
	@Override
179
	@Override
199
	protected boolean validatePage() {
180
	public void doRun(IProgressMonitor monitor, String projectID, String bsId)throws CoreException {
200
		return super.validatePage() && fServiceModelWidget.isConfigured(getCheckedElements());
181
		fServiceModelWidget.applyChangesToConfiguration();
182
		super.doRun(monitor, projectID, bsId);
183
		try {
184
			ServiceModelManager.getInstance().saveModelConfiguration();
185
		} catch (IOException e) {
186
			UIPlugin.log(e);
187
		}
201
	}
188
	}
189
190
	
191
	private IServiceConfiguration getConfig(IProject project) {
192
		IServiceConfiguration config = projectConfigs.get(project);
193
		if(config == null) {
194
			config = ServiceModelManager.getInstance().newServiceConfiguration(project.getName());
195
			projectConfigs.put(project, config);
196
		}
197
		return config;
198
	}
199
	
200
	
201
	private void changeProject(IProject project) {
202
		IServiceConfiguration config = getConfig(project);
203
    	fServiceModelWidget.applyChangesToConfiguration();
204
    	fServiceModelWidget.setServiceConfiguration(config);
205
    	remoteServices.setText(MessageFormat.format(Messages.getString("WizardProjectConversion.servicesTableForProjectLabel"), new Object[] {project.getName()}));  //$NON-NLS-1$
206
    	setPageComplete(true);
207
	}
208
	
209
	
210
	
211
212
	private void configureServicesForRemoteProject(IProject project) throws InvocationTargetException, InterruptedException {
213
		ServiceModelManager.getInstance().addConfiguration(project, getConfig(project));
214
	}
215
	
216
217
202
}
218
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/RDTMainWizardPage.java (-71 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM - Initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.rdt.ui.wizards;
12
13
import java.util.Iterator;
14
import java.util.LinkedList;
15
import java.util.List;
16
17
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
18
import org.eclipse.cdt.ui.wizards.CDTMainWizardPage;
19
import org.eclipse.cdt.ui.wizards.EntryDescriptor;
20
import org.eclipse.jface.wizard.IWizardPage;
21
import org.eclipse.ptp.internal.rdt.ui.RDTHelpContextIds;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.ui.PlatformUI;
25
26
/**
27
 * Main page of the RDT wizard, which filters out local project types.
28
 * 
29
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
30
 * part of a work in progress. There is no guarantee that this API will work or
31
 * that it will remain the same. Please do not use this API without consulting
32
 * with the RDT team.
33
 * @author crecoskie
34
 *
35
 */
36
public class RDTMainWizardPage extends CDTMainWizardPage {
37
38
	public RDTMainWizardPage(String pageName) {
39
		super(pageName);
40
		
41
		// default to view all toolchains
42
		CDTPrefUtil.setBool(CDTPrefUtil.KEY_NOSUPP, true);
43
	}
44
45
	/* (non-Javadoc)
46
	 * @see org.eclipse.cdt.ui.wizards.IWizardItemsListListener#filterItems(java.util.List)
47
	 */
48
	@SuppressWarnings("unchecked")
49
	public List filterItems(List items) {
50
		/// iterate through the list, removing entry descriptors we don't care about
51
		Iterator iterator = items.iterator();
52
		
53
		List<EntryDescriptor> filteredList = new LinkedList<EntryDescriptor>();
54
		
55
		while(iterator.hasNext()) {
56
			EntryDescriptor ed = (EntryDescriptor) iterator.next();
57
			if(ed.getId().startsWith("org.eclipse.ptp.rdt")) {  // both the category and the template start with this //$NON-NLS-1$
58
				filteredList.add(ed);
59
			}
60
		}
61
		
62
		return filteredList;
63
	}
64
	
65
	public void createControl(Composite parent){
66
		super.createControl(parent);
67
		Shell shell = getContainer().getShell(); //if not created on the shell, will not display properly
68
		PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, RDTHelpContextIds.CREATING_A_REMOTE_PROJECT);
69
	}
70
71
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/RemoteCIndexServiceProviderConfigurer.java (-36 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM - Initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.rdt.ui.wizards;
12
13
import org.eclipse.jface.dialogs.Dialog;
14
import org.eclipse.ptp.services.core.IServiceProvider;
15
import org.eclipse.ptp.services.ui.IServiceProviderConfiguration;
16
import org.eclipse.swt.widgets.Shell;
17
18
/**
19
 * Provides configuration UI for the RemoteCIndexServiceProvider by allowing an RSE
20
 * host to be selected.
21
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
22
 * part of a work in progress. There is no guarantee that this API will work or
23
 * that it will remain the same. Please do not use this API without consulting
24
 * with the RDT team.
25
 * 
26
 * @author crecoskie
27
 * @deprecated
28
 */
29
public class RemoteCIndexServiceProviderConfigurer implements IServiceProviderConfiguration {
30
31
	public void configureServiceProvider(IServiceProvider provider, Shell parentShell) {
32
		Dialog configDialog =  new HostSelectionDialog(provider, parentShell);
33
		configDialog.open();
34
	}
35
36
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/ServiceModelWizardPage.java (-24 / +236 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ptp.rdt.ui.wizards;
11
package org.eclipse.ptp.rdt.ui.wizards;
12
12
13
import java.util.HashSet;
13
import java.util.LinkedHashSet;
14
import java.util.LinkedHashSet;
14
import java.util.Set;
15
import java.util.Set;
15
16
Lines 17-36 Link Here
17
import org.eclipse.cdt.core.CProjectNature;
18
import org.eclipse.cdt.core.CProjectNature;
18
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPage;
19
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPage;
19
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
20
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
20
import org.eclipse.cdt.ui.wizards.CDTMainWizardPage;
21
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.jface.wizard.IWizardPage;
22
import org.eclipse.jface.wizard.IWizardPage;
23
import org.eclipse.ptp.internal.rdt.ui.RDTHelpContextIds;
23
import org.eclipse.ptp.internal.rdt.ui.RSEUtils;
24
import org.eclipse.ptp.rdt.core.services.IRDTServiceConstants;
24
import org.eclipse.ptp.rdt.ui.messages.Messages;
25
import org.eclipse.ptp.rdt.ui.messages.Messages;
26
import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteBuildServiceProvider;
27
import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteCIndexServiceProvider;
28
import org.eclipse.ptp.remote.core.IRemoteConnection;
29
import org.eclipse.ptp.remote.core.IRemoteServices;
25
import org.eclipse.ptp.services.core.IService;
30
import org.eclipse.ptp.services.core.IService;
26
import org.eclipse.ptp.services.core.IServiceConfiguration;
31
import org.eclipse.ptp.services.core.IServiceConfiguration;
32
import org.eclipse.ptp.services.core.IServiceModelManager;
33
import org.eclipse.ptp.services.core.IServiceProviderDescriptor;
27
import org.eclipse.ptp.services.core.ServiceModelManager;
34
import org.eclipse.ptp.services.core.ServiceModelManager;
28
import org.eclipse.ptp.services.ui.widgets.NewServiceModelWidget;
35
import org.eclipse.ptp.services.ui.widgets.NewServiceModelWidgetDialog;
36
import org.eclipse.rse.connectorservice.dstore.DStoreConnectorService;
37
import org.eclipse.rse.core.model.IHost;
38
import org.eclipse.rse.core.subsystems.IConnectorService;
29
import org.eclipse.swt.SWT;
39
import org.eclipse.swt.SWT;
40
import org.eclipse.swt.events.SelectionAdapter;
41
import org.eclipse.swt.events.SelectionEvent;
30
import org.eclipse.swt.graphics.Image;
42
import org.eclipse.swt.graphics.Image;
43
import org.eclipse.swt.layout.GridData;
44
import org.eclipse.swt.layout.GridLayout;
45
import org.eclipse.swt.widgets.Button;
46
import org.eclipse.swt.widgets.Combo;
31
import org.eclipse.swt.widgets.Composite;
47
import org.eclipse.swt.widgets.Composite;
32
import org.eclipse.swt.widgets.Control;
48
import org.eclipse.swt.widgets.Control;
33
import org.eclipse.ui.PlatformUI;
49
import org.eclipse.swt.widgets.Label;
50
import org.eclipse.swt.widgets.Text;
34
51
35
/**
52
/**
36
 * 
53
 * 
Lines 39-45 Link Here
39
 * that it will remain the same. Please do not use this API without consulting
56
 * that it will remain the same. Please do not use this API without consulting
40
 * with the RDT team.
57
 * with the RDT team.
41
 * 
58
 * 
42
 * @author crecoskie
43
 *
59
 *
44
 */
60
 */
45
public class ServiceModelWizardPage extends MBSCustomPage {
61
public class ServiceModelWizardPage extends MBSCustomPage {
Lines 47-66 Link Here
47
	public static final String SERVICE_MODEL_WIZARD_PAGE_ID = "org.eclipse.ptp.rdt.ui.serviceModelWizardPage"; //$NON-NLS-1$
63
	public static final String SERVICE_MODEL_WIZARD_PAGE_ID = "org.eclipse.ptp.rdt.ui.serviceModelWizardPage"; //$NON-NLS-1$
48
	public static final String DEFAULT_CONFIG = Messages.getString("ConfigureRemoteServices.0"); //$NON-NLS-1$
64
	public static final String DEFAULT_CONFIG = Messages.getString("ConfigureRemoteServices.0"); //$NON-NLS-1$
49
	
65
	
50
	public static final String SERVICE_MODEL_WIDGET_PROPERTY = "org.eclipse.ptp.rdt.ui.ServiceModelWizardPage.serviceModelWidget"; //$NON-NLS-1$
66
	public static final String CONFIG_PROPERTY = "org.eclipse.ptp.rdt.ui.ServiceModelWizardPage.serviceConfig"; //$NON-NLS-1$
51
67
52
	boolean fbVisited;
68
	boolean fbVisited;
53
	private String fTitle;
69
	private String fTitle;
54
	private String fDescription;
70
	private String fDescription;
55
	private ImageDescriptor fImageDescriptor;
71
	private ImageDescriptor fImageDescriptor;
56
	private Image fImage;
72
	private Image fImage;
57
	private Control fCanvas;
73
	private IServiceConfiguration fNewConfig;
58
	private IServiceConfiguration fConfig;
74
	private Control pageControl;
59
	private NewServiceModelWidget fModelWidget;
75
	
76
	private Text newConfigNameText;
77
	private Combo configCombo;
78
	
60
	
79
	
61
62
	public ServiceModelWizardPage(String pageID) {
80
	public ServiceModelWizardPage(String pageID) {
63
		super(pageID);
81
		super(pageID);
82
		
83
64
	}
84
	}
65
85
66
	/**
86
	/**
Lines 81-86 Link Here
81
		return allApplicableServices;
101
		return allApplicableServices;
82
	}
102
	}
83
	
103
	
104
	
84
	/**
105
	/**
85
	 * 
106
	 * 
86
	 */
107
	 */
Lines 105-131 Link Here
105
	/* (non-Javadoc)
126
	/* (non-Javadoc)
106
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
127
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
107
	 */
128
	 */
108
	public void createControl(Composite parent) {
129
	public void createControl(final Composite parent) {
109
		fCanvas = parent; // TODO
130
		Composite comp = new Composite(parent, SWT.NONE);
110
		fModelWidget = new NewServiceModelWidget(parent, SWT.NONE);
131
		comp.setLayout(new GridLayout(1, false));
132
		pageControl = comp;
133
134
		final Button newConfigButton = new Button(comp, SWT.RADIO);
135
		newConfigButton.setText("Create a new Service Configuration for the project"); //$NON-NLS-1$
136
		newConfigButton.setSelection(true);
137
		newConfigButton.setLayoutData(new GridData());
138
		
139
		Composite newComp = new Composite(comp, SWT.NONE);
140
		newComp.setLayoutData(new GridData());
141
		GridLayout layout = new GridLayout(1, false);
142
		layout.marginLeft = 10;
143
		newComp.setLayout(layout);
144
		
145
		final Label label1 = new Label(newComp, SWT.NONE);
146
		label1.setText("Service Configuration Name:"); //$NON-NLS-1$
147
		label1.setLayoutData(new GridData());
148
		
149
		newConfigNameText = new Text(newComp, SWT.BORDER);
150
		newConfigNameText.setText(getDefaultConfigName());
151
		GridData data = new GridData();
152
		data.widthHint = 150;
153
		newConfigNameText.setLayoutData(data);
154
		
155
		new Label(comp, SWT.NONE);
156
		
157
		Button existingConfigButton = new Button(comp, SWT.RADIO);
158
		existingConfigButton.setText("Add the project to an existing Service Configuration"); //$NON-NLS-1$
159
		existingConfigButton.setLayoutData(new GridData());
160
		
161
		Composite existingComp = new Composite(comp, SWT.NONE);
162
		layout = new GridLayout(1, false);
163
		layout.marginLeft = 10;
164
		existingComp.setLayoutData(new GridData());
165
		existingComp.setLayout(layout);
166
		
167
		final Label label2 = new Label(existingComp, SWT.NONE);
168
		label2.setText("Service Configuration:"); //$NON-NLS-1$
169
		label2.setLayoutData(new GridData());
111
		
170
		
112
		MBSCustomPageManager.addPageProperty(pageID, SERVICE_MODEL_WIDGET_PROPERTY, fModelWidget);
171
		configCombo = new Combo(existingComp, SWT.NONE);
172
		data = new GridData();
173
		data.widthHint = 150;
174
		configCombo.setLayoutData(data);
175
		label2.setEnabled(false);
176
		configCombo.setEnabled(false);
177
		
178
		// if there are no existing configurations, then you can't choose one
179
		if(!populateCombo()) {
180
			existingConfigButton.setEnabled(false);
181
		}
182
183
		updateConfigPageProperty(true);
184
		
185
		newConfigButton.addSelectionListener(new SelectionAdapter() {
186
			@Override public void widgetSelected(SelectionEvent e) {
187
				label1.setEnabled(true);
188
				newConfigNameText.setEnabled(true);
189
				label2.setEnabled(false);
190
				configCombo.setEnabled(false);
191
				updateConfigPageProperty(true);
192
			}
193
		});
194
		
195
		existingConfigButton.addSelectionListener(new SelectionAdapter() {
196
			@Override public void widgetSelected(SelectionEvent e) {
197
				label1.setEnabled(false);
198
				newConfigNameText.setEnabled(false);
199
				label2.setEnabled(true);
200
				configCombo.setEnabled(true);
201
				updateConfigPageProperty(false);
202
			}
203
		});
204
		
205
		configCombo.addSelectionListener(new SelectionAdapter() {
206
			@Override public void widgetSelected(SelectionEvent e) {
207
				updateConfigPageProperty(false);
208
			}
209
			
210
		});
211
		
212
		Button advanced = new Button(comp, SWT.PUSH);
213
		data = new GridData();
214
		data.horizontalAlignment = SWT.END;
215
		data.grabExcessHorizontalSpace = true;
216
		data.grabExcessVerticalSpace = true;
217
		data.verticalAlignment = SWT.END;
218
		
219
		advanced.setText("Advanced Settings..."); //$NON-NLS-1$
220
		advanced.setLayoutData(data);
221
		
222
		advanced.addSelectionListener(new SelectionAdapter() {
223
			public void widgetSelected(SelectionEvent e) {
224
				NewServiceModelWidgetDialog dialog = new NewServiceModelWidgetDialog(parent.getShell());
225
				IServiceConfiguration config = newConfigButton.getSelection() ? getNewConfiguration() : getExistingConfiguration();
226
				dialog.setText("Editing Service Configuration: " + config.getName()); //$NON-NLS-1$
227
				dialog.open(config);
228
			}
229
		});
230
231
232
//		Control control = fModelWidget.getParent().getShell(); //get the shell or doesn't display help correctly
233
//		PlatformUI.getWorkbench().getHelpSystem().setHelp(control,RDTHelpContextIds.SERVICE_MODEL_WIZARD);
234
	}
235
	
236
	
237
	private void updateConfigPageProperty(boolean useNew) {
238
		IServiceConfiguration config = useNew ? getNewConfiguration() : getExistingConfiguration();
239
		MBSCustomPageManager.addPageProperty(
240
				SERVICE_MODEL_WIZARD_PAGE_ID, CONFIG_PROPERTY, config);
113
		
241
		
114
		String configName = DEFAULT_CONFIG;
242
	}
243
	
244
	private boolean populateCombo() {
245
		IServiceModelManager smm = ServiceModelManager.getInstance();
246
		Set<IServiceConfiguration> configSet = smm.getConfigurations();
247
		IServiceConfiguration[] configs = configSet.toArray(new IServiceConfiguration[configSet.size()]);
248
		for(IServiceConfiguration config : configs) {
249
			configCombo.add(config.getName());
250
		}
251
		if(!configSet.isEmpty()) {
252
			configCombo.select(0);
253
		}
254
			
255
		configCombo.setData(configs);
256
		return !configSet.isEmpty();
257
	}
258
	
259
	
260
	
261
	
262
	
263
	private String getDefaultConfigName() {
264
		String candidateName = DEFAULT_CONFIG;
115
		IWizardPage page = getWizard().getStartingPage();
265
		IWizardPage page = getWizard().getStartingPage();
116
		if(page instanceof CDTMainWizardPage) {
266
		if(page instanceof NewRemoteProjectCreationPage) {
117
			CDTMainWizardPage cdtPage = (CDTMainWizardPage) page;
267
			NewRemoteProjectCreationPage cdtPage = (NewRemoteProjectCreationPage) page;
118
			configName = cdtPage.getProjectName();
268
			candidateName = cdtPage.getRemoteConnection().getName();
119
		}
269
		}
120
		
270
		
121
		fConfig = ServiceModelManager.getInstance().newServiceConfiguration(configName);
271
		Set<IServiceConfiguration> configs = ServiceModelManager.getInstance().getConfigurations();
272
		Set<String> existingNames = new HashSet<String>();
273
		for(IServiceConfiguration config : configs) {
274
			existingNames.add(config.getName());
275
		}
122
		
276
		
123
		fModelWidget.setServiceConfiguration(fConfig);
277
		int i = 2;
278
		String newConfigName = candidateName;
279
		while(existingNames.contains(newConfigName)) {
280
			newConfigName = candidateName + " (" + (i++) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
281
		}
124
		
282
		
125
		Control control = fModelWidget.getParent().getShell(); //get the shell or doesn't display help correctly
283
		return newConfigName;
126
		PlatformUI.getWorkbench().getHelpSystem().setHelp(control,RDTHelpContextIds.SERVICE_MODEL_WIZARD);
127
	}
284
	}
128
285
286
	
287
	private IServiceConfiguration getExistingConfiguration() {
288
		return ((IServiceConfiguration[])configCombo.getData())[configCombo.getSelectionIndex()];
289
	}
290
	
291
	/**
292
	 * Creates a new configuration with the RDT defaults.
293
	 */
294
	private IServiceConfiguration getNewConfiguration() {
295
		if(fNewConfig == null) {
296
			String configName = newConfigNameText.getText(); // TODO error check
297
			
298
			IServiceModelManager smm = ServiceModelManager.getInstance();
299
			fNewConfig = smm.newServiceConfiguration(configName);
300
			
301
			IWizardPage page = getWizard().getStartingPage();
302
			if(page instanceof NewRemoteProjectCreationPage) {
303
				NewRemoteProjectCreationPage cdtPage = (NewRemoteProjectCreationPage) page;
304
				IRemoteServices remoteServices = cdtPage.getRemoteServices();
305
				IRemoteConnection remoteConnection = cdtPage.getRemoteConnection();
306
				
307
				IService buildService = smm.getService(IRDTServiceConstants.SERVICE_BUILD);
308
				IServiceProviderDescriptor descriptor = buildService.getProviderDescriptor(RemoteBuildServiceProvider.ID);
309
				RemoteBuildServiceProvider rbsp = (RemoteBuildServiceProvider)smm.getServiceProvider(descriptor);
310
				rbsp.setRemoteToolsProviderID(remoteServices.getId());
311
				rbsp.setRemoteToolsConnection(remoteConnection);
312
				fNewConfig.setServiceProvider(buildService, rbsp);
313
			
314
				if(remoteServices.getId().equals("org.eclipse.ptp.remote.RSERemoteServices") ) { //$NON-NLS-1$
315
					IService indexingService = smm.getService(IRDTServiceConstants.SERVICE_C_INDEX);
316
					descriptor = indexingService.getProviderDescriptor(RemoteCIndexServiceProvider.ID);
317
					RemoteCIndexServiceProvider rcisp = (RemoteCIndexServiceProvider) smm.getServiceProvider(descriptor);
318
					
319
					String hostName = remoteConnection.getAddress();
320
					IHost host = RSEUtils.getConnection(hostName);
321
					String configPath = RSEUtils.getDefaultConfigDirectory(host);
322
					
323
					rcisp.setConnection(host, getDStoreConnectorService(host));
324
					rcisp.setIndexLocation(configPath);
325
					rcisp.setConfigured(true);
326
					fNewConfig.setServiceProvider(indexingService, rcisp);
327
				}
328
			}
329
		}
330
		
331
		return fNewConfig;
332
	}
333
	
334
	private IConnectorService getDStoreConnectorService(IHost host) {
335
		for(IConnectorService cs : host.getConnectorServices()) {
336
			if(cs instanceof DStoreConnectorService)
337
				return cs;
338
		}
339
		return null;
340
	}
341
	
129
	/* (non-Javadoc)
342
	/* (non-Javadoc)
130
	 * @see org.eclipse.jface.dialogs.IDialogPage#dispose()
343
	 * @see org.eclipse.jface.dialogs.IDialogPage#dispose()
131
	 */
344
	 */
Lines 138-144 Link Here
138
	 * @see org.eclipse.jface.dialogs.IDialogPage#getControl()
351
	 * @see org.eclipse.jface.dialogs.IDialogPage#getControl()
139
	 */
352
	 */
140
	public Control getControl() {
353
	public Control getControl() {
141
		return fModelWidget;
354
		return pageControl;
142
	}
355
	}
143
356
144
	/* (non-Javadoc)
357
	/* (non-Javadoc)
Lines 227-233 Link Here
227
		if(visible) {
440
		if(visible) {
228
			fbVisited = true;
441
			fbVisited = true;
229
		}
442
		}
230
		fCanvas.setVisible(visible);
231
	}
443
	}
232
444
233
445
(-)src/org/eclipse/ptp/rdt/ui/wizards/RemoteServicesProviderSelectionDialog.java (-270 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM - Initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.rdt.ui.wizards;
12
13
import java.util.HashMap;
14
import java.util.Map;
15
16
import org.eclipse.jface.dialogs.Dialog;
17
import org.eclipse.jface.dialogs.IDialogConstants;
18
import org.eclipse.ptp.rdt.ui.messages.Messages;
19
import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteBuildServiceProvider;
20
import org.eclipse.ptp.remote.core.IRemoteConnection;
21
import org.eclipse.ptp.remote.core.IRemoteServices;
22
import org.eclipse.ptp.remote.core.PTPRemoteCorePlugin;
23
import org.eclipse.ptp.remote.ui.IRemoteUIConnectionManager;
24
import org.eclipse.ptp.remote.ui.PTPRemoteUIPlugin;
25
import org.eclipse.ptp.services.core.IServiceProvider;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.events.SelectionEvent;
28
import org.eclipse.swt.events.SelectionListener;
29
import org.eclipse.swt.graphics.Point;
30
import org.eclipse.swt.layout.GridData;
31
import org.eclipse.swt.layout.GridLayout;
32
import org.eclipse.swt.widgets.Button;
33
import org.eclipse.swt.widgets.Combo;
34
import org.eclipse.swt.widgets.Composite;
35
import org.eclipse.swt.widgets.Control;
36
import org.eclipse.swt.widgets.Label;
37
import org.eclipse.swt.widgets.Shell;
38
39
/**
40
 * Allows the user to select a provider of Remote Services for a RemoteBuildServiceProvider.
41
 * 
42
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
43
 * part of a work in progress. There is no guarantee that this API will work or
44
 * that it will remain the same. Please do not use this API without consulting
45
 * with the RDT team.
46
 * 
47
 * @author crecoskie
48
 * @see org.eclipse.ptp.rdt.ui.serviceproviders.RemoteBuildServiceProvider
49
 */
50
public class RemoteServicesProviderSelectionDialog extends Dialog {
51
52
	
53
	private RemoteBuildServiceProvider fProvider;
54
	
55
	private Map<Integer, IRemoteServices> fComboIndexToRemoteServicesProviderMap = new HashMap<Integer, IRemoteServices>();
56
	
57
	private IRemoteServices fSelectedProvider;
58
59
	private Map<Integer, IRemoteConnection> fComboIndexToRemoteConnectionMap = new HashMap<Integer, IRemoteConnection>();
60
61
	private IRemoteConnection fSelectedConnection;
62
63
	public RemoteServicesProviderSelectionDialog(IServiceProvider provider, Shell parentShell) {
64
		super(parentShell);
65
		
66
		if(provider instanceof RemoteBuildServiceProvider)
67
			fProvider = (RemoteBuildServiceProvider) provider;
68
		else
69
			throw new IllegalArgumentException(); // should never happen
70
	}
71
	
72
    /* (non-Javadoc)
73
     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
74
     */
75
    protected Control createDialogArea(Composite parent) {
76
        Composite container = (Composite) super.createDialogArea(parent);
77
78
        getShell().setText(Messages.getString("RemoteServicesProviderSelectionDialog_0")); //$NON-NLS-1$
79
		
80
        GridLayout layout = new GridLayout();
81
        layout.numColumns = 5;
82
        container.setLayout(layout);
83
        
84
        // Label for "Provider:"
85
        Label providerLabel = new Label(container, SWT.LEFT);
86
        providerLabel.setText(Messages.getString("RemoteServicesProviderSelectionDialog_1")); //$NON-NLS-1$
87
        
88
        // combo for providers
89
        final Combo providerCombo = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
90
        // set layout to grab horizontal space
91
        providerCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
92
        
93
        //attempt to restore settings from saved state
94
        IRemoteServices providerSelected = fProvider.getRemoteServices(); 
95
        
96
        // populate the combo with a list of providers
97
        IRemoteServices[] providers = PTPRemoteCorePlugin.getDefault().getAllRemoteServices();
98
        int toSelect = 0;
99
        
100
        for(int k = 0; k < providers.length; k++) {
101
        	providerCombo.add(providers[k].getName(), k);
102
        	fComboIndexToRemoteServicesProviderMap.put(k, providers[k]);
103
        	
104
        	if (providerSelected != null && providerSelected.getName().compareTo(providers[k].getName()) == 0) {
105
        		toSelect = k;
106
        	}
107
        }
108
        
109
        // set selected host to be the first one if we're not restoring from settings
110
        providerCombo.select(toSelect);
111
        fSelectedProvider = fComboIndexToRemoteServicesProviderMap.get(toSelect);
112
            
113
        // connection combo
114
        // Label for "Connection:"
115
        Label connectionLabel = new Label(container, SWT.LEFT);
116
        connectionLabel.setText(Messages.getString("RemoteServicesProviderSelectionDialog.0")); //$NON-NLS-1$
117
        
118
        // combo for providers
119
        final Combo connectionCombo = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
120
        // set layout to grab horizontal space
121
        connectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
122
        
123
        // populate the combo with a list of providers
124
        populateConnectionCombo(connectionCombo);
125
           
126
        // new connection button
127
        final Button newConnectionButton = new Button(container, SWT.PUSH);
128
        newConnectionButton.setText(Messages.getString("RemoteServicesProviderSelectionDialog.1")); //$NON-NLS-1$
129
        updateNewConnectionButtonEnabled(newConnectionButton);
130
        
131
        
132
        newConnectionButton.addSelectionListener(new SelectionListener() {
133
134
			public void widgetDefaultSelected(SelectionEvent e) {
135
				widgetSelected(e);
136
				
137
			}
138
139
			public void widgetSelected(SelectionEvent e) {
140
				
141
				IRemoteUIConnectionManager connectionManager = getUIConnectionManager();
142
				if(connectionManager != null) {
143
					connectionManager.newConnection(getShell());
144
				}
145
				
146
				// refresh list of connections
147
				populateConnectionCombo(connectionCombo);
148
				
149
			}
150
        	
151
        });
152
        
153
        providerCombo.addSelectionListener(new SelectionListener() {
154
155
			public void widgetDefaultSelected(SelectionEvent e) {
156
				widgetSelected(e);
157
				
158
			}
159
160
			public void widgetSelected(SelectionEvent e) {
161
				int selectionIndex = providerCombo.getSelectionIndex();
162
				fSelectedProvider = fComboIndexToRemoteServicesProviderMap.get(selectionIndex);
163
				
164
				populateConnectionCombo(connectionCombo);
165
				updateNewConnectionButtonEnabled(newConnectionButton);
166
				
167
			}
168
        	
169
        });
170
        
171
        connectionCombo.addSelectionListener(new SelectionListener() {
172
173
			public void widgetDefaultSelected(SelectionEvent e) {
174
				widgetSelected(e);
175
				
176
			}
177
178
			public void widgetSelected(SelectionEvent e) {
179
				int selectionIndex = connectionCombo.getSelectionIndex();
180
				fSelectedConnection = fComboIndexToRemoteConnectionMap.get(selectionIndex);
181
				updateNewConnectionButtonEnabled(newConnectionButton);
182
			}
183
        	
184
        });
185
        
186
        
187
        return container;
188
    }
189
    
190
    
191
    private void updateNewConnectionButtonEnabled(Button button) {
192
    	IRemoteUIConnectionManager connectionManager = getUIConnectionManager();
193
    	button.setEnabled(connectionManager != null);  	
194
    }
195
196
	/**
197
	 * @return
198
	 */
199
	private IRemoteUIConnectionManager getUIConnectionManager() {
200
		IRemoteUIConnectionManager connectionManager = PTPRemoteUIPlugin.getDefault().getRemoteUIServices(fSelectedProvider)
201
				.getUIConnectionManager();
202
		return connectionManager;
203
	}
204
205
	/**
206
	 * @param connectionCombo
207
	 */
208
	private void populateConnectionCombo(final Combo connectionCombo) {
209
		connectionCombo.removeAll();
210
		
211
		//attempt to restore settings from saved state
212
        IRemoteConnection connectionSelected = fProvider.getConnection();
213
		
214
		IRemoteConnection[] connections = fSelectedProvider.getConnectionManager().getConnections();
215
		int toSelect = 0;
216
        
217
        for(int k = 0; k < connections.length; k++) {
218
        	connectionCombo.add(connections[k].getName(), k);
219
        	fComboIndexToRemoteConnectionMap .put(k, connections[k]);
220
        	
221
        	if (connectionSelected != null && connectionSelected.getName().compareTo(connections[k].getName()) == 0) {
222
        		toSelect = k;
223
        	}
224
        }
225
        
226
        // set selected connection to be the first one if we're not restoring from settings
227
        connectionCombo.select(toSelect);
228
        fSelectedConnection = fComboIndexToRemoteConnectionMap.get(toSelect);
229
	}
230
    
231
    /* (non-Javadoc)
232
     * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
233
     */
234
    protected void createButtonsForButtonBar(Composite parent) {
235
        createButton(parent, IDialogConstants.OK_ID,
236
            IDialogConstants.OK_LABEL, true);
237
        createButton(parent, IDialogConstants.CANCEL_ID,
238
            IDialogConstants.CANCEL_LABEL, false);
239
    }
240
    
241
    /* (non-Javadoc)
242
	 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
243
	 */
244
	@Override
245
	protected boolean isResizable() {
246
		return true;
247
	}
248
249
	/* (non-Javadoc)
250
     * @see org.eclipse.jface.dialogs.Dialog#getInitialSize()
251
     */
252
    protected Point getInitialSize() {
253
        return new Point(750, 125);
254
    }
255
256
	/* (non-Javadoc)
257
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
258
	 */
259
	@Override
260
	protected void okPressed() {
261
		super.okPressed();
262
		
263
		// set the provider
264
		fProvider.setRemoteToolsProviderID(fSelectedProvider.getId());
265
		fProvider.setRemoteToolsConnection(fSelectedConnection);
266
267
	}
268
269
    
270
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/NewRemoteCppProjectWizard.java (-96 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM - Initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.rdt.ui.wizards;
12
13
import org.eclipse.cdt.core.CCProjectNature;
14
import org.eclipse.cdt.core.CProjectNature;
15
import org.eclipse.cdt.ui.CUIPlugin;
16
import org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard;
17
import org.eclipse.cdt.ui.wizards.CDTMainWizardPage;
18
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.NullProgressMonitor;
21
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.ptp.internal.rdt.ui.RDTPluginImages;
23
import org.eclipse.ptp.rdt.core.resources.RemoteNature;
24
import org.eclipse.ptp.rdt.ui.messages.Messages;
25
import org.eclipse.swt.widgets.Composite;
26
27
/**
28
 * A wizard for creating new Remote C/C++ Projects
29
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
30
 * part of a work in progress. There is no guarantee that this API will work or
31
 * that it will remain the same. Please do not use this API without consulting
32
 * with the RDT team.
33
 * 
34
 * @author crecoskie
35
 *
36
 */
37
public class NewRemoteCppProjectWizard extends CDTCommonProjectWizard {
38
	private static final String PREFIX= "CProjectWizard"; //$NON-NLS-1$
39
	private static final String wz_title = Messages.getString("NewRemoteCppProjectWizard_0"); //$NON-NLS-1$
40
	private static final String wz_desc = Messages.getString("NewRemoteCppProjectWizard_1"); //$NON-NLS-1$
41
	
42
	/**
43
	 * 
44
	 */
45
	public NewRemoteCppProjectWizard() {
46
		
47
		super(wz_title, wz_desc);
48
	}
49
50
51
	/* (non-Javadoc)
52
	 * @see org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard#continueCreation(org.eclipse.core.resources.IProject)
53
	 */
54
	
55
	@Override
56
	protected IProject continueCreation(IProject prj) {
57
		try {
58
			CProjectNature.addCNature(prj, new NullProgressMonitor());
59
			CCProjectNature.addCCNature(prj, new NullProgressMonitor());
60
			RemoteNature.addRemoteNature(prj, new NullProgressMonitor());
61
		} catch (CoreException e) {}
62
		return prj;
63
	}
64
65
	/* (non-Javadoc)
66
	 * @see org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard#getNatures()
67
	 */
68
	@Override
69
	public String[] getNatures() {
70
		return new String[] { CProjectNature.C_NATURE_ID, CCProjectNature.CC_NATURE_ID, RemoteNature.REMOTE_NATURE_ID};
71
	}
72
73
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.ui.wizards.newresource.BasicNewResourceWizard#initializeDefaultPageImageDescriptor()
76
	 */
77
	@Override
78
	protected void initializeDefaultPageImageDescriptor() {
79
		setDefaultPageImageDescriptor(RDTPluginImages.DESC_WIZBAN_NEW_REMOTE_C_PROJ);
80
	}
81
82
83
	/* (non-Javadoc)
84
	 * @see org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard#addPages()
85
	 */
86
	@Override
87
	public void addPages() {
88
		fMainPage= new RDTMainWizardPage(CUIPlugin.getResourceString(PREFIX));
89
		fMainPage.setTitle(wz_title);
90
		fMainPage.setDescription(wz_desc);
91
		addPage(fMainPage);
92
	}
93
	
94
	
95
96
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/HostSelectionDialog.java (-212 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM - Initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.rdt.ui.wizards;
12
13
import java.util.HashMap;
14
import java.util.Map;
15
16
import org.eclipse.jface.dialogs.Dialog;
17
import org.eclipse.jface.dialogs.IDialogConstants;
18
import org.eclipse.jface.wizard.IWizard;
19
import org.eclipse.jface.wizard.WizardDialog;
20
import org.eclipse.ptp.rdt.ui.messages.Messages;
21
import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteCIndexServiceProvider;
22
import org.eclipse.ptp.services.core.IServiceProvider;
23
import org.eclipse.rse.connectorservice.dstore.DStoreConnectorService;
24
import org.eclipse.rse.core.model.IHost;
25
import org.eclipse.rse.core.model.SystemStartHere;
26
import org.eclipse.rse.core.subsystems.IConnectorService;
27
import org.eclipse.rse.ui.wizards.newconnection.RSEDefaultNewConnectionWizard;
28
import org.eclipse.rse.ui.wizards.newconnection.RSEMainNewConnectionWizard;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.events.SelectionAdapter;
31
import org.eclipse.swt.events.SelectionEvent;
32
import org.eclipse.swt.events.SelectionListener;
33
import org.eclipse.swt.graphics.Point;
34
import org.eclipse.swt.layout.GridData;
35
import org.eclipse.swt.layout.GridLayout;
36
import org.eclipse.swt.widgets.Button;
37
import org.eclipse.swt.widgets.Combo;
38
import org.eclipse.swt.widgets.Composite;
39
import org.eclipse.swt.widgets.Control;
40
import org.eclipse.swt.widgets.Label;
41
import org.eclipse.swt.widgets.Shell;
42
43
/**
44
 * Provides a dialog which allows you to select an RSE host for the RemoteCIndexServiceProvider.
45
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
46
 * part of a work in progress. There is no guarantee that this API will work or
47
 * that it will remain the same. Please do not use this API without consulting
48
 * with the RDT team.
49
 * 
50
 * @author crecoskie
51
 *
52
 */
53
public class HostSelectionDialog extends Dialog {
54
	
55
	private RemoteCIndexServiceProvider fProvider;
56
	
57
	private Map<Integer, IHost> fHostComboIndexToHostMap = new HashMap<Integer, IHost>();
58
	
59
	private IHost fSelectedHost;
60
	private String configPath;
61
62
	public HostSelectionDialog(IServiceProvider provider, Shell parentShell) {
63
		super(parentShell);
64
		
65
		if(provider instanceof RemoteCIndexServiceProvider)
66
			fProvider = (RemoteCIndexServiceProvider) provider;
67
		else
68
			throw new IllegalArgumentException(); // should never happen
69
	}
70
	
71
    /* (non-Javadoc)
72
     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
73
     */
74
    protected Control createDialogArea(Composite parent) {
75
        Composite container = (Composite) super.createDialogArea(parent);
76
        getShell().setText(Messages.getString("HostSelectionDialog.1")); //$NON-NLS-1$
77
		
78
        GridLayout layout = new GridLayout();
79
        layout.numColumns = 3;
80
        container.setLayout(layout);
81
        
82
        // Label for "Host:"
83
        Label hostLabel = new Label(container, SWT.LEFT);
84
        hostLabel.setText(Messages.getString("HostSelectionDialog_0")); //$NON-NLS-1$
85
        
86
        // combo for hosts
87
        final Combo hostCombo = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
88
        hostCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); // set layout to grab horizontal space
89
        
90
        //attempt to restore settings from saved state
91
        IHost hostSelected = fProvider.getHost();
92
        
93
        // populate the combo with a list of hosts
94
        IHost[] hosts = SystemStartHere.getConnections();
95
        int toSelect = 0;
96
        
97
        for(int k = 0; k < hosts.length; k++) {
98
        	hostCombo.add(hosts[k].getAliasName(), k);
99
        	fHostComboIndexToHostMap.put(k, hosts[k]);
100
        	
101
        	if (hostSelected != null && hostSelected.getAliasName().compareTo(hosts[k].getAliasName()) == 0) {
102
        		toSelect = k;
103
        	}
104
        }
105
        
106
        // set selected host to be the first one if we're not restoring from settings
107
        hostCombo.select(toSelect);
108
        fSelectedHost = fHostComboIndexToHostMap.get(toSelect);
109
        
110
        
111
        
112
        // button for creating new connections
113
        Button newConnectionButton = new Button(container, SWT.PUSH);
114
        newConnectionButton.setText(Messages.getString("HostSelectionDialog.0")); //$NON-NLS-1$
115
        newConnectionButton.addSelectionListener(new SelectionAdapter() {
116
117
			public void widgetSelected(SelectionEvent e) {
118
				// launch the RSE New Connection Wizard
119
				RSEMainNewConnectionWizard wizard = new RSEMainNewConnectionWizard();
120
				WizardDialog wizardDialog = new WizardDialog(getShell(), wizard);
121
				wizardDialog.open();
122
				
123
				IWizard actualWizard = wizard.getSelectedWizard();
124
				if(actualWizard instanceof RSEDefaultNewConnectionWizard) {
125
					// get the new host, if any
126
					IHost host = ((RSEDefaultNewConnectionWizard)actualWizard).getCreatedHost();
127
					
128
					// add the host
129
					int index = hostCombo.getItemCount() - 1;
130
					hostCombo.add(host.getAliasName(), index);
131
		        	fHostComboIndexToHostMap.put(index, host);
132
		        	
133
		        	// select the new host
134
		        	hostCombo.select(index);
135
		            fSelectedHost = host;
136
				}
137
			}
138
        	
139
        });
140
        
141
        configPath = fProvider.getIndexLocation();
142
        if(fProvider.isConfigured() && configPath == null) // happens if the project was created before the index location feature was added
143
        	configPath = ""; //$NON-NLS-1$
144
      
145
        final IndexFileLocationWidget scopeWidget = new IndexFileLocationWidget(container, SWT.NONE, fSelectedHost, configPath);
146
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
147
        data.horizontalSpan = 3;
148
        scopeWidget.setLayoutData(data); // set layout to grab horizontal space
149
        scopeWidget.addPathListener(new IIndexFilePathChangeListener() {
150
			public void pathChanged(String newPath) {
151
				configPath = newPath;
152
			}
153
		});
154
        
155
        
156
        hostCombo.addSelectionListener(new SelectionListener() {
157
			public void widgetDefaultSelected(SelectionEvent e) {
158
				widgetSelected(e);
159
			}
160
161
			public void widgetSelected(SelectionEvent e) {
162
				int selectionIndex = hostCombo.getSelectionIndex();
163
				fSelectedHost = fHostComboIndexToHostMap.get(selectionIndex);
164
				scopeWidget.setHost(fSelectedHost);
165
			}
166
        });
167
        
168
        return container;
169
    }
170
    
171
    /* (non-Javadoc)
172
     * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
173
     */
174
    protected void createButtonsForButtonBar(Composite parent) {
175
        createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
176
        createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
177
    }
178
    
179
    /* (non-Javadoc)
180
     * @see org.eclipse.jface.dialogs.Dialog#getInitialSize()
181
     */
182
    protected Point getInitialSize() {
183
        return new Point(500,300);
184
    }
185
186
	/* (non-Javadoc)
187
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
188
	 */
189
	@Override
190
	protected void okPressed() {
191
		super.okPressed();
192
		
193
		// set the host for the service provider
194
		fProvider.setConnection(fSelectedHost, getDStoreConnectorService(fSelectedHost));
195
		fProvider.setIndexLocation(configPath);
196
		fProvider.setConfigured(true);
197
	}
198
199
	private IConnectorService getDStoreConnectorService(IHost host) {
200
		IConnectorService[] connectorServices = host.getConnectorServices();
201
		
202
		for(int k = 0; k < connectorServices.length; k++) {
203
			if(connectorServices[k] instanceof DStoreConnectorService)
204
				return connectorServices[k];
205
		}
206
		
207
		return null;
208
	}
209
210
    
211
    
212
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/ConfigureRemoteServices.java (-85 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM - Initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.rdt.ui.wizards;
12
13
import java.io.IOException;
14
import java.util.Map;
15
16
import org.eclipse.cdt.core.CCorePlugin;
17
import org.eclipse.cdt.core.model.ICProject;
18
import org.eclipse.cdt.internal.core.model.CModelManager;
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.ptp.internal.rdt.core.index.RemoteFastIndexer;
22
import org.eclipse.ptp.rdt.ui.messages.Messages;
23
import org.eclipse.ptp.services.core.IService;
24
import org.eclipse.ptp.services.core.IServiceConfiguration;
25
import org.eclipse.ptp.services.core.IServiceProvider;
26
import org.eclipse.ptp.services.core.ServiceModelManager;
27
import org.eclipse.rse.internal.connectorservice.dstore.Activator;
28
29
/**
30
 * Configure remote services for a project with the available services and service providers
31
 * 
32
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
33
 * part of a work in progress. There is no guarantee that this API will work or
34
 * that it will remain the same. Please do not use this API without consulting
35
 * with the RDT team.
36
 * 
37
 * @author vkong
38
 *
39
 */
40
public class ConfigureRemoteServices {
41
	
42
	public static String DEFAULT_CONFIG = Messages.getString("ConfigureRemoteServices.0"); //$NON-NLS-1$
43
	
44
	/**
45
	 * @throws NullPointerException if any of the parameters are null
46
	 */
47
	public static void configure(IProject project, Map<String, String> serviceIDToProviderIDMap, 
48
			Map<String, IServiceProvider> providerIDToProviderMap, IProgressMonitor monitor) {
49
		
50
		monitor.beginTask("actual Configure remote services", 100); //$NON-NLS-1$
51
		
52
		if(project == null)
53
			throw new NullPointerException();
54
				
55
		final ServiceModelManager serviceModelManager = ServiceModelManager.getInstance();
56
57
		IServiceConfiguration config = serviceModelManager.newServiceConfiguration(DEFAULT_CONFIG);
58
		
59
		int workUnit = 90/serviceIDToProviderIDMap.size();
60
		
61
		for(String serviceID : serviceIDToProviderIDMap.keySet()) {
62
			IService service = serviceModelManager.getService(serviceID);
63
			String serviceProviderID = serviceIDToProviderIDMap.get(serviceID);
64
			IServiceProvider provider = providerIDToProviderMap.get(serviceProviderID);
65
			config.setServiceProvider(service, provider);
66
			
67
			monitor.worked(workUnit);
68
69
			//have to set it as active
70
			serviceModelManager.addConfiguration(project, config);
71
			serviceModelManager.setActiveConfiguration(project, config);
72
		}
73
		
74
		try {
75
			serviceModelManager.saveModelConfiguration();
76
		} catch (IOException e) {
77
			Activator.logError(e.toString(), e);
78
		}
79
		
80
		ICProject cProject = CModelManager.getDefault().getCModel().getCProject(project);
81
		CCorePlugin.getIndexManager().setIndexerId(cProject, RemoteFastIndexer.ID);
82
		monitor.worked(10);
83
		monitor.done();		
84
	}
85
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/ServiceModelWizardPageOperation.java (-19 / +7 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ptp.rdt.ui.wizards;
11
package org.eclipse.ptp.rdt.ui.wizards;
12
12
13
import static org.eclipse.ptp.rdt.ui.wizards.ServiceModelWizardPage.SERVICE_MODEL_WIDGET_PROPERTY;
13
import static org.eclipse.ptp.rdt.ui.wizards.ServiceModelWizardPage.CONFIG_PROPERTY;
14
14
15
import java.io.IOException;
15
import java.io.IOException;
16
import java.lang.reflect.InvocationTargetException;
16
import java.lang.reflect.InvocationTargetException;
Lines 19-25 Link Here
19
import org.eclipse.cdt.core.model.ICProject;
19
import org.eclipse.cdt.core.model.ICProject;
20
import org.eclipse.cdt.internal.core.model.CModelManager;
20
import org.eclipse.cdt.internal.core.model.CModelManager;
21
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
21
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
22
import org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard;
22
import org.eclipse.cdt.ui.wizards.ICDTCommonProjectWizard;
23
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IProgressMonitor;
25
import org.eclipse.jface.operation.IRunnableWithProgress;
25
import org.eclipse.jface.operation.IRunnableWithProgress;
Lines 27-33 Link Here
27
import org.eclipse.ptp.internal.rdt.core.index.RemoteFastIndexer;
27
import org.eclipse.ptp.internal.rdt.core.index.RemoteFastIndexer;
28
import org.eclipse.ptp.services.core.IServiceConfiguration;
28
import org.eclipse.ptp.services.core.IServiceConfiguration;
29
import org.eclipse.ptp.services.core.ServiceModelManager;
29
import org.eclipse.ptp.services.core.ServiceModelManager;
30
import org.eclipse.ptp.services.ui.widgets.NewServiceModelWidget;
31
import org.eclipse.rse.internal.connectorservice.dstore.Activator;
30
import org.eclipse.rse.internal.connectorservice.dstore.Activator;
32
31
33
/**
32
/**
Lines 38-67 Link Here
38
 * that it will remain the same. Please do not use this API without consulting
37
 * that it will remain the same. Please do not use this API without consulting
39
 * with the RDT team.
38
 * with the RDT team.
40
 * 
39
 * 
41
 * @author crecoskie
42
 *
40
 *
43
 */
41
 */
44
public class ServiceModelWizardPageOperation implements IRunnableWithProgress {
42
public class ServiceModelWizardPageOperation implements IRunnableWithProgress {
45
43
46
	/**
47
	 * 
48
	 */
49
	public ServiceModelWizardPageOperation() {
50
		// TODO Auto-generated constructor stub
51
	}
52
44
53
	/* (non-Javadoc)
45
54
	 * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
55
	 */
56
	public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
46
	public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
57
		monitor.beginTask("configure model services", 100); //$NON-NLS-1$
47
		monitor.beginTask("configure model services", 100);  //$NON-NLS-1$
58
	
48
		
59
		IWizard wizard = MBSCustomPageManager.getPageData(ServiceModelWizardPage.SERVICE_MODEL_WIZARD_PAGE_ID).getWizardPage().getWizard();
49
		IWizard wizard = MBSCustomPageManager.getPageData(ServiceModelWizardPage.SERVICE_MODEL_WIZARD_PAGE_ID).getWizardPage().getWizard();
60
		IProject project = ((CDTCommonProjectWizard) wizard).getLastProject();
50
		IProject project = ((ICDTCommonProjectWizard) wizard).getLastProject();
61
		
51
		
62
		NewServiceModelWidget widget = (NewServiceModelWidget)getMBSProperty(SERVICE_MODEL_WIDGET_PROPERTY);
52
		IServiceConfiguration config = (IServiceConfiguration)getMBSProperty(CONFIG_PROPERTY);
63
		widget.applyChangesToConfiguration();
64
		IServiceConfiguration config = widget.getServiceConfiguration();
65
		
53
		
66
		ServiceModelManager smm = ServiceModelManager.getInstance();
54
		ServiceModelManager smm = ServiceModelManager.getInstance();
67
		smm.addConfiguration(project, config);
55
		smm.addConfiguration(project, config);
(-)src/org/eclipse/ptp/rdt/ui/wizards/ConvertToRemoteServiceModelWidget.java (-205 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM Corporation - Initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ptp.rdt.ui.wizards;
13
14
import java.util.HashMap;
15
import java.util.Iterator;
16
import java.util.Map;
17
import java.util.Set;
18
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.ptp.rdt.ui.messages.Messages;
21
import org.eclipse.ptp.rdt.ui.serviceproviders.NullBuildServiceProvider;
22
import org.eclipse.ptp.rdt.ui.serviceproviders.NullCIndexServiceProvider;
23
import org.eclipse.ptp.services.core.IService;
24
import org.eclipse.ptp.services.core.IServiceProvider;
25
import org.eclipse.ptp.services.core.IServiceProviderDescriptor;
26
import org.eclipse.ptp.services.core.ServiceModelManager;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.widgets.Event;
29
import org.eclipse.swt.widgets.Listener;
30
import org.eclipse.swt.widgets.TableItem;
31
32
/**
33
 * A table widget listing remote services and service providers.  This widget is used in 
34
 * ConvertToRemoteWizardPage and it stores information on the remote service model for the
35
 * projects to be converted.
36
 * 
37
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
38
 * part of a work in progress. There is no guarantee that this API will work or
39
 * that it will remain the same. Please do not use this API without consulting
40
 * with the RDT team.
41
 * 
42
 * @author vkong
43
 *
44
 */
45
public class ConvertToRemoteServiceModelWidget extends ServiceModelWidget {
46
	
47
	IProject fCurrentProject;
48
	
49
	Map<IProject, Map<String,String>> projectToServices = new HashMap<IProject, Map<String,String>>();
50
	Map<IProject, Map<String,IServiceProvider>> projectToProviders = new HashMap<IProject, Map<String,IServiceProvider>>();
51
	
52
	public class ConfigureListener2 extends ConfigureListener {
53
		public void handleEvent(Event event) {
54
			super.handleEvent(event);
55
			//users have to configure the services manually by clicking the configure button, not done automatically
56
			//once the services have been configured, they will be saved
57
			projectToServices.put(fCurrentProject, fServiceIDToSelectedProviderID);
58
			projectToProviders.put(fCurrentProject, fProviderIDToProviderMap);			
59
		}
60
	}
61
	
62
	/**
63
	 * Find available remote services and service providers for the given project and
64
	 * add them to the table
65
	 * @param project
66
	 */
67
	public void addServicesToTable(IProject project) {
68
		fProviderIDToProviderMap = new HashMap<String, IServiceProvider>();
69
		fServiceIDToSelectedProviderID = new HashMap<String, String>();
70
		fCurrentProject = project;
71
		createTableContent(project);		
72
	}
73
	
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.ptp.rdt.ui.wizards.ServiceModelWidget#createTableContent(org.eclipse.core.resources.IProject)
76
	 */
77
	@Override
78
	protected void createTableContent(IProject project) {
79
		fTable.removeAll();
80
		if (project == null) {
81
			super.createTableContent(project);
82
		} else if (projectToServices.get(project) == null && projectToProviders.get(project) == null) {
83
			super.createTableContent(project);
84
		} else {
85
			Set<IService> services = getContributedServices(project);
86
			Iterator<IService> iterator = services.iterator();
87
			
88
			Map<String, String> serviceIDToSelectedProviderID = projectToServices.get(fCurrentProject);
89
			Map<String, IServiceProvider> providerIDToProviderMap = projectToProviders.get(fCurrentProject);
90
			
91
			while(iterator.hasNext()) {
92
				final IService service = iterator.next();			
93
				
94
				TableItem item = new TableItem (fTable, SWT.NONE);
95
96
				// column 0 lists the name of the service
97
				item.setText (0, service.getName());
98
				item.setData(SERVICE_KEY, service);
99
				
100
				String providerID = serviceIDToSelectedProviderID.get(service.getId());
101
				IServiceProvider provider= providerIDToProviderMap.get(providerID);
102
				String configString;
103
				
104
				//remember user's selection and restore
105
				if (provider != null) {				
106
					// column 1 holds a dropdown with a list of providers
107
					item.setText(1, provider.getName());
108
					item.setData(PROVIDER_KEY, provider);
109
					
110
					configString = provider.getConfigurationString();					
111
				} else { //no previous user selection
112
					
113
					// column 1 holds a dropdown with a list of providers
114
					// default entry is the null provider if there is one			
115
					IServiceProviderDescriptor descriptor;
116
					if (service.getId().compareTo(NullBuildServiceProvider.SERVICE_ID) == 0)
117
						descriptor = service.getProviderDescriptor(NullBuildServiceProvider.ID);
118
					else if (service.getId().compareTo(NullCIndexServiceProvider.SERVICE_ID) == 0)
119
						descriptor = service.getProviderDescriptor(NullCIndexServiceProvider.ID);
120
					else
121
						descriptor = service.getProviders().iterator().next();
122
					item.setText(1, descriptor.getName());
123
					item.setData(PROVIDER_KEY, descriptor);
124
					
125
					//No actual providers are created yet so there's no configuration
126
					configString =  Messages.getString("ServiceModelWidget.4"); //$NON-NLS-1$
127
					
128
					if (descriptor.getId().compareTo(NullBuildServiceProvider.ID) == 0 ||
129
							descriptor.getId().compareTo(NullCIndexServiceProvider.ID) == 0) {
130
						
131
						//since the null providers are choosen, setup the service provider mappings
132
						ServiceModelManager manager = ServiceModelManager.getInstance();
133
						IServiceProvider serviceProvider = manager.getServiceProvider(descriptor);
134
						
135
						configString = serviceProvider.getConfigurationString();
136
						// column 2 holds the configuration string of the provider's current configuration 
137
						if (configString == null) {
138
							configString = Messages.getString("ServiceModelWidget.4"); //$NON-NLS-1$
139
						}
140
						fServiceIDToSelectedProviderID.put(service.getId(), descriptor.getId());
141
						fProviderIDToProviderMap.put(descriptor.getId(), serviceProvider);						
142
					}
143
				}
144
				
145
				// column 2 holds the configuration string of the provider's current configuration 
146
				if (configString == null) {
147
					configString = Messages.getString("ServiceModelWidget.4"); //$NON-NLS-1$
148
				}
149
				item.setText(2, configString);
150
			}
151
			
152
			fServiceIDToSelectedProviderID.putAll(serviceIDToSelectedProviderID);
153
			fProviderIDToProviderMap.putAll(providerIDToProviderMap);
154
		}
155
		projectToServices.put(project, fServiceIDToSelectedProviderID);
156
		projectToProviders.put(project, fProviderIDToProviderMap);
157
		
158
		if (fConfigChangeListener != null)
159
			fConfigChangeListener.handleEvent(null);
160
		
161
		//reset the configuration button
162
		if (fConfigureButton != null)
163
			fConfigureButton.setEnabled(false);
164
	}
165
166
	public void emptyTable() {
167
		fTable.removeAll();	
168
	}
169
	
170
	protected Listener getConfigureListener() {
171
		return new ConfigureListener2();		
172
	}
173
174
	/**
175
	 * @return the projectToServices
176
	 */
177
	public Map<IProject, Map<String, String>> getProjectToServices() {
178
		return projectToServices;
179
	}
180
181
	/**
182
	 * @return the projectToProviders
183
	 */
184
	public Map<IProject, Map<String, IServiceProvider>> getProjectToProviders() {
185
		return projectToProviders;
186
	}
187
	
188
	public boolean isConfigured(Object[] selectedProjects) {
189
		boolean configured = true;
190
		if (selectedProjects == null || selectedProjects.length < 1)
191
			return false;
192
		for (int i = 0; i < selectedProjects.length; i++) {
193
			IProject project = (IProject) selectedProjects[i];
194
			Map<String, String> serviceIDToSelectedProviderID = projectToServices.get(project);
195
			Map<String, IServiceProvider> providerIDToProviderMap = projectToProviders.get(project);
196
			if (serviceIDToSelectedProviderID == null || providerIDToProviderMap == null)
197
				return false;
198
			configured = configured && isConfigured(project, serviceIDToSelectedProviderID, providerIDToProviderMap);
199
		}
200
		
201
		return configured;
202
		
203
	}
204
205
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/ServiceModelWidget.java (-459 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM Corporation - Initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ptp.rdt.ui.wizards;
13
14
import java.util.HashMap;
15
import java.util.Iterator;
16
import java.util.LinkedHashSet;
17
import java.util.LinkedList;
18
import java.util.List;
19
import java.util.Map;
20
import java.util.Set;
21
22
import org.eclipse.cdt.core.CCProjectNature;
23
import org.eclipse.cdt.core.CProjectNature;
24
import org.eclipse.core.resources.IProject;
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.jface.layout.TableColumnLayout;
27
import org.eclipse.jface.viewers.ColumnWeightData;
28
import org.eclipse.ptp.rdt.core.RDTLog;
29
import org.eclipse.ptp.rdt.ui.messages.Messages;
30
import org.eclipse.ptp.rdt.ui.serviceproviders.NullBuildServiceProvider;
31
import org.eclipse.ptp.rdt.ui.serviceproviders.NullCIndexServiceProvider;
32
import org.eclipse.ptp.services.core.IService;
33
import org.eclipse.ptp.services.core.IServiceProvider;
34
import org.eclipse.ptp.services.core.IServiceProviderDescriptor;
35
import org.eclipse.ptp.services.core.ServiceModelManager;
36
import org.eclipse.ptp.services.ui.IServiceProviderConfiguration;
37
import org.eclipse.ptp.services.ui.IServiceProviderContributor;
38
import org.eclipse.ptp.services.ui.ServiceModelUIManager;
39
import org.eclipse.swt.SWT;
40
import org.eclipse.swt.custom.CCombo;
41
import org.eclipse.swt.custom.TableEditor;
42
import org.eclipse.swt.layout.FillLayout;
43
import org.eclipse.swt.layout.GridData;
44
import org.eclipse.swt.layout.GridLayout;
45
import org.eclipse.swt.widgets.Button;
46
import org.eclipse.swt.widgets.Composite;
47
import org.eclipse.swt.widgets.Control;
48
import org.eclipse.swt.widgets.Event;
49
import org.eclipse.swt.widgets.Listener;
50
import org.eclipse.swt.widgets.Table;
51
import org.eclipse.swt.widgets.TableColumn;
52
import org.eclipse.swt.widgets.TableItem;
53
54
/**
55
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
56
 * part of a work in progress. There is no guarantee that this API will work or
57
 * that it will remain the same. Please do not use this API without consulting
58
 * with the RDT team.
59
 * 
60
 * @deprecated
61
 * @see org.eclipse.ptp.services.ui.wizards.ServiceModelWidget
62
 */
63
public class ServiceModelWidget{
64
	
65
	protected static final String PROVIDER_KEY = "provider-id"; //$NON-NLS-1$
66
	protected static final String SERVICE_KEY = "service-id"; //$NON-NLS-1$
67
	
68
	protected Map<String, String> fServiceIDToSelectedProviderID;
69
	protected Map<String, IServiceProvider> fProviderIDToProviderMap;
70
71
	protected Table fTable;
72
	protected Button fConfigureButton;
73
	protected Listener fConfigChangeListener = null;
74
	
75
	public ServiceModelWidget() {
76
		fServiceIDToSelectedProviderID = new HashMap<String, String>();
77
		fProviderIDToProviderMap = new HashMap<String, IServiceProvider>();
78
	}
79
	
80
	public Control createContents(Composite parent) {
81
		Composite canvas = new Composite(parent, SWT.NONE);
82
		GridLayout canvasLayout = new GridLayout(2, false);
83
		canvas.setLayout(canvasLayout);
84
		
85
		Composite tableParent = new Composite(canvas, SWT.NONE);
86
		tableParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
87
		
88
		fTable = new Table (tableParent, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL);
89
		fTable.setLinesVisible (true);
90
		fTable.setHeaderVisible (true);
91
		
92
		TableColumnLayout layout = new TableColumnLayout();
93
		// create the columns and headers... note fourth column holds "Configure..." buttons and hence has no title.
94
		String[] titles = {Messages.getString("ServiceModelWidget.0"), Messages.getString("ServiceModelWidget.1"), Messages.getString("ServiceModelWidget.3")}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
95
		for (int i=0; i<titles.length; i++) {
96
			TableColumn column = new TableColumn (fTable, SWT.NONE);
97
			column.setText (titles [i]);
98
			int width = ColumnWeightData.MINIMUM_WIDTH;
99
			
100
			// set the column widths
101
			switch (i) {
102
			case 0: // Service name... usually short
103
				width = 100;
104
				break;
105
106
			case 1: // provider name... typically long
107
			case 2: // configuration string... typically long
108
				width = 250;
109
				break;
110
111
			}
112
			
113
			layout.setColumnData(column, new ColumnWeightData(1, width, true));
114
			
115
116
		}
117
		tableParent.setLayout(layout);
118
		fTable.setLayout(new FillLayout());
119
		
120
		createTableContent(null);
121
		
122
		fTable.setVisible(true);
123
		
124
		final TableEditor editor = new TableEditor(fTable);
125
		editor.horizontalAlignment = SWT.BEGINNING;
126
		editor.grabHorizontal = true;
127
		fTable.addListener(SWT.Selection, new Listener() {
128
			public void handleEvent(Event event) {
129
				int selectionIndex = fTable.getSelectionIndex();
130
				if (selectionIndex == -1) {
131
					fConfigureButton.setEnabled(false);
132
					return;
133
				}
134
				final TableItem item = fTable.getItem(selectionIndex);
135
				IService service = (IService) item.getData(SERVICE_KEY);
136
				IServiceProviderDescriptor provider = (IServiceProviderDescriptor) item.getData(PROVIDER_KEY);
137
				
138
				updateConfigureButton(provider);
139
				
140
				final CCombo combo = new CCombo(fTable, SWT.READ_ONLY);
141
				
142
				// populate with list of providers
143
				Set<IServiceProviderDescriptor> providers = service.getProviders();
144
				Iterator<IServiceProviderDescriptor> providerIterator = providers.iterator();
145
				
146
				int index = 0;
147
				final List<IServiceProviderDescriptor> providerIds = new LinkedList<IServiceProviderDescriptor>();
148
				while(providerIterator.hasNext()) {
149
					IServiceProviderDescriptor descriptor = providerIterator.next();
150
					combo.add(descriptor.getName(), index);
151
					providerIds.add(descriptor);
152
					if (descriptor.equals(provider)) {
153
						combo.select(index);
154
					}
155
					++index;
156
				}
157
				
158
				combo.setFocus();
159
				Listener listener = new Listener() {
160
					public void handleEvent(Event event) {
161
						switch (event.type) {
162
						case SWT.FocusOut:
163
							combo.dispose();
164
							break;
165
						case SWT.Selection:
166
							int selection = combo.getSelectionIndex();
167
							if (selection == -1) {
168
								return;
169
							}
170
							IServiceProviderDescriptor descriptor = providerIds.get(selection);
171
							item.setText(1, descriptor.getName());
172
							IService service = (IService) item.getData(SERVICE_KEY);
173
							item.setData(PROVIDER_KEY, descriptor);
174
175
							updateConfigureButton(descriptor);							
176
							
177
							//look in cache to see if there is a service provider that is already setup
178
							IServiceProvider provider = fProviderIDToProviderMap.get(descriptor.getId());
179
							String configString = Messages.getString("ServiceModelWidget.4"); //$NON-NLS-1$							
180
							if (provider != null) { //a service provider was already setup
181
								configString = provider.getConfigurationString();
182
							}
183
							
184
							item.setText(2, configString);
185
							
186
							if (descriptor.getId().compareTo(NullBuildServiceProvider.ID) == 0 ||
187
									descriptor.getId().compareTo(NullCIndexServiceProvider.ID) == 0) {
188
								
189
								//since the null providers are chosen, setup the service provider and the mappings
190
								ServiceModelManager manager = ServiceModelManager.getInstance();
191
								IServiceProvider serviceProvider = manager.getServiceProvider(descriptor);
192
								
193
								configString = serviceProvider.getConfigurationString();				
194
								if (configString == null) {
195
									configString = Messages.getString("ServiceModelWidget.4"); //$NON-NLS-1$
196
								}
197
								item.setText(2, configString);
198
								fProviderIDToProviderMap.put(descriptor.getId(), serviceProvider);
199
							}
200
							
201
							fServiceIDToSelectedProviderID.put(service.getId(), descriptor.getId());
202
							
203
							// allow container page to check if configurations are set
204
							if (fConfigChangeListener != null)
205
								fConfigChangeListener.handleEvent(null);
206
							
207
							combo.dispose();
208
							break;
209
						}
210
					}
211
				};
212
				combo.addListener(SWT.FocusOut, listener);
213
				combo.addListener(SWT.Selection, listener);
214
215
				editor.setEditor(combo, item, 1);
216
			}
217
		});
218
		
219
		fConfigureButton = new Button(canvas, SWT.PUSH);
220
		fConfigureButton.setEnabled(false);
221
		fConfigureButton.setText(Messages.getString("ServiceModelWidget.2")); //$NON-NLS-1$
222
		fConfigureButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
223
		Listener configureListener = getConfigureListener();
224
		fConfigureButton.addListener(SWT.Selection, configureListener);
225
		return canvas;
226
	}
227
	
228
	public class ConfigureListener implements Listener {
229
		public void handleEvent(Event event) {
230
			// launch the configuration UI for the service provider
231
			TableItem[] selection = fTable.getSelection();
232
			if (selection.length == 0) {
233
				return;
234
			}
235
			TableItem item = selection[0];
236
			ServiceModelManager manager = ServiceModelManager.getInstance();
237
			IServiceProviderDescriptor descriptor = (IServiceProviderDescriptor) item.getData(PROVIDER_KEY);
238
			
239
			//look in cache first
240
			IServiceProvider serviceProvider = fProviderIDToProviderMap.get(descriptor.getId());
241
			
242
			if (serviceProvider == null) {
243
				serviceProvider = manager.getServiceProvider(descriptor);
244
				fProviderIDToProviderMap.put(descriptor.getId(), serviceProvider);
245
			}
246
247
			IServiceProviderConfiguration configUI = ServiceModelUIManager.getInstance().getServiceProviderConfigurationUI(serviceProvider);
248
			configUI.configureServiceProvider(serviceProvider, fConfigureButton.getShell());
249
			
250
			String configString = serviceProvider.getConfigurationString();
251
			// column 2 holds the configuration string of the provider's current configuration 
252
			if (configString == null) {
253
				configString = Messages.getString("ServiceModelWidget.4"); //$NON-NLS-1$
254
			}
255
			item.setText(2, configString);
256
			
257
			// allow container page to check if configurations are set
258
			if (fConfigChangeListener != null)
259
				fConfigChangeListener.handleEvent(null);
260
		}
261
	}
262
	
263
	//sub class may override to change behaviour
264
	protected Listener getConfigureListener() {
265
		return new ConfigureListener();		
266
	}
267
	
268
	/**
269
	 * Generate the services, providers and provider configuration available for
270
	 * the given project in the table
271
	 * 
272
	 * Sub-classes may override its behaviour
273
	 * @param project
274
	 */
275
	protected void createTableContent(IProject project) {
276
		fTable.removeAll();
277
		Set<IService> allApplicableServices = getContributedServices(project);
278
		
279
		Iterator<IService> iterator = allApplicableServices.iterator();
280
281
		// get the contributed services... we need one row for each
282
		while(iterator.hasNext()) {
283
			final IService service = iterator.next();			
284
			
285
			TableItem item = new TableItem (fTable, SWT.NONE);
286
287
			// column 0 lists the name of the service
288
			item.setText (0, service.getName());
289
			item.setData(SERVICE_KEY, service);
290
			
291
			// column 1 holds a dropdown with a list of providers
292
			// default entry is the null provider if there is one			
293
			IServiceProviderDescriptor descriptor;
294
//			if (service.getId().compareTo(NullBuildServiceProvider.SERVICE_ID) == 0)
295
//				descriptor = service.getProviderDescriptor(NullBuildServiceProvider.ID);
296
//			else if (service.getId().compareTo(NullCIndexServiceProvider.SERVICE_ID) == 0)
297
//				descriptor = service.getProviderDescriptor(NullCIndexServiceProvider.ID);
298
//			else
299
				descriptor = service.getProviders().iterator().next();
300
			item.setText(1, descriptor.getName());
301
			item.setData(PROVIDER_KEY, descriptor);
302
			
303
			// No actual providers are created yet so there's no configuration
304
			String configString = Messages.getString("ServiceModelWidget.4"); //$NON-NLS-1$
305
			
306
			if (descriptor.getId().compareTo(NullBuildServiceProvider.ID) == 0 ||
307
					descriptor.getId().compareTo(NullCIndexServiceProvider.ID) == 0) {
308
				
309
				//since the null providers are chosen, setup the service provider and the mappings
310
				ServiceModelManager manager = ServiceModelManager.getInstance();
311
				IServiceProvider serviceProvider = manager.getServiceProvider(descriptor);
312
				
313
				configString = serviceProvider.getConfigurationString();				
314
				if (configString == null) {
315
					configString = Messages.getString("ServiceModelWidget.4"); //$NON-NLS-1$
316
				}
317
				
318
				fProviderIDToProviderMap.put(descriptor.getId(), serviceProvider);				
319
			}
320
			
321
			// column 2 holds the configuration string of the provider's current configuration 
322
			item.setText(2, configString);
323
			
324
			fServiceIDToSelectedProviderID.put(service.getId(), descriptor.getId());
325
			
326
			// allow container page to check if configurations are set
327
			if (fConfigChangeListener != null)
328
				fConfigChangeListener.handleEvent(null);
329
		}
330
	}
331
	
332
	/**
333
	 * Find available remote services and service providers for a given project
334
	 * 
335
	 * If project is null, the C and C++ natures are used to determine which services
336
	 * are available
337
	 */
338
	protected Set<IService> getContributedServices(IProject project) {		
339
		ServiceModelManager modelManager = ServiceModelManager.getInstance();
340
		Set<IService> allApplicableServices = new LinkedHashSet<IService>();
341
		
342
		if (project != null) {
343
		
344
			String[] natureIds = new String[] {};			
345
			try {
346
				//get the project natures of the project
347
				natureIds = project.getDescription().getNatureIds();			
348
			} catch (CoreException e) {
349
				RDTLog.logError(e);	
350
			}		
351
	
352
			for (int i = 0; i < natureIds.length; i++) {
353
				String natureId = natureIds[i];
354
				Set<IService> services = modelManager.getServices(natureId);
355
				if (services != null)
356
					allApplicableServices.addAll(services);
357
			}
358
		}
359
		else {		
360
			Set<IService> cppServices = modelManager.getServices(CCProjectNature.CC_NATURE_ID);
361
			Set<IService> cServices = modelManager.getServices(CProjectNature.C_NATURE_ID);
362
			
363
			allApplicableServices.addAll(cppServices);
364
			allApplicableServices.addAll(cServices);
365
		}
366
		return allApplicableServices;
367
	}
368
369
	public Map<String, String> getServiceIDToSelectedProviderID() {
370
		return fServiceIDToSelectedProviderID;
371
	}
372
373
	public Table getTable() {
374
		return fTable;
375
	}
376
377
	public void setTable(Table table) {
378
		fTable = table;
379
	}
380
381
	public void setServiceIDToSelectedProviderID(
382
			Map<String, String> serviceIDToSelectedProviderID) {
383
		fServiceIDToSelectedProviderID = serviceIDToSelectedProviderID;
384
	}
385
386
	public Map<String, IServiceProvider> getProviderIDToProviderMap() {
387
		return fProviderIDToProviderMap;
388
	}
389
390
	public void setProviderIDToProviderMap(
391
			Map<String, IServiceProvider> providerIDToProviderMap) {
392
		fProviderIDToProviderMap = providerIDToProviderMap;
393
	}
394
395
	/**
396
	 * Sub-class may override behaviour
397
	 * @return true if all available services have been configured
398
	 */
399
	public boolean isConfigured() {
400
		return isConfigured(null, fServiceIDToSelectedProviderID, fProviderIDToProviderMap);
401
	}
402
	
403
	/**
404
	 * Determine if all service providers have been configured
405
	 * @param project
406
	 * @param serviceIDToSelectedProviderID
407
	 * @param providerIDToProviderMap
408
	 * @return true if all service providers have been configured
409
	 */
410
	protected boolean isConfigured(IProject project, Map<String, String> serviceIDToSelectedProviderID, Map<String, IServiceProvider> providerIDToProviderMap) {
411
		Set<IService> allApplicableServices = getContributedServices(project);
412
		Iterator<IService> iterator = allApplicableServices.iterator();
413
		boolean configured = true;
414
		while (iterator.hasNext()) {
415
			String providerID = serviceIDToSelectedProviderID.get(iterator.next().getId());
416
			if (providerID == null)
417
				return false;
418
			else {
419
				IServiceProvider provider = providerIDToProviderMap.get(providerID);
420
				if (provider == null)
421
					return false;
422
				else
423
					configured = configured && provider.isConfigured();
424
			}
425
		}
426
		return configured;
427
	}
428
429
430
	/**
431
	 * @return the configuration change listener
432
	 */
433
	public Listener getConfigChangeListener() {
434
		return fConfigChangeListener;
435
	}
436
437
	/**
438
	 * Listens for changes in service provider configuration
439
	 * @param configChangeListener the configuration change listener to set
440
	 */
441
	public void setConfigChangeListener(Listener configChangeListener) {
442
		fConfigChangeListener = configChangeListener;
443
	}
444
		
445
	/**
446
	 * Enable/disable the configure button in this widget based on the service provider descriptor selected
447
	 * @param enabled
448
	 */
449
	protected void updateConfigureButton(IServiceProviderDescriptor descriptor) {
450
		//no need to configure the null providers so disable the configure button
451
452
		if (descriptor.getId().compareTo(NullBuildServiceProvider.ID) == 0 ||
453
			descriptor.getId().compareTo(NullCIndexServiceProvider.ID) == 0)
454
			
455
			fConfigureButton.setEnabled(false);
456
		else
457
			fConfigureButton.setEnabled(true);
458
	}
459
}
(-)plugin.xml (-21 / +3 lines)
Lines 116-152 Link Here
116
      <wizard
116
      <wizard
117
            canFinishEarly="false"
117
            canFinishEarly="false"
118
            category="org.eclipse.ptp.rdt.ui.wizardCategory.Remote"
118
            category="org.eclipse.ptp.rdt.ui.wizardCategory.Remote"
119
            class="org.eclipse.ptp.rdt.ui.wizards.NewRemoteCppProjectWizard"
119
            class="org.eclipse.ptp.rdt.ui.wizards.NewRemoteProjectWizard"
120
            finalPerspective="org.eclipse.ptp.rdt.ui.remoteCPerspective"
120
            finalPerspective="org.eclipse.ptp.rdt.ui.remoteCPerspective"
121
            hasPages="true"
121
            hasPages="true"
122
            icon="icons/etool16/newremote_c_proj.gif"
122
            icon="icons/etool16/newremote_c_proj.gif"
123
            id="org.eclipse.ptp.rdt.ui.newRemoteProjectWizard"
123
            id="org.eclipse.ptp.rdt.ui.newRemoteProjectWizard"
124
            name="%wizard.name.0"
124
            name="%wizard.name.0"
125
            project="true">
125
            project="true">
126
            <description>
127
             	%remoteCCPPproject.desc
128
         	</description>
129
      </wizard>
126
      </wizard>
130
      
127
      
131
      <wizard
128
      <wizard
132
            canFinishEarly="false"
133
            category="org.eclipse.cdt.ui.newCWizards"
134
            class="org.eclipse.ptp.rdt.ui.wizards.NewRemoteCppProjectWizard"
135
            finalPerspective="org.eclipse.ptp.rdt.ui.remoteCPerspective"
136
            hasPages="true"
137
            icon="icons/etool16/newremote_c_proj.gif"
138
            id="org.eclipse.ptp.rdt.ui.newCRemoteProjectWizard"
139
            name="%wizard.name.0"
140
            project="true">
141
            <description>
142
             	%remoteCCPPproject.desc
143
         	</description>
144
      </wizard>     
145
      
146
      <wizard
147
            category="org.eclipse.ptp.rdt.ui.wizardCategory.Remote"
129
            category="org.eclipse.ptp.rdt.ui.wizardCategory.Remote"
148
            class="org.eclipse.ptp.rdt.ui.wizards.ConvertToRemoteWizard"
130
            class="org.eclipse.ptp.rdt.ui.wizards.ConvertToRemoteWizard"
149
            finalPerspective="org.eclipse.ptp.rdt.ui.remoteCPerspective"
131
            finalPerspective="org.eclipse.cdt.ui.CPerspective"
150
            hasPages="true"
132
            hasPages="true"
151
            icon="icons/obj16/convert-normal.gif"
133
            icon="icons/obj16/convert-normal.gif"
152
            id="org.eclipse.ptp.rdt.ui.wizards.ConvertToMakeWizard"
134
            id="org.eclipse.ptp.rdt.ui.wizards.ConvertToMakeWizard"
Lines 158-164 Link Here
158
         <selection
140
         <selection
159
            class="org.eclipse.core.resources.IProject">
141
            class="org.eclipse.core.resources.IProject">
160
         </selection>
142
         </selection>
161
      </wizard>      
143
      </wizard>
162
   </extension>
144
   </extension>
163
   <extension
145
   <extension
164
         point="org.eclipse.cdt.ui.IndexerPage">
146
         point="org.eclipse.cdt.ui.IndexerPage">
(-)plugin.properties (+6 lines)
Lines 33-38 Link Here
33
NullBuildService.name=Null Build Service
33
NullBuildService.name=Null Build Service
34
RDTRemoteCIndexingService.name=RDT Remote C/C++ Indexing Service
34
RDTRemoteCIndexingService.name=RDT Remote C/C++ Indexing Service
35
RDTRemoteBuildService.name=RDT Remote Build Service
35
RDTRemoteBuildService.name=RDT Remote Build Service
36
LocalCIndexingService.name=Local-only C/C++ Indexing Service
37
LocalBuildService.name=Local-only Build Service
38
RemoteCIndexingService.name=Remote C/C++ Indexing Service
39
RemoteBuildService.name=Remote Build Service
40
LocalProjectLocationProvider.name=Local-only Project Location
41
RemoteProjectLocationProvider.name=Remote Project Location
36
RemoteEnvironment=Remote Environment
42
RemoteEnvironment=Remote Environment
37
page.remote = Remote Development
43
page.remote = Remote Development
38
Environment = Environment
44
Environment = Environment
(-)src/org/eclipse/ptp/rdt/ui/wizards/RemoteMainWizardPage.java (+543 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 Intel Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Intel Corporation - initial API and implementation
10
 *     IBM Corporation
11
 *******************************************************************************/
12
package org.eclipse.ptp.rdt.ui.wizards;
13
import java.net.URI;
14
import java.util.ArrayList;
15
import java.util.Iterator;
16
import java.util.LinkedList;
17
import java.util.List;
18
19
import org.eclipse.cdt.internal.ui.CPluginImages;
20
import org.eclipse.cdt.ui.CUIPlugin;
21
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
22
import org.eclipse.cdt.ui.newui.PageLayout;
23
import org.eclipse.cdt.ui.newui.UIMessages;
24
import org.eclipse.cdt.ui.wizards.CNewWizard;
25
import org.eclipse.cdt.ui.wizards.CWizardHandler;
26
import org.eclipse.cdt.ui.wizards.EntryDescriptor;
27
import org.eclipse.cdt.ui.wizards.IWizardItemsListListener;
28
import org.eclipse.cdt.ui.wizards.IWizardWithMemory;
29
import org.eclipse.core.filesystem.EFS;
30
import org.eclipse.core.filesystem.IFileInfo;
31
import org.eclipse.core.filesystem.IFileStore;
32
import org.eclipse.core.resources.IProject;
33
import org.eclipse.core.resources.ResourcesPlugin;
34
import org.eclipse.core.runtime.CoreException;
35
import org.eclipse.core.runtime.IConfigurationElement;
36
import org.eclipse.core.runtime.IExtension;
37
import org.eclipse.core.runtime.IExtensionPoint;
38
import org.eclipse.core.runtime.IStatus;
39
import org.eclipse.core.runtime.Platform;
40
import org.eclipse.jface.wizard.IWizard;
41
import org.eclipse.jface.wizard.IWizardPage;
42
import org.eclipse.osgi.util.TextProcessor;
43
import org.eclipse.ptp.internal.rdt.ui.RDTHelpContextIds;
44
import org.eclipse.ptp.services.core.IServiceConfiguration;
45
import org.eclipse.swt.SWT;
46
import org.eclipse.swt.accessibility.AccessibleAdapter;
47
import org.eclipse.swt.accessibility.AccessibleEvent;
48
import org.eclipse.swt.events.SelectionAdapter;
49
import org.eclipse.swt.events.SelectionEvent;
50
import org.eclipse.swt.graphics.Image;
51
import org.eclipse.swt.layout.GridData;
52
import org.eclipse.swt.layout.GridLayout;
53
import org.eclipse.swt.widgets.Button;
54
import org.eclipse.swt.widgets.Composite;
55
import org.eclipse.swt.widgets.Label;
56
import org.eclipse.swt.widgets.Shell;
57
import org.eclipse.swt.widgets.Tree;
58
import org.eclipse.swt.widgets.TreeItem;
59
import org.eclipse.ui.PlatformUI;
60
61
public class RemoteMainWizardPage extends NewRemoteProjectCreationPage implements IWizardItemsListListener {
62
	private static final Image IMG_CATEGORY = CPluginImages.get(CPluginImages.IMG_OBJS_SEARCHFOLDER);
63
	private static final Image IMG_ITEM = CPluginImages.get(CPluginImages.IMG_OBJS_VARIABLE);
64
65
	public static final String PAGE_ID = "org.eclipse.cdt.managedbuilder.ui.wizard.NewModelProjectWizardPage"; //$NON-NLS-1$
66
67
	private static final String EXTENSION_POINT_ID = "org.eclipse.cdt.ui.CDTWizard"; //$NON-NLS-1$
68
	private static final String ELEMENT_NAME = "wizard"; //$NON-NLS-1$
69
	private static final String CLASS_NAME = "class"; //$NON-NLS-1$
70
	public static final String DESC = "EntryDescriptor"; //$NON-NLS-1$ 
71
72
    // widgets
73
    private Tree tree;
74
    private Composite right;
75
    private Button show_sup;
76
    private Label right_label;
77
   
78
    public CWizardHandler h_selected = null;
79
	private Label categorySelectedLabel;
80
	
81
	private IServiceConfiguration defaultConfig = null;
82
83
	    /**
84
     * Creates a new project creation wizard page.
85
     *
86
     * @param pageName the name of this page
87
     */
88
    public RemoteMainWizardPage(String pageName) {
89
        super(pageName);
90
        setPageComplete(false);
91
		// default to view all toolchains
92
		CDTPrefUtil.setBool(CDTPrefUtil.KEY_NOSUPP, true);
93
    }
94
95
    /** (non-Javadoc)
96
     * Method declared on IDialogPage.
97
     */
98
    @Override
99
	public void createControl(Composite parent) {
100
    	super.createControl(parent);
101
    	
102
    	createDynamicGroup((Composite)getControl()); 
103
		switchTo(updateData(tree, right, show_sup, RemoteMainWizardPage.this, getWizard()),
104
				getDescriptor(tree));
105
106
		setPageComplete(validatePage());
107
        setErrorMessage(null);
108
        setMessage(null);
109
        
110
		Shell shell = getContainer().getShell(); //if not created on the shell, will not display properly
111
		PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, RDTHelpContextIds.CREATING_A_REMOTE_PROJECT);
112
    }
113
    
114
    private void createDynamicGroup(Composite parent) {
115
        Composite c = new Composite(parent, SWT.NONE);
116
        c.setLayoutData(new GridData(GridData.FILL_BOTH));
117
    	c.setLayout(new GridLayout(2, true));
118
    	
119
        Label l1 = new Label(c, SWT.NONE);
120
        l1.setText(UIMessages.getString("CMainWizardPage.0")); //$NON-NLS-1$
121
        l1.setFont(parent.getFont());
122
        l1.setLayoutData(new GridData(GridData.BEGINNING));
123
        
124
        right_label = new Label(c, SWT.NONE);
125
        right_label.setFont(parent.getFont());
126
        right_label.setLayoutData(new GridData(GridData.BEGINNING));
127
    	
128
        tree = new Tree(c, SWT.SINGLE | SWT.BORDER);
129
        tree.setLayoutData(new GridData(GridData.FILL_BOTH));
130
        tree.addSelectionListener(new SelectionAdapter() {
131
			@Override
132
			public void widgetSelected(SelectionEvent e) {
133
				TreeItem[] tis = tree.getSelection();
134
				if (tis == null || tis.length == 0) return;
135
				switchTo((CWizardHandler)tis[0].getData(), (EntryDescriptor)tis[0].getData(DESC));
136
				setPageComplete(validatePage());
137
			}});
138
        tree.getAccessible().addAccessibleListener(
139
				 new AccessibleAdapter() {                       
140
	                 @Override
141
					public void getName(AccessibleEvent e) {
142
	                	 for (int i = 0; i < tree.getItemCount(); i++) {
143
	                		 if (tree.getItem(i).getText().compareTo(e.result) == 0)
144
	                			 return;
145
	                	 }
146
                         e.result = UIMessages.getString("CMainWizardPage.0"); //$NON-NLS-1$
147
	                 }
148
	             }
149
			 );
150
        right = new Composite(c, SWT.NONE);
151
        right.setLayoutData(new GridData(GridData.FILL_BOTH));
152
        right.setLayout(new PageLayout());
153
154
        show_sup = new Button(c, SWT.CHECK);
155
        show_sup.setText(UIMessages.getString("CMainWizardPage.1")); //$NON-NLS-1$
156
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
157
        gd.horizontalSpan = 2;
158
        show_sup.setLayoutData(gd);
159
        show_sup.addSelectionListener(new SelectionAdapter() {
160
			@Override
161
			public void widgetSelected(SelectionEvent e) {
162
				if (h_selected != null)
163
					h_selected.setSupportedOnly(show_sup.getSelection());
164
				switchTo(updateData(tree, right, show_sup, RemoteMainWizardPage.this, getWizard()),
165
						getDescriptor(tree));
166
			}} );
167
168
        // restore settings from preferences
169
		show_sup.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOSUPP));
170
    }
171
    
172
    @Override
173
	public IWizardPage getNextPage() {
174
		return (h_selected == null) ? null : h_selected.getSpecificPage();
175
    }		
176
177
    public URI getProjectLocation() {
178
    	return useDefaults() ? null : getLocationURI();
179
    }
180
181
    /**
182
     * Returns whether this page's controls currently all contain valid 
183
     * values.
184
     *
185
     * @return <code>true</code> if all controls are valid, and
186
     *   <code>false</code> if at least one is invalid
187
     */
188
    @Override
189
	protected boolean validatePage() {
190
		setMessage(null);
191
    	if (!super.validatePage())
192
    		return false;
193
194
        if (getProjectName().indexOf('#') >= 0) {
195
            setErrorMessage(UIMessages.getString("RemoteMainWizardPage.0")); //$NON-NLS-1$
196
            return false;
197
        }
198
        
199
        boolean bad = true; // should we treat existing project as error
200
        
201
        IProject handle = getProjectHandle();
202
        if (handle.exists()) {
203
        	if (getWizard() instanceof IWizardWithMemory) {
204
        		IWizardWithMemory w = (IWizardWithMemory)getWizard();
205
        		if (w.getLastProjectName() != null && w.getLastProjectName().equals(getProjectName()))
206
        			bad = false;
207
        	}
208
        	if (bad) { 
209
        		setErrorMessage(UIMessages.getString("CMainWizardPage.10")); //$NON-NLS-1$
210
        	    return false;
211
        	}
212
        }
213
214
        if (bad) { // skip this check if project already created 
215
        	try {
216
        		IFileStore fs;
217
	        	URI p = getProjectLocation();
218
	        	if (p == null) {
219
	        		fs = EFS.getStore(ResourcesPlugin.getWorkspace().getRoot().getLocationURI());
220
	        		fs = fs.getChild(getProjectName());
221
	        	} else
222
	        		fs = EFS.getStore(p);
223
        		IFileInfo f = fs.fetchInfo();
224
	        	if (f.exists() && f.isDirectory()) {
225
		  			if (fs.getChild(".project").fetchInfo().exists()) { //$NON-NLS-1$
226
						setMessage("Existing project settings will be overridden"); //$NON-NLS-1$
227
						return true;
228
		  			}
229
	        	}
230
        	} catch (CoreException e) {
231
        		CUIPlugin.log(e.getStatus());
232
        	}
233
        }
234
        
235
        if (!useDefaults()) {
236
            IStatus locationStatus = ResourcesPlugin.getWorkspace().validateProjectLocationURI(handle,
237
            		getLocationURI());
238
            if (!locationStatus.isOK()) {
239
                setErrorMessage(locationStatus.getMessage());
240
                return false;
241
            }
242
        }
243
244
        if (tree.getItemCount() == 0) {
245
        	setErrorMessage(UIMessages.getString("CMainWizardPage.3")); //$NON-NLS-1$
246
        	return false;
247
        }
248
        
249
        // it is not an error, but we cannot continue
250
        if (h_selected == null) {
251
            setErrorMessage(null);
252
	        return false;	        	
253
        }
254
255
        String s = h_selected.getErrorMessage(); 
256
		if (s != null) {
257
    		setErrorMessage(s);
258
    		return false;
259
        }
260
		
261
        setErrorMessage(null);
262
        return true;
263
    }
264
265
    /**
266
     * 
267
     * @param tree
268
     * @param right
269
     * @param show_sup
270
     * @param ls
271
     * @param wizard
272
     * @return : selected Wizard Handler.
273
     */
274
	public static CWizardHandler updateData(Tree tree, Composite right, Button show_sup, IWizardItemsListListener ls, IWizard wizard) {
275
		// remember selected item
276
		TreeItem[] sel = tree.getSelection();
277
		String savedStr = (sel.length > 0) ? sel[0].getText() : null; 
278
		
279
		tree.removeAll();
280
		IExtensionPoint extensionPoint =
281
			    Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_POINT_ID);
282
		if (extensionPoint == null) return null;
283
		IExtension[] extensions = extensionPoint.getExtensions();
284
		if (extensions == null) return null;
285
		
286
		List<EntryDescriptor> items = new ArrayList<EntryDescriptor>();
287
		for (int i = 0; i < extensions.length; ++i)	{
288
			IConfigurationElement[] elements = extensions[i].getConfigurationElements();
289
			for (IConfigurationElement element : elements) {
290
				if (element.getName().equals(ELEMENT_NAME)) {
291
					CNewWizard w = null;
292
					try {
293
						w = (CNewWizard) element.createExecutableExtension(CLASS_NAME);
294
					} catch (CoreException e) {
295
						System.out.println(UIMessages.getString("CMainWizardPage.5") + e.getLocalizedMessage()); //$NON-NLS-1$
296
						return null; 
297
					}
298
					if (w == null) return null;
299
					w.setDependentControl(right, ls);
300
					for (EntryDescriptor ed : w.createItems(show_sup.getSelection(), wizard))	
301
						items.add(ed);
302
				}
303
			}
304
		}
305
		// If there is a EntryDescriptor which is default for category, make sure it 
306
		// is in the front of the list.
307
		for (int i = 0; i < items.size(); ++i)
308
		{
309
			EntryDescriptor ed = items.get(i);
310
			if (ed.isDefaultForCategory())
311
			{
312
				items.remove(i);
313
				items.add(0, ed);
314
				break;
315
			}				
316
		}
317
		
318
		// bug # 211935 : allow items filtering.
319
		if (ls != null) // NULL means call from prefs
320
			items = ls.filterItems(items);
321
		addItemsToTree(tree, items);
322
		
323
		if (tree.getItemCount() > 0) {
324
			TreeItem target = null;
325
			// try to search item which was selected before
326
			if (savedStr != null) {
327
				TreeItem[] all = tree.getItems();
328
				for (TreeItem element : all) {
329
					if (savedStr.equals(element.getText())) {
330
						target = element;
331
						break;
332
					}
333
				}
334
			}
335
			if (target == null)
336
			{
337
				target = tree.getItem(0);
338
				if (target.getItemCount() != 0)
339
					target = target.getItem(0);
340
			}
341
			tree.setSelection(target);
342
			return (CWizardHandler)target.getData();
343
		}
344
		return null;
345
	}
346
347
	private static void addItemsToTree(Tree tree, List<EntryDescriptor> items) {
348
	//  Sorting is disabled because of users requests	
349
	//	Collections.sort(items, CDTListComparator.getInstance());
350
		
351
		ArrayList<TreeItem> placedTreeItemsList = new ArrayList<TreeItem>(items.size());
352
		ArrayList<EntryDescriptor> placedEntryDescriptorsList = new ArrayList<EntryDescriptor>(items.size());
353
		for (EntryDescriptor wd : items) {
354
			if (wd.getParentId() == null) {
355
				wd.setPath(wd.getId());
356
				TreeItem ti = new TreeItem(tree, SWT.NONE);
357
				ti.setText(TextProcessor.process(wd.getName()));
358
				ti.setData(wd.getHandler());
359
				ti.setData(DESC, wd);
360
				ti.setImage(calcImage(wd));
361
				placedTreeItemsList.add(ti);
362
				placedEntryDescriptorsList.add(wd);
363
			}
364
		}
365
		while(true) {
366
			boolean found = false;
367
			Iterator<EntryDescriptor> it2 = items.iterator();
368
			while (it2.hasNext()) {
369
				EntryDescriptor wd1 = it2.next();
370
				if (wd1.getParentId() == null) continue;
371
				for (int i = 0; i< placedEntryDescriptorsList.size(); i++) {
372
					EntryDescriptor wd2 = placedEntryDescriptorsList.get(i);
373
					if (wd2.getId().equals(wd1.getParentId())) {
374
						found = true;
375
						wd1.setParentId(null);
376
						CWizardHandler h = wd2.getHandler();
377
						/* If neither wd1 itself, nor its parent (wd2) have a handler
378
						 * associated with them, and the item is not a category,
379
						 * then skip it. If it's category, then it's possible that
380
						 * children will have a handler associated with them.
381
						 */
382
						if (h == null && wd1.getHandler() == null && !wd1.isCategory())
383
							break;
384
385
						wd1.setPath(wd2.getPath() + "/" + wd1.getId()); //$NON-NLS-1$
386
						wd1.setParent(wd2);
387
						if (h != null) {
388
							if (wd1.getHandler() == null && !wd1.isCategory())
389
								wd1.setHandler((CWizardHandler)h.clone());
390
							if (!h.isApplicable(wd1))
391
								break;
392
						}
393
						
394
						TreeItem p = placedTreeItemsList.get(i);
395
						TreeItem ti = new TreeItem(p, SWT.NONE);
396
						ti.setText(wd1.getName());
397
						ti.setData(wd1.getHandler());
398
						ti.setData(DESC, wd1);
399
						ti.setImage(calcImage(wd1));
400
						placedTreeItemsList.add(ti);
401
						placedEntryDescriptorsList.add(wd1);
402
						break;
403
					}
404
				}
405
			}
406
			// repeat iterations until all items are placed.
407
			if (!found) break;
408
		}
409
		// orphan elements (with not-existing parentId) are ignored
410
	}
411
412
	private void switchTo(CWizardHandler h, EntryDescriptor ed) {
413
		if (h == null) 
414
			h = ed.getHandler();
415
		if (ed.isCategory())
416
			h = null;
417
		try {
418
			if (h != null) 
419
				h.initialize(ed);
420
		} catch (CoreException e) { 
421
			h = null;
422
		}
423
		if (h_selected != null) 
424
			h_selected.handleUnSelection();
425
		h_selected = h;
426
		if (h == null) {
427
			if (ed.isCategory()) {
428
				if (categorySelectedLabel == null) {
429
					categorySelectedLabel = new Label(right, SWT.WRAP);
430
					categorySelectedLabel.setText(
431
							UIMessages.getString("RemoteMainWizardPage.1"));  //$NON-NLS-1$
432
					right.layout();
433
				}
434
				categorySelectedLabel.setVisible(true);
435
			}
436
			return;
437
		}
438
		right_label.setText(h_selected.getHeader());
439
		if (categorySelectedLabel != null)
440
			categorySelectedLabel.setVisible(false);
441
		h_selected.handleSelection();
442
		h_selected.setSupportedOnly(show_sup.getSelection());
443
	}
444
445
446
	public static EntryDescriptor getDescriptor(Tree _tree) {
447
		TreeItem[] sel = _tree.getSelection();
448
		if (sel == null || sel.length == 0) 
449
			return null;
450
		return (EntryDescriptor)sel[0].getData(DESC);
451
	}
452
	
453
	public void toolChainListChanged(int count) {
454
		setPageComplete(validatePage());
455
		getWizard().getContainer().updateButtons();
456
	}
457
458
	public boolean isCurrent() { return isCurrentPage(); }
459
	
460
	private static Image calcImage(EntryDescriptor ed) {
461
		if (ed.getImage() != null) return ed.getImage();
462
		if (ed.isCategory()) return IMG_CATEGORY;
463
		return IMG_ITEM;
464
	}
465
466
	@SuppressWarnings("unchecked")
467
	public List filterItems(List items) {
468
		/// iterate through the list, removing entry descriptors we don't care about
469
		Iterator iterator = items.iterator();
470
		
471
		List<EntryDescriptor> filteredList = new LinkedList<EntryDescriptor>();
472
		
473
		while(iterator.hasNext()) {
474
			EntryDescriptor ed = (EntryDescriptor) iterator.next();
475
			if(ed.getId().startsWith("org.eclipse.ptp.rdt")) {  // both the category and the template start with this //$NON-NLS-1$
476
				filteredList.add(ed);
477
			}
478
		}
479
		
480
		return filteredList;
481
	}
482
483
//	public void pageChanged(PageChangedEvent event) {
484
//		if (event.getSelectedPage().equals(this)) {
485
//			if (defaultConfig == null) {
486
//				ServiceModelManager manager = ServiceModelManager.getInstance();
487
//				
488
//				/*
489
//				 * Create a new service configuration
490
//				 * 
491
//				 * XXX: this should check if a service configuration has already
492
//				 * 		been selected, in which case it should use that one.
493
//				 */
494
//				IServiceConfiguration config = manager.newServiceConfiguration(handle.getName());
495
//				
496
//				/*
497
//				 * Make this configuration active for this project.
498
//				 */
499
//				manager.setConfiguration(handle, config);
500
//				
501
//				/*
502
//				 * Set default service providers based on location of project
503
//				 */
504
//				URI location = getLocationURI();
505
//				IRemoteServices remServ = PTPRemoteCorePlugin.getDefault().getRemoteServices(location);
506
//				IRemoteConnection remConn = PTPRemoteCorePlugin.getDefault().getConnection(location);
507
//				
508
//				/*
509
//				 * Project location
510
//				 */
511
//				IRemoteServiceProvider projectProvider = new RemoteProjectServiceProvider();
512
//				projectProvider.setRemoteServicesID(remServ.getId());
513
//				projectProvider.setRemoteConnectionName(remConn.getName());
514
//				config.setServiceProvider(manager.getService(RemoteProjectServiceProvider.ID), projectProvider);
515
//
516
//				/*
517
//				 * Build service
518
//				 */
519
//				IRemoteServiceProvider buildProvider = new RemoteBuildServiceProvider();
520
//				buildProvider.setRemoteServicesID(remServ.getId());
521
//				buildProvider.setRemoteConnectionName(remConn.getName());
522
//				config.setServiceProvider(manager.getService(RemoteBuildServiceProvider.ID), buildProvider);
523
//
524
//				/*
525
//				 * Index service
526
//				 */
527
//				IRemoteServiceProvider indexProvider = new RemoteCIndexServiceProvider();
528
//				indexProvider.setRemoteServicesID(remServ.getId());
529
//				indexProvider.setRemoteConnectionName(remConn.getName());
530
//				config.setServiceProvider(manager.getService(RemoteCIndexServiceProvider.ID), indexProvider);
531
//				
532
//				defaultConfig = config;
533
//				
534
//				/*
535
//				 * Pass configuration to ServiceModelWizardPage
536
//				 */
537
//				MBSCustomPageManager.addPageProperty(ServiceModelWizardPage.SERVICE_MODEL_WIZARD_PAGE_ID, 
538
//						ServiceModelWizardPage.SERVICE_CONFIGURATION_PROPERTY, config);
539
//			}
540
//		}
541
//	}
542
}
543
(-)src/org/eclipse/ptp/rdt/ui/wizards/RemoteCommonProjectWizard.java (+422 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2008 Rational Software Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM Rational Software - Initial API and implementation
10
 * Intel corp - rework for New Project Model
11
 *******************************************************************************/
12
package org.eclipse.ptp.rdt.ui.wizards;
13
14
15
import java.lang.reflect.InvocationTargetException;
16
import java.net.URI;
17
import java.util.ArrayList;
18
import java.util.Arrays;
19
import java.util.List;
20
21
import org.eclipse.cdt.core.CCorePlugin;
22
import org.eclipse.cdt.core.model.CoreModel;
23
import org.eclipse.cdt.core.model.ILanguage;
24
import org.eclipse.cdt.core.model.LanguageManager;
25
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
26
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
27
import org.eclipse.cdt.ui.CUIPlugin;
28
import org.eclipse.cdt.ui.newui.UIMessages;
29
import org.eclipse.cdt.ui.wizards.CWizardHandler;
30
import org.eclipse.cdt.ui.wizards.ICDTCommonProjectWizard;
31
import org.eclipse.cdt.ui.wizards.IWizardWithMemory;
32
import org.eclipse.core.filesystem.EFS;
33
import org.eclipse.core.filesystem.IFileInfo;
34
import org.eclipse.core.filesystem.IFileStore;
35
import org.eclipse.core.resources.IProject;
36
import org.eclipse.core.resources.IProjectDescription;
37
import org.eclipse.core.resources.IResource;
38
import org.eclipse.core.resources.IWorkspace;
39
import org.eclipse.core.resources.IWorkspaceRoot;
40
import org.eclipse.core.resources.IWorkspaceRunnable;
41
import org.eclipse.core.resources.ResourcesPlugin;
42
import org.eclipse.core.runtime.CoreException;
43
import org.eclipse.core.runtime.IConfigurationElement;
44
import org.eclipse.core.runtime.IExecutableExtension;
45
import org.eclipse.core.runtime.IProgressMonitor;
46
import org.eclipse.core.runtime.NullProgressMonitor;
47
import org.eclipse.core.runtime.Platform;
48
import org.eclipse.core.runtime.SubProgressMonitor;
49
import org.eclipse.core.runtime.content.IContentType;
50
import org.eclipse.core.runtime.content.IContentTypeManager;
51
import org.eclipse.jface.dialogs.MessageDialog;
52
import org.eclipse.jface.operation.IRunnableWithProgress;
53
import org.eclipse.ptp.services.core.ServiceModelManager;
54
import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
55
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
56
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
57
58
public abstract class RemoteCommonProjectWizard extends BasicNewResourceWizard 
59
implements IExecutableExtension, IWizardWithMemory, ICDTCommonProjectWizard
60
{
61
	private static final String PREFIX= "CProjectWizard"; //$NON-NLS-1$
62
	private static final String OP_ERROR= "CProjectWizard.op_error"; //$NON-NLS-1$
63
	private static final String title= CUIPlugin.getResourceString(OP_ERROR + ".title"); //$NON-NLS-1$
64
	private static final String message= CUIPlugin.getResourceString(OP_ERROR + ".message"); //$NON-NLS-1$
65
	private static final String[] EMPTY_ARR = new String[0]; 
66
	
67
	protected IConfigurationElement fConfigElement;
68
	protected RemoteMainWizardPage fMainPage;
69
	
70
	protected IProject newProject;
71
	private String wz_title;
72
	private String wz_desc;
73
	
74
	private boolean existingPath = false;
75
	private String lastProjectName = null;
76
	private URI lastProjectLocation = null;
77
	private CWizardHandler savedHandler = null;
78
	
79
	private ServiceModelManager manager = ServiceModelManager.getInstance();
80
81
	public RemoteCommonProjectWizard() {
82
		this(UIMessages.getString("NewModelProjectWizard.0"),UIMessages.getString("NewModelProjectWizard.1")); //$NON-NLS-1$ //$NON-NLS-2$
83
	}
84
85
	public RemoteCommonProjectWizard(String title, String desc) {
86
		super();
87
		setDialogSettings(CUIPlugin.getDefault().getDialogSettings());
88
		setNeedsProgressMonitor(true);
89
		setForcePreviousAndNextButtons(true);
90
		setWindowTitle(title);
91
		wz_title = title;
92
		wz_desc = desc;
93
	}
94
	
95
	@Override
96
	public void addPages() {
97
		fMainPage= new RemoteMainWizardPage(CUIPlugin.getResourceString(PREFIX));
98
		fMainPage.setTitle(wz_title);
99
		fMainPage.setDescription(wz_desc);
100
		addPage(fMainPage);
101
	}
102
103
	/**
104
	 * @return true if user has changed settings since project creation
105
	 */
106
	private boolean isChanged() {
107
		if (savedHandler != fMainPage.h_selected)
108
			return true;
109
110
		if (!fMainPage.getProjectName().equals(lastProjectName))
111
			return true;
112
			
113
		URI projectLocation = fMainPage.getProjectLocation();
114
		if (projectLocation == null) {
115
			if (lastProjectLocation != null)
116
				return true;
117
		} else if (!projectLocation.equals(lastProjectLocation))
118
			return true;
119
		
120
		return savedHandler.isChanged(); 
121
	}
122
123
	public IProject getProject(boolean defaults) {
124
		return getProject(defaults, true);
125
	}
126
127
	public IProject getProject(boolean defaults, boolean onFinish) {
128
		if (newProject != null && isChanged()) 
129
			clearProject(); 
130
		if (newProject == null)	{
131
            existingPath = false;
132
		  	try {
133
		  		IFileStore fs;
134
				URI p = fMainPage.getProjectLocation();
135
			  	if (p == null) { 
136
			  		fs = EFS.getStore(ResourcesPlugin.getWorkspace().getRoot().getLocationURI());
137
				    fs = fs.getChild(fMainPage.getProjectName());
138
			  	} else
139
			  		fs = EFS.getStore(p);
140
		  		IFileInfo f = fs.fetchInfo();
141
		  		if (f.exists() && f.isDirectory()) {
142
		  			if (fs.getChild(".project").fetchInfo().exists()) { //$NON-NLS-1$
143
	                	if (!
144
	                		MessageDialog.openConfirm(getShell(), 
145
	        				UIMessages.getString("CDTCommonProjectWizard.0"),  //$NON-NLS-1$
146
							UIMessages.getString("CDTCommonProjectWizard.1")) //$NON-NLS-1$
147
							)
148
	                		return null;
149
	                }
150
	                existingPath = true;
151
		  		}
152
        	} catch (CoreException e) {
153
        		CUIPlugin.log(e.getStatus());
154
        	}
155
			savedHandler = fMainPage.h_selected;
156
			savedHandler.saveState();
157
			lastProjectName = fMainPage.getProjectName();
158
			lastProjectLocation = fMainPage.getProjectLocation();
159
			// start creation process
160
			invokeRunnable(getRunnable(defaults, onFinish)); 
161
		} 
162
		return newProject;
163
	}
164
165
	/**
166
	 * Remove created project either after error
167
	 * or if user returned back from config page. 
168
	 */
169
	private void clearProject() {
170
		if (lastProjectName == null) return;
171
		try {
172
			ResourcesPlugin.getWorkspace().getRoot().getProject(lastProjectName).delete(!existingPath, true, null);
173
		} catch (CoreException ignore) {}
174
		if (newProject != null) {
175
			manager.remove(newProject);
176
		}
177
		newProject = null;
178
		lastProjectName = null;
179
		lastProjectLocation = null;
180
	}
181
	
182
	private boolean invokeRunnable(IRunnableWithProgress runnable) {
183
		IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(runnable);
184
		try {
185
			getContainer().run(true, true, op);
186
		} catch (InvocationTargetException e) {
187
			CUIPlugin.errorDialog(getShell(), title, message, e.getTargetException(), false);
188
			clearProject();
189
			return false;
190
		} catch  (InterruptedException e) {
191
			clearProject();
192
			return false;
193
		}
194
		return true;
195
	}
196
197
	@Override
198
	public boolean performFinish() {
199
		boolean needsPost = (newProject != null && !isChanged());
200
		// create project if it is not created yet
201
		if (getProject(fMainPage.isCurrent(), true) == null) 
202
			return false;
203
		fMainPage.h_selected.postProcess(newProject, needsPost);
204
		try {
205
			setCreated();
206
		} catch (CoreException e) {
207
			e.printStackTrace();
208
			return false;
209
		}
210
		BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
211
		selectAndReveal(newProject);
212
		return true;
213
	}
214
	
215
	protected boolean setCreated() throws CoreException {
216
		ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
217
		
218
		ICProjectDescription des = mngr.getProjectDescription(newProject, false);
219
		
220
		if(des == null ) {
221
			return false;
222
		}
223
		
224
		if(des.isCdtProjectCreating()){
225
			des = mngr.getProjectDescription(newProject, true);
226
			des.setCdtProjectCreated();
227
			mngr.setProjectDescription(newProject, des, false, null);
228
			return true;
229
		}
230
		return false;
231
	}
232
	
233
    @Override
234
	public boolean performCancel() {
235
    	clearProject();
236
        return true;
237
    }
238
239
	public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
240
		fConfigElement= config;
241
	}
242
243
	private IRunnableWithProgress getRunnable(boolean _defaults, final boolean onFinish) {
244
		final boolean defaults = _defaults;
245
		return new IRunnableWithProgress() {
246
			public void run(IProgressMonitor imonitor) throws InvocationTargetException, InterruptedException {
247
				final Exception except[] = new Exception[1];
248
				getShell().getDisplay().syncExec(new Runnable() {
249
					public void run() {
250
						IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {
251
							public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
252
								final IProgressMonitor fMonitor;
253
								if (monitor == null) {
254
									fMonitor= new NullProgressMonitor();
255
								} else {
256
									fMonitor = monitor;
257
								}
258
								fMonitor.beginTask(CUIPlugin.getResourceString("CProjectWizard.op_description"), 100); //$NON-NLS-1$
259
								fMonitor.worked(10);
260
								try {							
261
									newProject = createIProject(lastProjectName, lastProjectLocation, new SubProgressMonitor(fMonitor, 40));
262
									if (newProject != null) 
263
										fMainPage.h_selected.createProject(newProject, defaults, onFinish, new SubProgressMonitor(fMonitor, 40));
264
									fMonitor.worked(10);
265
								} catch (CoreException e) {	CUIPlugin.log(e); }
266
								finally {
267
									fMonitor.done();
268
								}
269
							}
270
						});
271
						try {
272
							getContainer().run(false, true, op);
273
						} catch (InvocationTargetException e) {
274
							except[0] = e;
275
						} catch (InterruptedException e) {
276
							except[0] = e;
277
						}
278
					}
279
				});
280
				if (except[0] != null) {
281
					if (except[0] instanceof InvocationTargetException) {
282
						throw (InvocationTargetException)except[0];
283
					}
284
					if (except[0] instanceof InterruptedException) {
285
						throw (InterruptedException)except[0];
286
					}
287
					throw new InvocationTargetException(except[0]);
288
				}					
289
			}
290
		};
291
	}
292
	
293
	public IProject createIProject(final String name, final URI location) throws CoreException{
294
		return createIProject(name, location, new NullProgressMonitor());
295
	}
296
	
297
	/**
298
	 * @since 5.1
299
	 */
300
	protected IProgressMonitor continueCreationMonitor;
301
302
	/**
303
	 * @param monitor 
304
	 * @since 5.1
305
	 * 
306
	 */	
307
	public IProject createIProject(final String name, final URI location, IProgressMonitor monitor) throws CoreException{
308
		
309
		monitor.beginTask(UIMessages.getString("CDTCommonProjectWizard.creatingProject"), 100); //$NON-NLS-1$
310
		
311
		if (newProject != null)	return newProject;
312
		
313
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
314
		IWorkspaceRoot root = workspace.getRoot();
315
		final IProject newProjectHandle = root.getProject(name);
316
		
317
		if (!newProjectHandle.exists()) {
318
//			IWorkspaceDescription workspaceDesc = workspace.getDescription();
319
//			workspaceDesc.setAutoBuilding(false);
320
//			workspace.setDescription(workspaceDesc);
321
			IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
322
			if(location != null)
323
				description.setLocationURI(location);
324
			newProject = CCorePlugin.getDefault().createCDTProject(description, newProjectHandle, new SubProgressMonitor(monitor,25));
325
		} else {
326
			IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
327
				public void run(IProgressMonitor monitor) throws CoreException {
328
					newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, monitor);
329
				}
330
			};
331
			workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, new SubProgressMonitor(monitor,25));
332
			newProject = newProjectHandle;
333
		}
334
        
335
		// Open the project if we have to
336
		if (!newProject.isOpen()) {
337
			newProject.open(new SubProgressMonitor(monitor,25));
338
		}
339
		
340
		continueCreationMonitor = new SubProgressMonitor(monitor,25);
341
		IProject proj = continueCreation(newProject);
342
		
343
		monitor.done();
344
		
345
		return proj;	
346
	}
347
	
348
	protected abstract IProject continueCreation(IProject prj); 
349
	public abstract String[] getNatures();
350
	
351
	@Override
352
	public void dispose() {
353
		fMainPage.dispose();
354
	}
355
	
356
    @Override
357
	public boolean canFinish() {
358
    	if (fMainPage.h_selected != null) {
359
    		if(!fMainPage.h_selected.canFinish())
360
    			return false;
361
    		String s = fMainPage.h_selected.getErrorMessage();
362
    		if (s != null) return false;
363
    	}
364
    	return super.canFinish();
365
    }
366
    /**
367
     * Returns last project name used for creation
368
     */
369
	public String getLastProjectName() {
370
		return lastProjectName;
371
	}
372
373
	public URI getLastProjectLocation() {
374
		return lastProjectLocation;
375
	}
376
377
	public IProject getLastProject() {
378
		return newProject;
379
	}
380
381
	// Methods below should provide data for language check
382
	public String[] getLanguageIDs (){
383
		String[] contentTypeIds = getContentTypeIDs();
384
		if(contentTypeIds.length > 0) {
385
			IContentTypeManager manager = Platform.getContentTypeManager();
386
			List<String> languageIDs = new ArrayList<String>();
387
			for(int i = 0; i < contentTypeIds.length; ++i) {
388
				IContentType contentType = manager.getContentType(contentTypeIds[i]);
389
				if(null != contentType) {
390
					ILanguage language = LanguageManager.getInstance().getLanguage(contentType);
391
					if(!languageIDs.contains(language.getId())) {
392
						languageIDs.add(language.getId());
393
					}
394
				}
395
			}
396
			return languageIDs.toArray(new String[languageIDs.size()]);
397
		}
398
		return EMPTY_ARR;
399
	}
400
	
401
	public String[] getContentTypeIDs (){
402
		return EMPTY_ARR;
403
	}
404
	
405
	public String[] getExtensions (){
406
		String[] contentTypeIds = getContentTypeIDs();
407
		if(contentTypeIds.length > 0) {
408
			IContentTypeManager manager = Platform.getContentTypeManager();
409
			List<String> extensions = new ArrayList<String>();
410
			for(int i = 0; i < contentTypeIds.length; ++i) {
411
				IContentType contentType = manager.getContentType(contentTypeIds[i]);
412
				if(null != contentType) {
413
					String[] thisTypeExtensions = contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
414
					extensions.addAll(Arrays.asList(thisTypeExtensions));
415
				}
416
			}
417
			return extensions.toArray(new String[extensions.size()]);
418
		}
419
		return EMPTY_ARR;
420
	}
421
	
422
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/NewRemoteProjectCreationPage.java (+365 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Jakub Jurkiewicz <jakub.jurkiewicz@gmail.com> - Fix for Bug 174737
11
 *     [IDE] New Plug-in Project wizard status handling is inconsistent
12
 *     Oakland Software Incorporated (Francis Upton) <francisu@ieee.org>
13
 *		    Bug 224997 [Workbench] Impossible to copy project
14
 *******************************************************************************/
15
package org.eclipse.ptp.rdt.ui.wizards;
16
17
import java.net.URI;
18
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.IWorkspace;
22
import org.eclipse.core.resources.ResourcesPlugin;
23
import org.eclipse.core.runtime.IPath;
24
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.Path;
26
import org.eclipse.jface.dialogs.Dialog;
27
import org.eclipse.jface.viewers.IStructuredSelection;
28
import org.eclipse.ptp.rdt.ui.wizards.RemoteProjectContentsLocationArea.IErrorMessageReporter;
29
import org.eclipse.ptp.remote.core.IRemoteConnection;
30
import org.eclipse.ptp.remote.core.IRemoteServices;
31
import org.eclipse.swt.SWT;
32
import org.eclipse.swt.layout.GridData;
33
import org.eclipse.swt.layout.GridLayout;
34
import org.eclipse.swt.widgets.Button;
35
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Event;
37
import org.eclipse.swt.widgets.Label;
38
import org.eclipse.swt.widgets.Listener;
39
import org.eclipse.swt.widgets.Text;
40
import org.eclipse.ui.PlatformUI;
41
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
42
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
43
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
44
import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
45
46
/**
47
 * Standard main page for a wizard that is creates a project resource.
48
 * <p>
49
 * This page may be used by clients as-is; it may be also be subclassed to suit.
50
 * </p>
51
 * <p>
52
 * Example usage:
53
 * <pre>
54
 * mainPage = new NewRemoteProjectCreationPage("basicNewProjectPage");
55
 * mainPage.setTitle("Project");
56
 * mainPage.setDescription("Create a new project resource.");
57
 * </pre>
58
 * </p>
59
 */
60
public class NewRemoteProjectCreationPage extends WizardNewProjectCreationPage {
61
62
       // initial value stores
63
    private String initialProjectFieldValue;
64
65
    // widgets
66
    private Text projectNameField;
67
68
    private Listener nameModifyListener = new Listener() {
69
        public void handleEvent(Event e) {
70
        	setLocationForSelection();
71
            boolean valid = validatePage();
72
            setPageComplete(valid);
73
                
74
        }
75
    };
76
77
	private RemoteProjectContentsLocationArea locationArea;
78
79
//	private WorkingSetGroup workingSetGroup;
80
81
    // constants
82
    private static final int SIZING_TEXT_FIELD_WIDTH = 250;
83
84
    /**
85
     * Creates a new project creation wizard page.
86
     *
87
     * @param pageName the name of this page
88
     */
89
    public NewRemoteProjectCreationPage(String pageName) {
90
    	super(pageName);
91
	    setPageComplete(false);
92
    }
93
94
    /**
95
	 * Creates a new project creation wizard page.
96
	 * 
97
	 * @param pageName
98
	 * @param selection
99
	 * @param workingSetTypes
100
	 * 
101
	 * @deprecated default placement of the working set group has been removed.
102
	 *             If you wish to use the working set block please call
103
	 *             {@link #createWorkingSetGroup(Composite, IStructuredSelection, String[])}
104
	 *             in your overridden {@link #createControl(Composite)}
105
	 *             implementation.
106
	 * @since 3.4
107
	 */
108
	public NewRemoteProjectCreationPage(String pageName,
109
			IStructuredSelection selection, String[] workingSetTypes) {
110
		this(pageName);
111
	}
112
113
	/** (non-Javadoc)
114
     * Method declared on IDialogPage.
115
     */
116
    public void createControl(Composite parent) {
117
        Composite composite = new Composite(parent, SWT.NULL);
118
119
        initializeDialogUnits(parent);
120
121
        PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
122
                IIDEHelpContextIds.NEW_PROJECT_WIZARD_PAGE);
123
124
        composite.setLayout(new GridLayout());
125
        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
126
127
        createProjectNameGroup(composite);
128
        locationArea = new RemoteProjectContentsLocationArea(getErrorReporter(), composite);
129
        if(initialProjectFieldValue != null) {
130
			locationArea.updateProjectName(initialProjectFieldValue);
131
		}
132
        
133
		// Scale the buttons based on the rest of the dialog
134
        for (Button button : locationArea.getButtons()) {
135
        	setButtonLayoutData(button);
136
        }
137
		
138
        setPageComplete(validatePage());
139
        // Show description on opening
140
        setErrorMessage(null);
141
        setMessage(null);
142
        setControl(composite);
143
        Dialog.applyDialogFont(composite);
144
    }
145
    
146
    /**
147
	 * Get an error reporter for the receiver.
148
	 * @return IErrorMessageReporter
149
	 */
150
	private IErrorMessageReporter getErrorReporter() {
151
		return new IErrorMessageReporter(){
152
			/* (non-Javadoc)
153
			 * @see org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMessageReporter#reportError(java.lang.String)
154
			 */
155
			public void reportError(String errorMessage, boolean infoOnly) {
156
				if (infoOnly) {
157
					setMessage(errorMessage, IStatus.INFO);
158
					setErrorMessage(null);
159
				}
160
				else
161
					setErrorMessage(errorMessage);
162
				boolean valid = errorMessage == null;
163
				if(valid) {
164
					valid = validatePage();
165
				}
166
				
167
				setPageComplete(valid);
168
			}
169
		};
170
	}
171
172
    /**
173
     * Creates the project name specification controls.
174
     *
175
     * @param parent the parent composite
176
     */
177
    private final void createProjectNameGroup(Composite parent) {
178
        // project specification group
179
        Composite projectGroup = new Composite(parent, SWT.NONE);
180
        GridLayout layout = new GridLayout();
181
        layout.numColumns = 2;
182
        projectGroup.setLayout(layout);
183
        projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
184
185
        // new project label
186
        Label projectLabel = new Label(projectGroup, SWT.NONE);
187
        projectLabel.setText(IDEWorkbenchMessages.WizardNewProjectCreationPage_nameLabel);
188
        projectLabel.setFont(parent.getFont());
189
190
        // new project name entry field
191
        projectNameField = new Text(projectGroup, SWT.BORDER);
192
        GridData data = new GridData(GridData.FILL_HORIZONTAL);
193
        data.widthHint = SIZING_TEXT_FIELD_WIDTH;
194
        projectNameField.setLayoutData(data);
195
        projectNameField.setFont(parent.getFont());
196
197
        // Set the initial value first before listener
198
        // to avoid handling an event during the creation.
199
        if (initialProjectFieldValue != null) {
200
			projectNameField.setText(initialProjectFieldValue);
201
		}
202
        projectNameField.addListener(SWT.Modify, nameModifyListener);
203
    }
204
205
    /**
206
     * Returns the current project location path as entered by 
207
     * the user, or its anticipated initial value.
208
     * Note that if the default has been returned the path
209
     * in a project description used to create a project
210
     * should not be set.
211
     *
212
     * @return the project location path or its anticipated initial value.
213
     */
214
    public IPath getLocationPath() {
215
        return new Path(locationArea.getProjectLocation());
216
    }
217
218
    /**
219
     * Returns the current project location URI as entered by 
220
     * the user, or <code>null</code> if a valid project location
221
     * has not been entered.
222
     *
223
     * @return the project location URI, or <code>null</code>
224
     * @since 3.2
225
     */
226
    public URI getLocationURI() {
227
    	return locationArea.getProjectLocationURI();
228
    }
229
230
    /**
231
     * Returns the current project name as entered by the user, or its anticipated
232
     * initial value.
233
     *
234
     * @return the project name, its anticipated initial value, or <code>null</code>
235
     *   if no project name is known
236
     */
237
    public String getProjectName() {
238
        if (projectNameField == null) {
239
			return initialProjectFieldValue;
240
		}
241
242
        return getProjectNameFieldValue();
243
    }
244
245
    /**
246
     * Returns the value of the project name field
247
     * with leading and trailing spaces removed.
248
     * 
249
     * @return the project name in the field
250
     */
251
    private String getProjectNameFieldValue() {
252
        if (projectNameField == null) {
253
			return ""; //$NON-NLS-1$
254
		}
255
256
        return projectNameField.getText().trim();
257
    }
258
259
    
260
    public IRemoteConnection getRemoteConnection() {
261
    	return locationArea.getRemoteConnection();
262
    }
263
    
264
    
265
    public IRemoteServices getRemoteServices() {
266
    	return locationArea.getRemoteServices();
267
    }
268
    
269
    /**
270
     * Sets the initial project name that this page will use when
271
     * created. The name is ignored if the createControl(Composite)
272
     * method has already been called. Leading and trailing spaces
273
     * in the name are ignored.
274
     * Providing the name of an existing project will not necessarily 
275
     * cause the wizard to warn the user.  Callers of this method 
276
     * should first check if the project name passed already exists 
277
     * in the workspace.
278
     * 
279
     * @param name initial project name for this page
280
     * 
281
     * @see IWorkspace#validateName(String, int)
282
     * 
283
     */
284
    public void setInitialProjectName(String name) {
285
        if (name == null) {
286
			initialProjectFieldValue = null;
287
		} else {
288
            initialProjectFieldValue = name.trim();
289
            if(locationArea != null) {
290
				locationArea.updateProjectName(name.trim());
291
			}
292
        }
293
    }
294
295
    /**
296
     * Set the location to the default location if we are set to useDefaults.
297
     */
298
    private void setLocationForSelection() {
299
    	locationArea.updateProjectName(getProjectNameFieldValue());
300
    }
301
302
  
303
    /**
304
     * Returns whether this page's controls currently all contain valid 
305
     * values.
306
     *
307
     * @return <code>true</code> if all controls are valid, and
308
     *   <code>false</code> if at least one is invalid
309
     */
310
    protected boolean validatePage() {
311
        IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
312
313
        String projectFieldContents = getProjectNameFieldValue();
314
        if (projectFieldContents.equals("")) { //$NON-NLS-1$
315
            setErrorMessage(null);
316
            setMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectNameEmpty);
317
            return false;
318
        }
319
320
        IStatus nameStatus = workspace.validateName(projectFieldContents,
321
                IResource.PROJECT);
322
        if (!nameStatus.isOK()) {
323
            setErrorMessage(nameStatus.getMessage());
324
            return false;
325
        }
326
327
        IProject handle = getProjectHandle();
328
        if (handle.exists()) {
329
            setErrorMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectExistsMessage);
330
            return false;
331
        }
332
                
333
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
334
				getProjectNameFieldValue());
335
		locationArea.setExistingProject(project);
336
		
337
		String validLocationMessage = locationArea.checkValidLocation();
338
		if (validLocationMessage != null) { // there is no destination location given
339
			setErrorMessage(validLocationMessage);
340
			return false;
341
		}
342
343
        setErrorMessage(null);
344
        setMessage(null);
345
        return true;
346
    }
347
348
    /*
349
     * see @DialogPage.setVisible(boolean)
350
     */
351
    public void setVisible(boolean visible) {
352
        getControl().setVisible(visible);
353
        if (visible) {
354
			projectNameField.setFocus();
355
		}
356
    }
357
358
    /**
359
     * Returns the useDefaults.
360
     * @return boolean
361
     */
362
    public boolean useDefaults() {
363
        return locationArea.isDefault();
364
    }
365
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/NewRemoteProjectWizard.java (+75 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM - Initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.rdt.ui.wizards;
12
13
import org.eclipse.cdt.core.CCProjectNature;
14
import org.eclipse.cdt.core.CProjectNature;
15
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.NullProgressMonitor;
18
import org.eclipse.ptp.internal.rdt.ui.RDTPluginImages;
19
import org.eclipse.ptp.rdt.core.resources.RemoteNature;
20
21
/**
22
 * A wizard for creating new Remote C/C++ Projects
23
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
24
 * part of a work in progress. There is no guarantee that this API will work or
25
 * that it will remain the same. Please do not use this API without consulting
26
 * with the RDT team.
27
 * 
28
 * @author crecoskie
29
 *
30
 */
31
public class NewRemoteProjectWizard extends RemoteCommonProjectWizard {
32
	private static final String PREFIX= "CProjectWizard"; //$NON-NLS-1$
33
	private static final String wz_title = "New Remote Project"; //$NON-NLS-1$
34
	private static final String wz_desc = "Create remote project of the selected type"; //$NON-NLS-1$
35
	
36
	/**
37
	 * 
38
	 */
39
	public NewRemoteProjectWizard() {
40
		super(wz_title, wz_desc);
41
	}
42
43
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard#continueCreation(org.eclipse.core.resources.IProject)
46
	 */
47
	
48
	@Override
49
	protected IProject continueCreation(IProject prj) {
50
		try {
51
			CProjectNature.addCNature(prj, new NullProgressMonitor());
52
			CCProjectNature.addCCNature(prj, new NullProgressMonitor());
53
			RemoteNature.addRemoteNature(prj, new NullProgressMonitor());
54
		} catch (CoreException e) {}
55
		return prj;
56
	}
57
58
	/* (non-Javadoc)
59
	 * @see org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard#getNatures()
60
	 */
61
	@Override
62
	public String[] getNatures() {
63
		return new String[] { CProjectNature.C_NATURE_ID, CCProjectNature.CC_NATURE_ID, RemoteNature.REMOTE_NATURE_ID};
64
	}
65
66
67
	/* (non-Javadoc)
68
	 * @see org.eclipse.ui.wizards.newresource.BasicNewResourceWizard#initializeDefaultPageImageDescriptor()
69
	 */
70
	@Override
71
	protected void initializeDefaultPageImageDescriptor() {
72
		setDefaultPageImageDescriptor(RDTPluginImages.DESC_WIZBAN_NEW_REMOTE_C_PROJ);
73
	}
74
75
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/RemoteProjectContentsLocationArea.java (+490 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM - Initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.rdt.ui.wizards;
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.net.URI;
15
import java.util.HashMap;
16
import java.util.Map;
17
18
import org.eclipse.core.filesystem.URIUtil;
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.core.runtime.Platform;
25
import org.eclipse.core.runtime.Status;
26
import org.eclipse.jface.dialogs.ErrorDialog;
27
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
28
import org.eclipse.jface.operation.IRunnableWithProgress;
29
import org.eclipse.ptp.rdt.ui.UIPlugin;
30
import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteBuildServiceProvider;
31
import org.eclipse.ptp.remote.core.IRemoteConnection;
32
import org.eclipse.ptp.remote.core.IRemoteServices;
33
import org.eclipse.ptp.remote.core.PTPRemoteCorePlugin;
34
import org.eclipse.ptp.remote.core.exception.RemoteConnectionException;
35
import org.eclipse.ptp.remote.ui.IRemoteUIConnectionManager;
36
import org.eclipse.ptp.remote.ui.IRemoteUIFileManager;
37
import org.eclipse.ptp.remote.ui.IRemoteUIServices;
38
import org.eclipse.ptp.remote.ui.PTPRemoteUIPlugin;
39
import org.eclipse.swt.SWT;
40
import org.eclipse.swt.events.ModifyEvent;
41
import org.eclipse.swt.events.ModifyListener;
42
import org.eclipse.swt.events.SelectionEvent;
43
import org.eclipse.swt.events.SelectionListener;
44
import org.eclipse.swt.layout.GridData;
45
import org.eclipse.swt.layout.GridLayout;
46
import org.eclipse.swt.widgets.Button;
47
import org.eclipse.swt.widgets.Combo;
48
import org.eclipse.swt.widgets.Composite;
49
import org.eclipse.swt.widgets.Control;
50
import org.eclipse.swt.widgets.Group;
51
import org.eclipse.swt.widgets.Label;
52
import org.eclipse.swt.widgets.Text;
53
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
54
import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils;
55
56
/**
57
 * Allows the user to select a provider of Remote Services for a RemoteBuildServiceProvider.
58
 * 
59
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
60
 * part of a work in progress. There is no guarantee that this API will work or
61
 * that it will remain the same. Please do not use this API without consulting
62
 * with the RDT team.
63
 * 
64
 * @author crecoskie
65
 * @see org.eclipse.ptp.rdt.ui.serviceproviders.RemoteBuildServiceProvider
66
 */
67
public class RemoteProjectContentsLocationArea {
68
69
	/**
70
	 * IErrorMessageReporter is an interface for type that allow message
71
	 * reporting.
72
	 * 
73
	 */
74
	public interface IErrorMessageReporter {
75
		/**
76
		 * Report the error message
77
		 * 
78
		 * @param errorMessage
79
		 *            String or <code>null</code>. If the errorMessage is
80
		 *            null then clear any error state.
81
		 * @param infoOnly
82
		 *            the message is an informational message, but the dialog
83
		 *            cannot continue
84
		 * 
85
		 */
86
		public void reportError(String errorMessage, boolean infoOnly);
87
	}
88
	
89
	private static final String FILE_SCHEME = "file"; //$NON-NLS-1$
90
91
	private IProject fExistingProject;
92
93
	private IErrorMessageReporter fErrorReporter;
94
95
	private RemoteBuildServiceProvider fProvider;
96
	
97
	private Map<Integer, IRemoteServices> fComboIndexToRemoteServicesProviderMap = new HashMap<Integer, IRemoteServices>();
98
	
99
	private IRemoteServices fSelectedProvider;
100
101
	private Map<Integer, IRemoteConnection> fComboIndexToRemoteConnectionMap = new HashMap<Integer, IRemoteConnection>();
102
103
	private IRemoteConnection fSelectedConnection;
104
105
	private String fProjectName = IDEResourceInfoUtils.EMPTY_STRING;
106
	
107
	private Button fBrowseButton;
108
	
109
	private Button fNewConnectionButton;
110
	
111
	private Combo fProviderCombo;
112
	
113
	private Combo fConnectionCombo;
114
	
115
	private Text fLocationText;
116
117
//	public RemoteProjectContentsLocationArea(IServiceProvider provider, Composite composite) {
118
//		if(provider instanceof RemoteBuildServiceProvider)
119
//			fProvider = (RemoteBuildServiceProvider) provider;
120
//		else
121
//			throw new IllegalArgumentException(); // should never happen
122
//		createContents(composite);
123
//	}
124
	public RemoteProjectContentsLocationArea(IErrorMessageReporter reporter, Composite composite) {
125
		fErrorReporter = reporter;
126
		createContents(composite);
127
	}
128
	
129
    /**
130
	 * Check if the entry in the widget location is valid. If it is valid return
131
	 * null. Otherwise return a string that indicates the problem.
132
	 * 
133
	 * @return String
134
	 */
135
	public String checkValidLocation() {
136
137
		String locationFieldContents = fLocationText.getText();
138
		if (locationFieldContents.length() == 0) {
139
			return IDEWorkbenchMessages.WizardNewProjectCreationPage_projectLocationEmpty;
140
		}
141
142
		URI newPath = getProjectLocationURI();
143
		if (newPath == null) {
144
			return IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationError;
145
		}
146
147
		if (fExistingProject != null) {
148
			URI projectPath = fExistingProject.getLocationURI();
149
			if (projectPath != null && URIUtil.equals(projectPath, newPath)) {
150
				return IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationIsSelf;
151
			}
152
		}
153
154
		return null;
155
	}
156
    
157
    /**
158
	 * Return the browse button. Usually referenced in order to set the layout
159
	 * data for a dialog.
160
	 * 
161
	 * @return Button
162
	 */
163
	public Button[] getButtons() {
164
		return new Button[]{fBrowseButton, fNewConnectionButton};
165
	}
166
167
	/**
168
	 * Get the URI for the location field if possible.
169
	 * 
170
	 * @return URI or <code>null</code> if it is not valid.
171
	 */
172
	public URI getProjectLocationURI() {
173
		return fSelectedProvider.getFileManager(fSelectedConnection).toURI(new Path(fLocationText.getText()));
174
	}
175
176
	/**
177
	 * Return whether or not we are currently showing the default location for
178
	 * the project.
179
	 * 
180
	 * @return boolean
181
	 */
182
	public boolean isDefault() {
183
//		return useDefaultsButton.getSelection();
184
		return false;
185
	}
186
    
187
	/**
188
	 * Set the project to base the contents off of.
189
	 *
190
	 * @param existingProject
191
	 */
192
	public void setExistingProject(IProject existingProject) {
193
		fProjectName = existingProject.getName();
194
		fExistingProject = existingProject;
195
	}
196
197
	/**
198
	 * Set the text to the default or clear it if not using the defaults.
199
	 * 
200
	 * @param newName
201
	 *            the name of the project to use. If <code>null</code> use the
202
	 *            existing project name.
203
	 */
204
	public void updateProjectName(String newName) {
205
		fProjectName = newName;
206
		if (isDefault()) {
207
//			locationPathField.setText(TextProcessor
208
//					.process(getDefaultPathDisplayString()));
209
		}
210
211
	}
212
	
213
	/**
214
	 * Attempt to open a connection.
215
	 */
216
	private void checkConnection() {
217
		if (!fSelectedConnection.isOpen()) {
218
			IRunnableWithProgress op = new IRunnableWithProgress() {
219
				public void run(IProgressMonitor monitor)
220
						throws InvocationTargetException,
221
						InterruptedException {
222
					try {
223
						fSelectedConnection.open(monitor);
224
						if (monitor.isCanceled()) {
225
							throw new InterruptedException("Cancelled by user"); //$NON-NLS-1$
226
						}
227
					} catch (RemoteConnectionException e) {
228
						throw new InvocationTargetException(e);
229
					}
230
				}
231
				
232
			};
233
			try {
234
				new ProgressMonitorDialog(fConnectionCombo.getShell()).run(true, true, op);
235
			} catch (InvocationTargetException e) {
236
				ErrorDialog.openError(fConnectionCombo.getShell(), "Connection error", //$NON-NLS-1$
237
						"Could not open connection", //$NON-NLS-1$
238
						new Status(IStatus.ERROR, UIPlugin.PLUGIN_ID, e.getCause().getMessage()));
239
			} catch (InterruptedException e) {
240
				ErrorDialog.openError(fConnectionCombo.getShell(), "Connection error", //$NON-NLS-1$
241
						"Could not open connection", //$NON-NLS-1$
242
						new Status(IStatus.ERROR, UIPlugin.PLUGIN_ID, e.getMessage()));
243
			}
244
		}
245
	}
246
	
247
	/**
248
	 * Return the path we are going to display. If it is a file URI then remove
249
	 * the file prefix.
250
	 * 
251
	 * @return String
252
	 */
253
	private String getDefaultPathDisplayString() {
254
255
		URI defaultURI = null;
256
		if (fExistingProject != null) {
257
			defaultURI = fExistingProject.getLocationURI();
258
		}
259
260
		// Handle files specially. Assume a file if there is no project to query
261
		if (defaultURI == null || defaultURI.getScheme().equals(FILE_SCHEME)) {
262
			return Platform.getLocation().append(fProjectName).toOSString();
263
		}
264
		return defaultURI.toString();
265
266
	}
267
	
268
	/**
269
	 * @return
270
	 */
271
	private IRemoteUIConnectionManager getUIConnectionManager() {
272
		IRemoteUIConnectionManager connectionManager = PTPRemoteUIPlugin.getDefault().getRemoteUIServices(fSelectedProvider)
273
				.getUIConnectionManager();
274
		return connectionManager;
275
	}
276
	
277
278
	/**
279
	 * @param connectionCombo
280
	 */
281
	private void populateConnectionCombo(final Combo connectionCombo) {
282
		connectionCombo.removeAll();
283
		
284
		//attempt to restore settings from saved state
285
//        IRemoteConnection connectionSelected = fProvider.getConnection();
286
		
287
		IRemoteConnection[] connections = fSelectedProvider.getConnectionManager().getConnections();
288
		int toSelect = 0;
289
        
290
        for(int k = 0; k < connections.length; k++) {
291
        	connectionCombo.add(connections[k].getName(), k);
292
        	fComboIndexToRemoteConnectionMap .put(k, connections[k]);
293
        	
294
//        	if (connectionSelected != null && connectionSelected.getName().compareTo(connections[k].getName()) == 0) {
295
//        		toSelect = k;
296
//        	}
297
        }
298
        
299
        // set selected connection to be the first one if we're not restoring from settings
300
        connectionCombo.select(toSelect);
301
        fSelectedConnection = fComboIndexToRemoteConnectionMap.get(toSelect);
302
	}
303
	
304
	/**
305
     * @param button
306
     */
307
    private void updateNewConnectionButtonEnabled(Button button) {
308
    	IRemoteUIConnectionManager connectionManager = getUIConnectionManager();
309
    	button.setEnabled(connectionManager != null);  	
310
    }
311
312
	protected Control createContents(Composite parent) {
313
    	Group container = new Group(parent, SWT.SHADOW_ETCHED_IN);
314
    	
315
        GridLayout layout = new GridLayout();
316
        layout.numColumns = 3;
317
        container.setLayout(layout);
318
        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
319
        container.setLayoutData(gd);
320
        
321
        // Label for "Provider:"
322
        Label providerLabel = new Label(container, SWT.LEFT);
323
        providerLabel.setText("Remote Provider:"); //$NON-NLS-1$
324
        
325
        // combo for providers
326
        fProviderCombo = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
327
        // set layout to grab horizontal space
328
        fProviderCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
329
        gd = new GridData();
330
        gd.horizontalSpan = 2;
331
        fProviderCombo.setLayoutData(gd);
332
        fProviderCombo.addSelectionListener(new SelectionListener() {
333
			public void widgetDefaultSelected(SelectionEvent e) {
334
				widgetSelected(e);
335
			}
336
337
			public void widgetSelected(SelectionEvent e) {
338
				int selectionIndex = fProviderCombo.getSelectionIndex();
339
				fSelectedProvider = fComboIndexToRemoteServicesProviderMap.get(selectionIndex);
340
				
341
				populateConnectionCombo(fConnectionCombo);
342
				updateNewConnectionButtonEnabled(fNewConnectionButton);
343
			}
344
        });
345
    
346
        //attempt to restore settings from saved state
347
//        IRemoteServices providerSelected = fProvider.getRemoteServices(); 
348
        
349
        // populate the combo with a list of providers
350
        IRemoteServices[] providers = PTPRemoteCorePlugin.getDefault().getAllRemoteServices();
351
        int toSelect = 0;
352
        
353
        for(int k = 0; k < providers.length; k++) {
354
        	fProviderCombo.add(providers[k].getName(), k);
355
        	fComboIndexToRemoteServicesProviderMap.put(k, providers[k]);
356
        	
357
//        	if (providerSelected != null && providerSelected.getName().compareTo(providers[k].getName()) == 0) {
358
//        		toSelect = k;
359
//        	}
360
        }
361
        
362
        // set selected host to be the first one if we're not restoring from settings
363
        fProviderCombo.select(toSelect);
364
        fSelectedProvider = fComboIndexToRemoteServicesProviderMap.get(toSelect);
365
        
366
        // connection combo
367
        // Label for "Connection:"
368
        Label connectionLabel = new Label(container, SWT.LEFT);
369
        connectionLabel.setText("Connection:"); //$NON-NLS-1$
370
        
371
        // combo for providers
372
        fConnectionCombo = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
373
        // set layout to grab horizontal space
374
        fConnectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
375
        fConnectionCombo.addSelectionListener(new SelectionListener() {
376
			public void widgetDefaultSelected(SelectionEvent e) {
377
				widgetSelected(e);
378
			}
379
380
			public void widgetSelected(SelectionEvent e) {
381
				int selectionIndex = fConnectionCombo.getSelectionIndex();
382
				fSelectedConnection = fComboIndexToRemoteConnectionMap.get(selectionIndex);
383
				updateNewConnectionButtonEnabled(fNewConnectionButton);
384
			}
385
        });
386
        
387
        // populate the combo with a list of providers
388
        populateConnectionCombo(fConnectionCombo);
389
           
390
        // new connection button
391
        fNewConnectionButton = new Button(container, SWT.PUSH);
392
        fNewConnectionButton.setText("New..."); //$NON-NLS-1$
393
        updateNewConnectionButtonEnabled(fNewConnectionButton);
394
        fNewConnectionButton.addSelectionListener(new SelectionListener() {
395
			public void widgetDefaultSelected(SelectionEvent e) {
396
				widgetSelected(e);
397
			}
398
399
			public void widgetSelected(SelectionEvent e) {
400
				IRemoteUIConnectionManager connectionManager = getUIConnectionManager();
401
				if(connectionManager != null) {
402
					connectionManager.newConnection(fNewConnectionButton.getShell());
403
				}
404
				// refresh list of connections
405
				populateConnectionCombo(fConnectionCombo);
406
			}
407
        });
408
        
409
        Label locationLabel = new Label(container, SWT.LEFT);
410
        locationLabel.setText("Location:"); //$NON-NLS-1$
411
        
412
        fLocationText = new Text(container, SWT.SINGLE | SWT.BORDER);
413
		gd = new GridData(GridData.FILL_HORIZONTAL);
414
		gd.horizontalSpan = 1;
415
		gd.grabExcessHorizontalSpace = true;
416
		gd.widthHint = 250;
417
		fLocationText.setLayoutData(gd);
418
		fLocationText.addModifyListener(new ModifyListener() {
419
			public void modifyText(ModifyEvent e) {
420
				fErrorReporter.reportError(checkValidLocation(), false);
421
			}
422
		});
423
		
424
        // new connection button
425
        fBrowseButton = new Button(container, SWT.PUSH);
426
        fBrowseButton.setText("Browse..."); //$NON-NLS-1$
427
        fBrowseButton.addSelectionListener(new SelectionListener() {
428
			public void widgetDefaultSelected(SelectionEvent e) {
429
				widgetSelected(e);
430
			}
431
432
			public void widgetSelected(SelectionEvent e) {
433
				if (fSelectedConnection != null) {
434
					checkConnection();
435
					if (fSelectedConnection.isOpen()) {
436
						IRemoteUIServices remoteUIServices = PTPRemoteUIPlugin.getDefault().getRemoteUIServices(fSelectedProvider);
437
						if (remoteUIServices != null) {
438
							IRemoteUIFileManager fileMgr = remoteUIServices.getUIFileManager();
439
							if (fileMgr != null) {
440
								fileMgr.setConnection(fSelectedConnection);
441
								String correctPath = fLocationText.getText();
442
								IPath selectedPath = fileMgr.browseDirectory(fLocationText.getShell(), "Project Location (" + fSelectedConnection.getName() + ")", correctPath); //$NON-NLS-1$ //$NON-NLS-2$
443
								if (selectedPath != null) {
444
									fLocationText.setText(selectedPath.toString());
445
								}
446
							}
447
						}
448
					}
449
				}
450
			}
451
        });
452
453
        return container;
454
    }
455
	
456
	/* (non-Javadoc)
457
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
458
	 */
459
	protected void okPressed() {
460
		
461
		// set the provider
462
		fProvider.setRemoteToolsProviderID(fSelectedProvider.getId());
463
		fProvider.setRemoteToolsConnection(fSelectedConnection);
464
465
	}
466
	
467
	public IRemoteServices getRemoteServices() {
468
		return fSelectedProvider;
469
	}
470
	
471
	public IRemoteConnection getRemoteConnection() {
472
		return fSelectedConnection;
473
	}
474
	
475
	/**
476
	 * Return the location for the project. 
477
	 * 
478
	 * @return String
479
	 */
480
	public String getProjectLocation() {
481
		return fLocationText.getText();
482
	}
483
	
484
	/**
485
	 * Returns the name of the selected connection.
486
	 */
487
	public IRemoteConnection getConnection() {
488
		return fSelectedConnection;
489
	}
490
}

Return to bug 283402