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 293929 | Differences between
and this patch

Collapse All | Expand All

(-)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 18-25 Link Here
18
import org.eclipse.cdt.core.CCorePlugin;
18
import org.eclipse.cdt.core.CCorePlugin;
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.internal.ui.wizards.ICDTCommonProjectWizard;
21
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
22
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
22
import org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard;
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.ServiceProviderConfigurationWidget;
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
		ServiceProviderConfigurationWidget widget = (ServiceProviderConfigurationWidget)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/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/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/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/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/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/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.ServiceProviderConfigurationWidget;
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
    ServiceProviderConfigurationWidget 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 ServiceProviderConfigurationWidget(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/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
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/ServiceModelWizardPage.java (-28 / +126 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.viewers.ISelectionChangedListener;
23
import org.eclipse.jface.viewers.SelectionChangedEvent;
22
import org.eclipse.jface.wizard.IWizardPage;
24
import org.eclipse.jface.wizard.IWizardPage;
23
import org.eclipse.ptp.internal.rdt.ui.RDTHelpContextIds;
25
import org.eclipse.ptp.internal.rdt.ui.RSEUtils;
26
import org.eclipse.ptp.rdt.core.services.IRDTServiceConstants;
24
import org.eclipse.ptp.rdt.ui.messages.Messages;
27
import org.eclipse.ptp.rdt.ui.messages.Messages;
28
import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteBuildServiceProvider;
29
import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteCIndexServiceProvider;
30
import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteCIndexServiceProvider2;
31
import org.eclipse.ptp.rdt.ui.subsystems.DStoreServerDefaults;
32
import org.eclipse.ptp.remote.core.IRemoteConnection;
33
import org.eclipse.ptp.remote.core.IRemoteServices;
25
import org.eclipse.ptp.services.core.IService;
34
import org.eclipse.ptp.services.core.IService;
26
import org.eclipse.ptp.services.core.IServiceConfiguration;
35
import org.eclipse.ptp.services.core.IServiceConfiguration;
36
import org.eclipse.ptp.services.core.IServiceModelManager;
37
import org.eclipse.ptp.services.core.IServiceProviderDescriptor;
27
import org.eclipse.ptp.services.core.ServiceModelManager;
38
import org.eclipse.ptp.services.core.ServiceModelManager;
28
import org.eclipse.ptp.services.ui.widgets.ServiceProviderConfigurationWidget;
39
import org.eclipse.ptp.services.ui.widgets.AddServiceConfigurationWidget;
40
import org.eclipse.rse.connectorservice.dstore.DStoreConnectorService;
41
import org.eclipse.rse.core.model.IHost;
42
import org.eclipse.rse.core.subsystems.IConnectorService;
29
import org.eclipse.swt.SWT;
43
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.graphics.Image;
44
import org.eclipse.swt.graphics.Image;
45
import org.eclipse.swt.layout.GridData;
46
import org.eclipse.swt.layout.GridLayout;
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;
34
49
35
/**
50
/**
36
 * 
51
 * 
Lines 39-63 Link Here
39
 * that it will remain the same. Please do not use this API without consulting
54
 * that it will remain the same. Please do not use this API without consulting
40
 * with the RDT team.
55
 * with the RDT team.
41
 * 
56
 * 
42
 * @author crecoskie
43
 *
57
 *
44
 */
58
 */
45
public class ServiceModelWizardPage extends MBSCustomPage {
59
public class ServiceModelWizardPage extends MBSCustomPage {
46
	public static final String SERVICE_MODEL_WIZARD_PAGE_ID = "org.eclipse.ptp.rdt.ui.serviceModelWizardPage"; //$NON-NLS-1$
60
	public static final String SERVICE_MODEL_WIZARD_PAGE_ID = "org.eclipse.ptp.rdt.ui.serviceModelWizardPage"; //$NON-NLS-1$
47
	public static final String DEFAULT_CONFIG = Messages.getString("ConfigureRemoteServices.0"); //$NON-NLS-1$
61
	public static final String DEFAULT_CONFIG = Messages.getString("ConfigureRemoteServices.0"); //$NON-NLS-1$
48
	
62
	public static final String CONFIG_PROPERTY = "org.eclipse.ptp.rdt.ui.ServiceModelWizardPage.serviceConfig"; //$NON-NLS-1$
49
	public static final String SERVICE_MODEL_WIDGET_PROPERTY = "org.eclipse.ptp.rdt.ui.ServiceModelWizardPage.serviceModelWidget"; //$NON-NLS-1$
50
63
51
	boolean fbVisited;
64
	boolean fbVisited;
52
	private String fTitle;
65
	private String fTitle;
53
	private String fDescription;
66
	private String fDescription;
54
	private ImageDescriptor fImageDescriptor;
67
	private ImageDescriptor fImageDescriptor;
55
	private Image fImage;
68
	private Image fImage;
56
	private Control fCanvas;
69
	private IServiceConfiguration fNewConfig;
57
	private IServiceConfiguration fConfig;
70
	private Control pageControl;
58
	private ServiceProviderConfigurationWidget fModelWidget;
71
	
72
	private AddServiceConfigurationWidget serviceConfigWidget;
59
	
73
	
60
61
	public ServiceModelWizardPage(String pageID) {
74
	public ServiceModelWizardPage(String pageID) {
62
		super(pageID);
75
		super(pageID);
63
	}
76
	}
Lines 80-85 Link Here
80
		return allApplicableServices;
93
		return allApplicableServices;
81
	}
94
	}
82
	
95
	
96
	
83
	/**
97
	/**
84
	 * 
98
	 * 
85
	 */
99
	 */
Lines 104-143 Link Here
104
	/* (non-Javadoc)
118
	/* (non-Javadoc)
105
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
119
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
106
	 */
120
	 */
107
	public void createControl(Composite parent) {
121
	public void createControl(final Composite parent) {
108
		fCanvas = parent; // TODO
122
		Composite comp = new Composite(parent, SWT.NONE);
109
		fModelWidget = new ServiceProviderConfigurationWidget(parent, SWT.NONE);
123
		comp.setLayout(new GridLayout(1, false));
110
		
124
		comp.setLayoutData(new GridData(GridData.FILL_BOTH));
111
		MBSCustomPageManager.addPageProperty(pageID, SERVICE_MODEL_WIDGET_PROPERTY, fModelWidget);
125
		pageControl = comp;
126
127
        serviceConfigWidget = new AddServiceConfigurationWidget(comp, SWT.NONE);
128
        GridData data = new GridData(GridData.FILL_BOTH);
129
        serviceConfigWidget.setLayoutData(data);
130
        serviceConfigWidget.addSelectionChangedListener(new ISelectionChangedListener() {
131
			public void selectionChanged(SelectionChangedEvent event) {
132
				updateConfigPageProperty();
133
			}
134
        });
135
        serviceConfigWidget.setDefaultConfiguration(getNewConfiguration());
136
        serviceConfigWidget.setSelection(true);
137
        
138
		updateConfigPageProperty();
139
	}
140
	
141
	private void updateConfigPageProperty() {
142
		IServiceConfiguration config = serviceConfigWidget.getServiceConfiguration();
143
		MBSCustomPageManager.addPageProperty(
144
				SERVICE_MODEL_WIZARD_PAGE_ID, CONFIG_PROPERTY, config);
112
		
145
		
113
		String configName = DEFAULT_CONFIG;
146
	}
147
	
148
	private String getDefaultConfigName() {
149
		String candidateName = DEFAULT_CONFIG;
114
		IWizardPage page = getWizard().getStartingPage();
150
		IWizardPage page = getWizard().getStartingPage();
115
		if(page instanceof CDTMainWizardPage) {
151
		if(page instanceof NewRemoteProjectCreationPage) {
116
			CDTMainWizardPage cdtPage = (CDTMainWizardPage) page;
152
			NewRemoteProjectCreationPage cdtPage = (NewRemoteProjectCreationPage) page;
117
			configName = cdtPage.getProjectName();
153
			candidateName = cdtPage.getRemoteConnection().getName();
118
		}
154
		}
119
		
155
		
120
		fConfig = ServiceModelManager.getInstance().newServiceConfiguration(configName);
156
		Set<IServiceConfiguration> configs = ServiceModelManager.getInstance().getConfigurations();
157
		Set<String> existingNames = new HashSet<String>();
158
		for(IServiceConfiguration config : configs) {
159
			existingNames.add(config.getName());
160
		}
121
		
161
		
122
		fModelWidget.setServiceConfiguration(fConfig);
162
		int i = 2;
163
		String newConfigName = candidateName;
164
		while(existingNames.contains(newConfigName)) {
165
			newConfigName = candidateName + " (" + (i++) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
166
		}
123
		
167
		
124
		Control control = fModelWidget.getParent().getShell(); //get the shell or doesn't display help correctly
168
		return newConfigName;
125
		PlatformUI.getWorkbench().getHelpSystem().setHelp(control,RDTHelpContextIds.SERVICE_MODEL_WIZARD);
126
	}
169
	}
127
170
	
171
	/**
172
	 * Creates a new configuration with the RDT defaults.
173
	 */
174
	private IServiceConfiguration getNewConfiguration() {
175
		if(fNewConfig == null) {
176
			IServiceModelManager smm = ServiceModelManager.getInstance();
177
			fNewConfig = smm.newServiceConfiguration(getDefaultConfigName());
178
			
179
			IWizardPage page = getWizard().getStartingPage();
180
			if(page instanceof NewRemoteProjectCreationPage) {
181
				NewRemoteProjectCreationPage cdtPage = (NewRemoteProjectCreationPage) page;
182
				IRemoteServices remoteServices = cdtPage.getRemoteServices();
183
				IRemoteConnection remoteConnection = cdtPage.getRemoteConnection();
184
				
185
				IService buildService = smm.getService(IRDTServiceConstants.SERVICE_BUILD);
186
				IServiceProviderDescriptor descriptor = buildService.getProviderDescriptor(RemoteBuildServiceProvider.ID);
187
				RemoteBuildServiceProvider rbsp = (RemoteBuildServiceProvider)smm.getServiceProvider(descriptor);
188
				rbsp.setRemoteToolsProviderID(remoteServices.getId());
189
				rbsp.setRemoteToolsConnection(remoteConnection);
190
				fNewConfig.setServiceProvider(buildService, rbsp);
191
			
192
				if (remoteServices.getId().equals("org.eclipse.ptp.remote.RSERemoteServices")) { //$NON-NLS-1$
193
					IService indexingService = smm.getService(IRDTServiceConstants.SERVICE_C_INDEX);
194
					descriptor = indexingService.getProviderDescriptor(RemoteCIndexServiceProvider.ID);
195
					RemoteCIndexServiceProvider rcisp = (RemoteCIndexServiceProvider) smm.getServiceProvider(descriptor);
196
					
197
					String hostName = remoteConnection.getAddress();
198
					IHost host = RSEUtils.getConnection(hostName);
199
					String configPath = RSEUtils.getDefaultConfigDirectory(host);
200
					
201
					rcisp.setConnection(host, getDStoreConnectorService(host));
202
					rcisp.setIndexLocation(configPath);
203
					rcisp.setConfigured(true);
204
					fNewConfig.setServiceProvider(indexingService, rcisp);
205
				} else if (remoteServices.getId().equals("org.eclipse.ptp.remote.RemoteTools")) { //$NON-NLS-1$
206
					IService indexingService = smm.getService(IRDTServiceConstants.SERVICE_C_INDEX);
207
					descriptor = indexingService.getProviderDescriptor(RemoteCIndexServiceProvider2.ID);
208
					RemoteCIndexServiceProvider2 rcisp = (RemoteCIndexServiceProvider2) smm.getServiceProvider(descriptor);
209
					rcisp.setConnection(remoteServices, remoteConnection);
210
					rcisp.setDStoreCommand(DStoreServerDefaults.COMMAND);
211
					rcisp.setDStoreEnv("CLASSPATH=" + DStoreServerDefaults.CLASSPATH); //$NON-NLS-1$
212
					fNewConfig.setServiceProvider(indexingService, rcisp);
213
				}
214
			}
215
		}
216
		
217
		return fNewConfig;
218
	}
219
	
220
	private IConnectorService getDStoreConnectorService(IHost host) {
221
		for(IConnectorService cs : host.getConnectorServices()) {
222
			if(cs instanceof DStoreConnectorService)
223
				return cs;
224
		}
225
		return null;
226
	}
227
	
128
	/* (non-Javadoc)
228
	/* (non-Javadoc)
129
	 * @see org.eclipse.jface.dialogs.IDialogPage#dispose()
229
	 * @see org.eclipse.jface.dialogs.IDialogPage#dispose()
130
	 */
230
	 */
131
	public void dispose() {
231
	public void dispose() {
132
		// TODO Auto-generated method stub
232
		// TODO Auto-generated method stub
133
134
	}
233
	}
135
234
136
	/* (non-Javadoc)
235
	/* (non-Javadoc)
137
	 * @see org.eclipse.jface.dialogs.IDialogPage#getControl()
236
	 * @see org.eclipse.jface.dialogs.IDialogPage#getControl()
138
	 */
237
	 */
139
	public Control getControl() {
238
	public Control getControl() {
140
		return fModelWidget;
239
		return pageControl;
141
	}
240
	}
142
241
143
	/* (non-Javadoc)
242
	/* (non-Javadoc)
Lines 226-232 Link Here
226
		if(visible) {
325
		if(visible) {
227
			fbVisited = true;
326
			fbVisited = true;
228
		}
327
		}
229
		fCanvas.setVisible(visible);
230
	}
328
	}
231
329
232
330
(-)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/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/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/UIPlugin.java (+2 lines)
Lines 17-22 Link Here
17
import org.eclipse.core.runtime.Preferences;
17
import org.eclipse.core.runtime.Preferences;
18
import org.eclipse.core.runtime.Status;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.ptp.rdt.ui.serviceproviders.IndexLocationChangeListener;
19
import org.eclipse.ptp.rdt.ui.serviceproviders.IndexLocationChangeListener;
20
import org.eclipse.ptp.rdt.ui.subsystems.DStoreServerDefaults;
20
import org.eclipse.swt.widgets.Display;
21
import org.eclipse.swt.widgets.Display;
21
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
22
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
22
import org.osgi.framework.BundleContext;
23
import org.osgi.framework.BundleContext;
Lines 64-69 Link Here
64
		
65
		
65
		IndexLocationChangeListener.startListening();
66
		IndexLocationChangeListener.startListening();
66
		turnOffIndexerAnnotations();
67
		turnOffIndexerAnnotations();
68
		DStoreServerDefaults.loadDefaults();
67
	}
69
	}
68
	
70
	
69
	
71
	
(-)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
(-)plugin.xml (-21 / +14 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">
Lines 188-193 Link Here
188
            priority="1"
170
            priority="1"
189
            serviceId="org.eclipse.ptp.rdt.core.BuildService">
171
            serviceId="org.eclipse.ptp.rdt.core.BuildService">
190
      </provider>
172
      </provider>
173
      <provider
174
            class="org.eclipse.ptp.rdt.ui.serviceproviders.RemoteCIndexServiceProvider2"
175
            id="org.eclipse.ptp.rdt.ui.RemoteCIndexServiceProvider2"
176
            name="Remote Tools C/C++ Indexing Service"
177
            priority="1"
178
            serviceId="org.eclipse.ptp.rdt.core.CIndexingService">
179
      </provider>
191
   </extension>
180
   </extension>
192
   <extension
181
   <extension
193
         id="org.eclipse.ptp.rdt.core.remoteNature"
182
         id="org.eclipse.ptp.rdt.core.remoteNature"
Lines 628-633 Link Here
628
              configurationUIClass="org.eclipse.ptp.rdt.ui.wizards.RemoteServicesServiceProviderConfigurer"
617
              configurationUIClass="org.eclipse.ptp.rdt.ui.wizards.RemoteServicesServiceProviderConfigurer"
629
              id="org.eclipse.ptp.rdt.ui.RemoteBuildServiceProvider">
618
              id="org.eclipse.ptp.rdt.ui.RemoteBuildServiceProvider">
630
        </providerContributor>
619
        </providerContributor>
620
        <providerContributor
621
              class="org.eclipse.ptp.rdt.ui.wizards.RemoteCIndexServiceProvider2Contributer"
622
              id="org.eclipse.ptp.rdt.ui.RemoteCIndexServiceProvider2">
623
        </providerContributor>
631
     </extension>
624
     </extension>
632
     <extension
625
     <extension
633
           point="org.eclipse.ptp.services.core.serviceCategories">
626
           point="org.eclipse.ptp.services.core.serviceCategories">
(-)src/org/eclipse/ptp/rdt/ui/subsystems/DStoreServerRunner.java (+287 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
package org.eclipse.ptp.rdt.ui.subsystems;
9
10
import java.io.BufferedReader;
11
import java.io.IOException;
12
import java.io.InputStreamReader;
13
import java.util.Arrays;
14
import java.util.HashMap;
15
import java.util.List;
16
import java.util.Map;
17
18
import org.eclipse.core.filesystem.IFileStore;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.Status;
23
import org.eclipse.core.runtime.jobs.Job;
24
import org.eclipse.dstore.core.client.ClientConnection;
25
import org.eclipse.dstore.core.client.ConnectionStatus;
26
import org.eclipse.dstore.core.model.DataStore;
27
import org.eclipse.osgi.util.NLS;
28
import org.eclipse.ptp.rdt.ui.UIPlugin;
29
import org.eclipse.ptp.remote.core.IRemoteConnection;
30
import org.eclipse.ptp.remote.core.IRemoteFileManager;
31
import org.eclipse.ptp.remote.core.IRemoteProcess;
32
import org.eclipse.ptp.remote.core.IRemoteProcessBuilder;
33
import org.eclipse.ptp.remote.core.IRemoteServices;
34
import org.eclipse.ptp.remote.core.exception.RemoteConnectionException;
35
36
public class DStoreServerRunner extends Job {
37
	public enum DStoreServerState {STARTING, RUNNING, FINISHED, ERROR}
38
39
	private boolean DEBUG = true;
40
	
41
	private List<String> fCommand;
42
43
	private String workDir = null;
44
	private Map<String, String> fEnv = new HashMap<String, String>();
45
	private DStoreServerState fServerState = DStoreServerState.STARTING;
46
	private IRemoteServices fRemoteServices;
47
48
	private IRemoteConnection fRemoteConnection;
49
	private IRemoteProcess fRemoteProcess;
50
	private ClientConnection fDStoreConnection = null;
51
	private int fPort;
52
	private static final String fSuccessString = "Server Started Successfully"; //$NON-NLS-1$
53
54
	public DStoreServerRunner(IRemoteServices services, IRemoteConnection connection) {
55
		super("DStoreServerRunner"); //$NON-NLS-1$
56
		setPriority(Job.LONG);
57
		setSystem(!DEBUG);
58
		fRemoteServices = services;
59
		fRemoteConnection = connection;
60
	}
61
62
	public DataStore getDataStore() {
63
		if (fDStoreConnection == null) {
64
			fDStoreConnection = new ClientConnection(fRemoteConnection.getName());
65
		}
66
		return fDStoreConnection.getDataStore();
67
	}
68
69
	public synchronized DStoreServerState getServerState() {
70
		return fServerState;
71
	}
72
73
	public void setCommand(String command) {
74
		if (command != null) {
75
			fCommand = Arrays.asList(command.split(" ")); //$NON-NLS-1$
76
		}
77
	}
78
79
	public void setEnv(String env) {
80
		if (env != null) {
81
			for (String vars : env.split("\n")) { //$NON-NLS-1$
82
				String[] envVar = vars.split("="); //$NON-NLS-1$
83
				if (envVar.length == 2) {
84
					fEnv.put(envVar[0], envVar[1]);
85
				}
86
			}
87
		}
88
	}
89
90
	public void setWorkDir(String workDir) {
91
		this.workDir = workDir;
92
	}
93
	
94
	public synchronized boolean startServer() {
95
		if (fServerState == DStoreServerState.RUNNING) {
96
			return false;
97
		}
98
		if (fServerState == DStoreServerState.FINISHED || 
99
				fServerState == DStoreServerState.ERROR) {
100
			setServerState(DStoreServerState.STARTING);
101
			fPort = 0;
102
		}
103
		if (!fRemoteConnection.isOpen()) {
104
			try {
105
				fRemoteConnection.open(null);
106
			} catch (RemoteConnectionException e) {
107
				e.printStackTrace();
108
				return false;
109
			}
110
		}
111
		schedule();
112
		while (getServerState() == DStoreServerState.STARTING) {
113
			try {
114
				wait(500);
115
			} catch (InterruptedException e) {
116
				if (DStoreServerDefaults.DSTORE_TRACING) {
117
					System.err.println("DSTORE SERVER: InterruptedException " + e.getLocalizedMessage()); //$NON-NLS-1$
118
				}
119
				return false;
120
			}
121
		}
122
		if (fServerState == DStoreServerState.RUNNING) {
123
			int port;
124
			try {
125
				port = fRemoteConnection.forwardLocalPort("localhost", fPort, null); //$NON-NLS-1$
126
			} catch (RemoteConnectionException e) {
127
				if (DStoreServerDefaults.DSTORE_TRACING) {
128
					System.err.println("DSTORE SERVER: port fowarding failed " + e.getLocalizedMessage()); //$NON-NLS-1$
129
				}
130
				return false;
131
			}
132
			fDStoreConnection.setHost("localhost"); //$NON-NLS-1$
133
			fDStoreConnection.setPort(Integer.toString(port));
134
			ConnectionStatus status = fDStoreConnection.connect(null, 0);
135
			DataStore dataStore = fDStoreConnection.getDataStore();
136
			dataStore.showTicket(null);
137
			dataStore.registerLocalClassLoader(getClass().getClassLoader());
138
			return status.isConnected();
139
		}
140
		return false;
141
	}
142
	
143
	@Override
144
	protected void canceling() {
145
		terminateServer();
146
	}
147
148
	@Override
149
	protected IStatus run(IProgressMonitor monitor) {
150
		assert fCommand != null;
151
		assert fRemoteProcess == null;
152
153
		/*
154
		 * Catch all try...catch
155
		 */
156
		try {
157
			if (monitor.isCanceled()) {
158
				return Status.CANCEL_STATUS;
159
			}
160
			/*
161
			 * Prepare remote connection.
162
			 */
163
			IRemoteFileManager fileManager = fRemoteServices.getFileManager(fRemoteConnection);
164
165
			IFileStore directory = null;
166
			if (workDir != null) {
167
				directory = fileManager.getResource(workDir);
168
			}
169
			IRemoteProcessBuilder builder = fRemoteServices.getProcessBuilder(fRemoteConnection, fCommand);
170
			if (directory != null) {
171
				builder.directory(directory);
172
			}
173
			
174
			builder.environment().putAll(fEnv);
175
176
			/*
177
			 * Create process.
178
			 */
179
			if (monitor.isCanceled()) {
180
				return Status.CANCEL_STATUS;
181
			}
182
			
183
			synchronized (this) {
184
				fRemoteProcess = builder.start();
185
			}
186
			
187
			if (DStoreServerDefaults.DSTORE_TRACING) {
188
				final BufferedReader stdout = new BufferedReader(new InputStreamReader(fRemoteProcess.getInputStream()));
189
				new Thread(new Runnable() {
190
					public void run() {
191
						try {
192
							String output;
193
							while ((output = stdout.readLine()) != null) {
194
								System.out.println("DSTORE SERVER stdout: " + output); //$NON-NLS-1$
195
							}
196
						} catch (IOException e) {
197
							// Ignore
198
						}
199
					}
200
				}, "dstore server stdout").start();  //$NON-NLS-1$
201
			}
202
203
			final BufferedReader stderr = new BufferedReader(new InputStreamReader(fRemoteProcess.getErrorStream()));
204
			new Thread(new Runnable() {
205
				public void run() {
206
					try {
207
						String output;
208
						while ((output = stderr.readLine()) != null) {
209
							if (getServerState() == DStoreServerState.STARTING && output.startsWith(fSuccessString)) {
210
								if ((output = stderr.readLine()) != null && output.matches("^[0-9]+$")) { //$NON-NLS-1$
211
									fPort = Integer.parseInt(output);
212
									setServerState(DStoreServerState.RUNNING);
213
									if (DStoreServerDefaults.DSTORE_TRACING) {
214
										System.err.println("DSTORE SERVER started on port " + output); //$NON-NLS-1$
215
									}
216
								}
217
							}
218
							if (DStoreServerDefaults.DSTORE_TRACING) {
219
								System.err.println("DSTORE SERVER stderr: " + output);  //$NON-NLS-1$
220
							}
221
						}
222
					} catch (IOException e) {
223
						// Ignore
224
					}
225
				}
226
			}, "dstore server stderr").start();  //$NON-NLS-1$
227
228
			/*
229
			 * Wait while running but not canceled.
230
			 */
231
			while (!fRemoteProcess.isCompleted() && !monitor.isCanceled()) {
232
				synchronized (this) {
233
					try {
234
						wait(500);
235
					} catch (InterruptedException e) {
236
						// Ignore interrupt;
237
					}
238
				}
239
			}
240
			
241
			try {
242
				fRemoteProcess.waitFor();
243
			} catch (InterruptedException e) {
244
				// Do nothing
245
			}
246
247
			/*
248
			 * Check if process terminated successfully (if not canceled).
249
			 */
250
			if (fRemoteProcess.exitValue() != 0) {
251
				if (!monitor.isCanceled()) {
252
					throw new CoreException(new Status(IStatus.ERROR, UIPlugin.getPluginId(), NLS.bind("DStore server finished with exit code {0}", fRemoteProcess.exitValue()))); //$NON-NLS-1$
253
				}
254
			}
255
			setServerState(DStoreServerState.FINISHED);
256
			return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
257
		} catch (CoreException e) {
258
			setServerState(DStoreServerState.ERROR);
259
			return e.getStatus();
260
		} catch (IOException e) {
261
			setServerState(DStoreServerState.ERROR);
262
			return new Status(IStatus.ERROR, UIPlugin.getPluginId(), "failed to start dstore server", e); //$NON-NLS-1$
263
		} finally {
264
			synchronized (this) {
265
				fRemoteProcess = null;
266
				if (fDStoreConnection != null) {
267
					fDStoreConnection.disconnect();
268
					fDStoreConnection = null;
269
				}
270
			}
271
		}
272
	}
273
	
274
	protected synchronized void setServerState(DStoreServerState state) {
275
		if (DStoreServerDefaults.DSTORE_TRACING) {
276
			System.err.println("DSTORE SERVER new state: " + state.toString()); //$NON-NLS-1$
277
		}
278
		fServerState = state;
279
		this.notifyAll();
280
	}
281
282
	protected synchronized void terminateServer() {
283
		if (fServerState == DStoreServerState.RUNNING && fRemoteProcess != null) {
284
			fRemoteProcess.destroy();
285
		}
286
	}
287
}
(-)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/DStoreIndexPage.java (+74 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
package org.eclipse.ptp.rdt.ui.wizards;
9
10
import org.eclipse.core.runtime.ListenerList;
11
import org.eclipse.ptp.rdt.ui.messages.Messages;
12
import org.eclipse.ptp.rdt.ui.wizards.DStoreServerWidget.FieldModifier;
13
import org.eclipse.ptp.remote.core.IRemoteConnection;
14
import org.eclipse.ptp.remote.core.IRemoteServices;
15
import org.eclipse.ptp.remote.ui.widgets.RemoteDirectoryWidget;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.ModifyEvent;
18
import org.eclipse.swt.events.ModifyListener;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.layout.GridLayout;
21
import org.eclipse.swt.widgets.Composite;
22
23
public class DStoreIndexPage extends Composite {
24
	private String fDefaultPath = null;
25
	private RemoteDirectoryWidget fDirectoryWidget;
26
	private ListenerList modifyListeners = new ListenerList();
27
	
28
	public DStoreIndexPage(Composite parent, int style) {
29
		super(parent, style);
30
		
31
		GridLayout layout = new GridLayout(2, false);
32
		setLayout(layout);
33
		setLayoutData(new GridData(GridData.FILL_BOTH));
34
		
35
		fDirectoryWidget = new RemoteDirectoryWidget(this, SWT.NONE, Messages.getString("IndexFileLocationWidget.0"), fDefaultPath); //$NON-NLS-1$
36
		fDirectoryWidget.setBrowseMessage("Select Index File Location"); //$NON-NLS-1$
37
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
38
        data.horizontalSpan = 3;
39
        fDirectoryWidget.setLayoutData(data); // set layout to grab horizontal space
40
        fDirectoryWidget.addModifyListener(new ModifyListener() {
41
			public void modifyText(ModifyEvent e) {
42
				fDefaultPath = fDirectoryWidget.getLocationPath();
43
				e.data = FieldModifier.VALUE_INDEX_LOCATION;
44
				notifyListeners(e);
45
			}
46
		});
47
	}
48
	
49
	public void addModifyListener(ModifyListener listener) {
50
		modifyListeners.add(listener);
51
	}
52
53
	public String getLocationPath() {
54
		return fDirectoryWidget.getLocationPath();
55
	}
56
	
57
	public void removeModifyListener(ModifyListener listener) {
58
		modifyListeners.remove(listener);
59
	}
60
	
61
	public void setConnection(IRemoteServices services, IRemoteConnection conn) {
62
		fDirectoryWidget.setConnection(services, conn);
63
	}
64
65
	public void setLocationPath(String path) {
66
		fDirectoryWidget.setLocationPath(path);
67
	}
68
	
69
	private void notifyListeners(ModifyEvent e) {
70
		for (Object listener : modifyListeners.getListeners()) {
71
			((ModifyListener)listener).modifyText(e);
72
		}
73
	}
74
}
(-)src/org/eclipse/ptp/rdt/ui/subsystems/DStoreServerDefaults.java (+107 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation.
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
package org.eclipse.ptp.rdt.ui.subsystems;
12
13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.util.Properties;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.FileLocator;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.Path;
21
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.core.runtime.Status;
23
import org.eclipse.osgi.util.NLS;
24
import org.eclipse.ptp.rdt.ui.UIPlugin;
25
import org.osgi.framework.Bundle;
26
27
public class DStoreServerDefaults {
28
29
	public static String COMMAND = null;
30
	public static String CLASSPATH = null;
31
	public static boolean DSTORE_TRACING = false;
32
33
	private static final String DEFAULTS_RESOURCE_PATH = "/data/dstore-server.properties"; //$NON-NLS-1$
34
	private static final String DSTORE_TRACING_OPTION = "org.eclipse.ptp.rdt.ui/debug/dstore/tracing"; //$NON-NLS-1$
35
36
	public static void loadDefaults() throws CoreException {
37
		if (UIPlugin.getDefault().isDebugging()) {
38
			String option = Platform.getDebugOption(DSTORE_TRACING_OPTION);
39
			if (option != null) {
40
				DSTORE_TRACING = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
41
			}
42
		}
43
		
44
		Bundle bundle = UIPlugin.getDefault().getBundle();
45
		Properties properties = read(new Path(DEFAULTS_RESOURCE_PATH), bundle);
46
47
		COMMAND = getString(bundle, properties, "COMMAND"); //$NON-NLS-1$
48
		CLASSPATH = getString(bundle, properties, "CLASSPATH"); //$NON-NLS-1$
49
50
		assert COMMAND != null;
51
		assert CLASSPATH != null;
52
	}
53
54
	public static Properties read(Path defaultsPropertiesPath, Bundle bundle)
55
			throws CoreException {
56
		InputStream inStream;
57
		Properties properties = new Properties();
58
		try {
59
			inStream = FileLocator.openStream(bundle, defaultsPropertiesPath,
60
					false);
61
			properties.load(inStream);
62
63
		} catch (IOException e) {
64
			throw new CoreException(new Status(IStatus.ERROR, bundle
65
					.getSymbolicName(),
66
					"Failed to read DStore Server properties file")); //$NON-NLS-1$
67
		}
68
		return properties;
69
	}
70
71
	public static String getString(Bundle bundle, Properties properties,
72
			String key) throws CoreException {
73
		String value = properties.getProperty(key);
74
		if (value == null) {
75
			throw new CoreException(
76
					new Status(
77
							IStatus.ERROR,
78
							bundle.getSymbolicName(),
79
							NLS
80
									.bind(
81
											"Missing default value for {0} while reading DStore Server properties", key))); //$NON-NLS-1$
82
		}
83
		return value;
84
	}
85
86
	public static int getInteger(Bundle bundle, Properties properties,
87
			String key) throws CoreException {
88
		String value = getString(bundle, properties, key);
89
		try {
90
			return Integer.parseInt(value);
91
		} catch (NumberFormatException e) {
92
			throw new CoreException(
93
					new Status(
94
							IStatus.ERROR,
95
							bundle.getSymbolicName(),
96
							NLS
97
									.bind(
98
											"Invalid value for {0} while reading DStore Server properties", key))); //$NON-NLS-1$
99
		}
100
	}
101
102
	public static boolean getBoolean(Bundle bundle, Properties properties,
103
			String key) throws CoreException {
104
		String value = getString(bundle, properties, key);
105
		return Boolean.parseBoolean(value);
106
	}
107
}
(-)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/DStoreServerPage.java (+104 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
package org.eclipse.ptp.rdt.ui.wizards;
9
10
import org.eclipse.core.runtime.ListenerList;
11
import org.eclipse.ptp.rdt.ui.wizards.DStoreServerWidget.FieldModifier;
12
import org.eclipse.ptp.remote.core.IRemoteConnection;
13
import org.eclipse.ptp.remote.core.IRemoteServices;
14
import org.eclipse.ptp.remote.ui.widgets.RemoteDirectoryWidget;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.events.ModifyEvent;
17
import org.eclipse.swt.events.ModifyListener;
18
import org.eclipse.swt.layout.GridData;
19
import org.eclipse.swt.layout.GridLayout;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Group;
22
import org.eclipse.swt.widgets.Label;
23
import org.eclipse.swt.widgets.Text;
24
25
public class DStoreServerPage extends Composite {
26
	private Text text;
27
	
28
	private RemoteDirectoryWidget fLocationWidget;
29
	private ListenerList modifyListeners = new ListenerList();
30
	
31
	public DStoreServerPage(Composite parent, int style) {
32
		super(parent, style);
33
		
34
		GridLayout layout = new GridLayout(1, false);
35
		setLayout(layout);
36
		setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
37
		
38
		fLocationWidget = new RemoteDirectoryWidget(this, SWT.NONE, "DStore Location", null); //$NON-NLS-1$
39
		fLocationWidget.addModifyListener(new ModifyListener() {
40
			public void modifyText(ModifyEvent e) {
41
				e.data = FieldModifier.VALUE_DSTORE_LOCATION;
42
				notifyListeners(e);
43
			}
44
		});
45
		
46
		Group group = new Group(this, SWT.NONE);
47
		group.setText("Server Command"); //$NON-NLS-1$
48
		group.setLayout(new GridLayout(2, false));
49
		group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
50
51
		Composite textComp = new Composite(group, SWT.NONE);
52
		textComp.setLayout(new GridLayout(2, false));
53
		textComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
54
55
		Label label = new Label(textComp, SWT.NONE);
56
		label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
57
		label.setText("Command:"); //$NON-NLS-1$
58
		
59
		text = new Text(textComp, SWT.BORDER);
60
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
61
		data.heightHint = text.getLineHeight() * 3;
62
		text.setLayoutData(data);
63
		text.addModifyListener(new ModifyListener() {
64
			public void modifyText(ModifyEvent e) {
65
				e.data = FieldModifier.VALUE_DSTORE_COMMAND;
66
				notifyListeners(e);
67
			}
68
		});
69
	}
70
	
71
	public void addModifyListener(ModifyListener listener) {
72
		modifyListeners.add(listener);
73
	}
74
	
75
	public String getLocationPath() {
76
		return fLocationWidget.getLocationPath();
77
	}
78
	
79
	public String getServerCommand() {
80
		return text.getText();
81
	}
82
	
83
	public void removeModifyListener(ModifyListener listener) {
84
		modifyListeners.remove(listener);
85
	}
86
87
	public void setConnection(IRemoteServices services, IRemoteConnection conn) {
88
		fLocationWidget.setConnection(services, conn);
89
	}
90
91
	public void setLocationPath(String path) {
92
		fLocationWidget.setLocationPath(path);
93
	}
94
	
95
	public void setServerCommand(String command) {
96
		text.setText(command);
97
	}
98
	
99
	private void notifyListeners(ModifyEvent e) {
100
		for (Object listener : modifyListeners.getListeners()) {
101
			((ModifyListener)listener).modifyText(e);
102
		}
103
	}
104
}
(-)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/subsystems/StatusMonitor.java (+338 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002, 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
 * Initial Contributors:
9
 * The following IBM employees contributed to the Remote System Explorer
10
 * component that contains this file: David McKnight, Kushal Munir, 
11
 * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, 
12
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
13
 * 
14
 * Contributors:
15
 * Martin Oberhuber (Wind River) - [168870] refactor org.eclipse.rse.core package of the UI plugin
16
 * David McKnight   (IBM)        - [225902] [dstore] use C_NOTIFICATION command to wake up the server
17
 * David McKnight   (IBM)        - [229947] [dstore] interruption to Thread.sleep()  should not stop waitForUpdate()
18
 * David McKnight   (IBM)        - [231126] [dstore] status monitor needs to reset WaitThreshold on nudge
19
 * David McKnight   (IBM)        - [278341] [dstore] Disconnect on idle causes the client hang
20
 *******************************************************************************/
21
22
package org.eclipse.ptp.rdt.ui.subsystems;
23
24
import java.util.ArrayList;
25
import java.util.HashMap;
26
import java.util.List;
27
import java.util.Map;
28
29
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.dstore.core.model.DE;
31
import org.eclipse.dstore.core.model.DataElement;
32
import org.eclipse.dstore.core.model.DataStore;
33
import org.eclipse.dstore.core.model.DataStoreSchema;
34
import org.eclipse.dstore.extra.DomainEvent;
35
import org.eclipse.dstore.extra.IDomainListener;
36
import org.eclipse.ptp.remote.core.IRemoteConnection;
37
import org.eclipse.ptp.remote.core.IRemoteConnectionChangeEvent;
38
import org.eclipse.ptp.remote.core.IRemoteConnectionChangeListener;
39
import org.eclipse.swt.widgets.Display;
40
41
/*
42
 * This utility class can be used to monitor the status of one more more status DataElements.
43
 * Only one instanceof of this class is required per DataStore for use in monitoring statuses.
44
 * This is intended to be used in place of StatusChangeListeners
45
 * 
46
 *  * <p>
47
 * The following is one example of the use of the StatusMonitor. The code:
48
 * <blockquote><pre>
49
 *    		DataElement status = dataStore.command(dsCmd, args, deObj);
50
 *
51
 *			StatusMonitor smon = StatusMonitorFactory.getInstance().getStatusMonitorFor(getSystem(), ds);
52
 *			smon.waitForUpdate(status, monitor);
53
 * </pre></blockquote>
54
 */
55
public class StatusMonitor implements IDomainListener, IRemoteConnectionChangeListener {
56
57
	private static Map<IRemoteConnection, StatusMonitor> fMonitors = new HashMap<IRemoteConnection, StatusMonitor>();
58
	
59
	public static StatusMonitor getStatusMonitorFor(IRemoteConnection connection, DataStore store) {
60
		StatusMonitor monitor = fMonitors.get(connection);
61
		if (monitor == null) {
62
			monitor = new StatusMonitor(connection, store);
63
			fMonitors.put(connection, monitor);
64
		}
65
		return monitor;
66
	}
67
	
68
	protected IRemoteConnection fRemoteConnection;
69
70
	protected boolean fNetworkDown = false;
71
72
	protected List<DataElement> fWorkingStatuses = new ArrayList<DataElement>();
73
	protected List<DataElement> fCancelledStatuses = new ArrayList<DataElement>();
74
	protected List<DataElement> fDoneStatuses = new ArrayList<DataElement>();
75
76
	protected DataStore fDataStore;
77
78
	/**
79
	 * Construct a StatusChangeListener
80
	 * 
81
	 * @param system
82
	 *            the system associated with this monitor
83
	 * @param dataStore
84
	 *            the dataStore associated with this monitor
85
	 */
86
	public StatusMonitor(IRemoteConnection connection, DataStore dataStore) {
87
		fRemoteConnection = connection;
88
		fDataStore = dataStore;
89
		reInit();
90
	}
91
92
	/* (non-Javadoc)
93
	 * @see org.eclipse.ptp.remote.core.IRemoteConnectionChangeListener#connectionChanged(org.eclipse.ptp.remote.core.IRemoteConnectionChangeEvent)
94
	 */
95
	public void connectionChanged(IRemoteConnectionChangeEvent e) {
96
		if (e.getType() == IRemoteConnectionChangeEvent.CONNECTION_CLOSED ||
97
				e.getType() == IRemoteConnectionChangeEvent.CONNECTION_ABORTED) {
98
			fNetworkDown = true;
99
		}
100
	}
101
102
	public void dispose() {
103
		fRemoteConnection.removeConnectionChangeListener(this);
104
		fWorkingStatuses.clear();
105
		fDoneStatuses.clear();
106
		fCancelledStatuses.clear();
107
		fDataStore.getDomainNotifier().removeDomainListener(this);
108
	}
109
110
	/**
111
	 * @see IDomainListener#domainChanged(DomainEvent)
112
	 */
113
	public void domainChanged(DomainEvent event) {
114
		if (fWorkingStatuses.size() == 0) {
115
			return;
116
		}
117
118
		DataElement parent = (DataElement) event.getParent();
119
		if (fWorkingStatuses.contains(parent)) {
120
			boolean isStatusDone = determineStatusDone(parent);
121
			if (isStatusDone) {
122
				setDone(parent);
123
			}
124
		}
125
	}
126
127
	public DataStore getDataStore() {
128
		return fDataStore;
129
	}
130
131
	/**
132
	 * Test if the StatusChangeListener returned because the network connection
133
	 * to the remote system was broken.
134
	 */
135
	public boolean isNetworkDown() {
136
		return fNetworkDown;
137
	}
138
139
	/**
140
	 * @see IDomainListener#listeningTo(DomainEvent)
141
	 */
142
	public boolean listeningTo(DomainEvent event) {
143
		if (fWorkingStatuses.size() == 0) {
144
			return true;
145
		}
146
147
		DataElement parent = (DataElement) event.getParent();
148
		if (fWorkingStatuses.contains(parent)) {
149
			return determineStatusDone(parent);
150
		}
151
152
		return false;
153
	}
154
155
	public void reInit() {
156
		fNetworkDown = false;
157
		fRemoteConnection.addConnectionChangeListener(this);
158
		fWorkingStatuses.clear();
159
		fDoneStatuses.clear();
160
		fCancelledStatuses.clear();
161
		fDataStore.getDomainNotifier().addDomainListener(this);
162
	}
163
164
	public synchronized void setCancelled(DataElement status) {
165
		fWorkingStatuses.remove(status);
166
		fCancelledStatuses.add(status);
167
	}
168
169
	/**
170
	 * setDone(boolean)
171
	 */
172
	public synchronized void setDone(DataElement status) {
173
		fWorkingStatuses.remove(status);
174
		fDoneStatuses.add(status);
175
	}
176
177
	public synchronized void setWorking(DataElement status) {
178
		fWorkingStatuses.add(status);
179
	}
180
181
	public DataElement waitForUpdate(DataElement status) throws InterruptedException {
182
		return waitForUpdate(status, null, 0);
183
	}
184
185
	public DataElement waitForUpdate(DataElement status, int wait) throws InterruptedException {
186
		return waitForUpdate(status, null, wait);
187
	}
188
189
	public DataElement waitForUpdate(DataElement status, IProgressMonitor monitor) throws InterruptedException {
190
		return waitForUpdate(status, monitor, 0);
191
	}
192
193
	public synchronized DataElement waitForUpdate(DataElement status, IProgressMonitor monitor, int wait)
194
			throws InterruptedException {
195
		if (fNetworkDown && status.getDataStore().isConnected()) {
196
			reInit();
197
		}
198
		if (determineStatusDone(status)) {
199
			setDone(status);
200
			return status;
201
		}
202
203
		setWorking(status);
204
205
		Display display = Display.getCurrent();
206
207
		// Prevent infinite looping by introducing a threshold for wait
208
209
		int WaitThreshold = 50;
210
		if (wait > 0)
211
			WaitThreshold = wait * 10; // 1 second means 10 sleep(100ms)
212
		else if (wait == -1) // force a diagnostic
213
			WaitThreshold = -1;
214
215
		int initialWaitThreshold = WaitThreshold;
216
		int nudges = 0; // nudges used for waking up server with slow
217
						// connections
218
		// nudge up to 12 times before giving up
219
220
		if (display != null) {
221
			// Current thread is UI thread
222
			while (fWorkingStatuses.contains(status)) {
223
				// while (display.readAndDispatch()) {
224
				// Process everything on event queue
225
				// }
226
227
				if ((monitor != null) && (monitor.isCanceled())) {
228
					setCancelled(status);
229
					throw new InterruptedException();
230
				}
231
232
				boolean statusDone = determineStatusDone(status);
233
234
				if (statusDone) {
235
					setDone(status);
236
				} else {
237
					try {
238
						Thread.sleep(100);
239
					} catch (InterruptedException e) {
240
						// Continue waiting in case of spurious interrupt.
241
						// We check the progress monitor to listen for Eclipse
242
						// Shutdown.
243
						continue;
244
					}
245
					if (WaitThreshold > 0) // update timer count if
246
						// threshold not reached
247
						--WaitThreshold; // decrement the timer count
248
249
					if (WaitThreshold == 0) {
250
						wakeupServer(status);
251
252
						// no diagnostic factory but there is a timeout
253
						if (nudges >= 12)
254
							return status; // returning the undone status object
255
256
						nudges++;
257
						WaitThreshold = initialWaitThreshold;
258
					} else if (fNetworkDown || !fDataStore.isConnected()) {
259
						dispose();
260
						throw new InterruptedException();
261
					}
262
				}
263
			}
264
265
		} else {
266
			// Current thread is not UI thread
267
			while (fWorkingStatuses.contains(status)) {
268
269
				if ((monitor != null) && (monitor.isCanceled())) {
270
					setCancelled(status);
271
					throw new InterruptedException();
272
				}
273
274
				boolean statusDone = determineStatusDone(status);
275
276
				if (statusDone) {
277
					setDone(status);
278
				} else {
279
					try {
280
						Thread.sleep(100);
281
					} catch (InterruptedException e) {
282
						// Continue waiting in case of spurious interrupt.
283
						// We check the progress monitor to listen for Eclipse
284
						// Shutdown.
285
						continue;
286
					}
287
288
					if (WaitThreshold > 0) // update timer count if
289
						// threshold not reached
290
						--WaitThreshold; // decrement the timer count
291
292
					if (WaitThreshold == 0) {
293
						wakeupServer(status);
294
295
						// no diagnostic factory but there is a timeout
296
						if (nudges >= 12)
297
							return status; // returning the undone status object
298
299
						nudges++;
300
						WaitThreshold = initialWaitThreshold;
301
					} else if (fNetworkDown) {
302
						dispose();
303
						throw new InterruptedException();
304
					}
305
				}
306
			}
307
		}
308
309
		return status;
310
	}
311
312
	public boolean wasCancelled(DataElement status) {
313
		if (fCancelledStatuses.contains(status)) {
314
			return true;
315
		}
316
		return false;
317
	}
318
319
	private void wakeupServer(DataElement status) {
320
		if (status != null) {
321
			// token command to wake up update handler
322
			DataElement cmdDescriptor = fDataStore.findCommandDescriptor(DataStoreSchema.C_NOTIFICATION);
323
			DataElement subject = status.getParent().get(0);
324
			if (cmdDescriptor != null) {
325
				fDataStore.command(cmdDescriptor, subject);
326
			}
327
		}
328
	}
329
330
	/**
331
	 * Determines whether the status is done.
332
	 * 
333
	 * @return <code>true</code> if status done, <code>false</code> otherwise.
334
	 */
335
	protected boolean determineStatusDone(DataElement status) {
336
		return status.getAttribute(DE.A_VALUE).equals("done") || status.getAttribute(DE.A_NAME).equals("done"); //$NON-NLS-1$ //$NON-NLS-2$
337
	}
338
}
(-)src/org/eclipse/ptp/rdt/ui/subsystems/RemoteCIndexSubsystem2.java (+1057 lines)
Added 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.subsystems;
12
13
import java.io.IOException;
14
import java.lang.reflect.InvocationTargetException;
15
import java.net.URI;
16
import java.net.URISyntaxException;
17
import java.util.ArrayList;
18
import java.util.Collections;
19
import java.util.HashSet;
20
import java.util.Iterator;
21
import java.util.LinkedList;
22
import java.util.List;
23
import java.util.Set;
24
25
import org.eclipse.cdt.core.CCProjectNature;
26
import org.eclipse.cdt.core.CProjectNature;
27
import org.eclipse.cdt.core.index.IIndexFileLocation;
28
import org.eclipse.cdt.core.model.CModelException;
29
import org.eclipse.cdt.core.model.CoreModelUtil;
30
import org.eclipse.cdt.core.model.ICContainer;
31
import org.eclipse.cdt.core.model.ICElement;
32
import org.eclipse.cdt.core.model.ICProject;
33
import org.eclipse.cdt.core.model.IParent;
34
import org.eclipse.cdt.core.model.ITranslationUnit;
35
import org.eclipse.core.resources.IFile;
36
import org.eclipse.core.resources.IProject;
37
import org.eclipse.core.resources.IResource;
38
import org.eclipse.core.resources.IResourceVisitor;
39
import org.eclipse.core.resources.IWorkspace;
40
import org.eclipse.core.resources.IWorkspaceRoot;
41
import org.eclipse.core.resources.ResourcesPlugin;
42
import org.eclipse.core.runtime.AssertionFailedException;
43
import org.eclipse.core.runtime.CoreException;
44
import org.eclipse.core.runtime.IProgressMonitor;
45
import org.eclipse.core.runtime.IStatus;
46
import org.eclipse.core.runtime.NullProgressMonitor;
47
import org.eclipse.core.runtime.Status;
48
import org.eclipse.dstore.core.model.DataElement;
49
import org.eclipse.dstore.core.model.DataStore;
50
import org.eclipse.dstore.core.model.DataStoreResources;
51
import org.eclipse.dstore.core.model.DataStoreSchema;
52
import org.eclipse.ptp.internal.rdt.core.IRemoteIndexerInfoProvider;
53
import org.eclipse.ptp.internal.rdt.core.Serializer;
54
import org.eclipse.ptp.internal.rdt.core.callhierarchy.CalledByResult;
55
import org.eclipse.ptp.internal.rdt.core.callhierarchy.CallsToResult;
56
import org.eclipse.ptp.internal.rdt.core.contentassist.Proposal;
57
import org.eclipse.ptp.internal.rdt.core.contentassist.RemoteContentAssistInvocationContext;
58
import org.eclipse.ptp.internal.rdt.core.includebrowser.IIndexIncludeValue;
59
import org.eclipse.ptp.internal.rdt.core.index.RemoteIndexerProgress;
60
import org.eclipse.ptp.internal.rdt.core.index.RemoteIndexerTask;
61
import org.eclipse.ptp.internal.rdt.core.miners.CDTMiner;
62
import org.eclipse.ptp.internal.rdt.core.model.Scope;
63
import org.eclipse.ptp.internal.rdt.core.navigation.OpenDeclarationResult;
64
import org.eclipse.ptp.internal.rdt.core.search.RemoteSearchMatch;
65
import org.eclipse.ptp.internal.rdt.core.search.RemoteSearchQuery;
66
import org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem;
67
import org.eclipse.ptp.internal.rdt.core.typehierarchy.THGraph;
68
import org.eclipse.ptp.rdt.core.RDTLog;
69
import org.eclipse.ptp.rdt.core.resources.RemoteNature;
70
import org.eclipse.ptp.rdt.core.serviceproviders.IIndexServiceProvider;
71
import org.eclipse.ptp.rdt.ui.messages.Messages;
72
import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteCIndexServiceProvider2;
73
import org.eclipse.ptp.services.core.IService;
74
import org.eclipse.ptp.services.core.IServiceConfiguration;
75
import org.eclipse.ptp.services.core.IServiceProvider;
76
import org.eclipse.ptp.services.core.ServiceModelManager;
77
78
/**
79
 * An RSE subsystem which is used to provide C/C++ indexing services from a Miner
80
 * running on a remote host.
81
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
82
 * part of a work in progress. There is no guarantee that this API will work or
83
 * that it will remain the same. Please do not use this API without consulting
84
 * with the RDT team.
85
 * 
86
 * @author crecoskie
87
 *
88
 */
89
public class RemoteCIndexSubsystem2 implements ICIndexSubsystem {
90
91
	private Set<IProject> fInitializedProjects = new HashSet<IProject>();
92
	private ProjectChangeListener fProjectOpenListener = new ProjectChangeListener(this);
93
	private final RemoteCIndexServiceProvider2 fProvider;
94
	private DStoreServerRunner fDataStoreRunner = null;
95
96
	public RemoteCIndexSubsystem2(RemoteCIndexServiceProvider2 provider) {
97
//		fRemoteServices = services;
98
//		fRemoteConnection = connection;
99
		fProvider = provider;
100
		ResourcesPlugin.getWorkspace().addResourceChangeListener(fProjectOpenListener);
101
	}
102
	
103
	/* (non-Javadoc)
104
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#checkAllProjects(org.eclipse.core.runtime.IProgressMonitor)
105
	 */
106
	public void checkAllProjects(IProgressMonitor monitor) {
107
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
108
		IWorkspaceRoot workspaceRoot = workspace.getRoot();
109
110
		for (IProject project : workspaceRoot.getProjects()) {
111
			// is the project open? if not, there's not much we can do
112
			if (!project.isOpen())
113
				continue;
114
115
			// is this an RDT C/C++ project?
116
			// check the project natures... we care about the project if it has
117
			// both the remote nature and
118
			// at least one of the CDT natures
119
			try {
120
				if (!project.hasNature(RemoteNature.REMOTE_NATURE_ID)
121
						|| !(project.hasNature(CProjectNature.C_NATURE_ID)
122
						|| project.hasNature(CCProjectNature.CC_NATURE_ID)))
123
					continue;
124
				
125
				checkProject(project, monitor);
126
			} catch (Throwable e) {
127
				RDTLog.logError(e);	
128
			}
129
		}
130
	}
131
	
132
	/* (non-Javadoc)
133
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#checkProject(org.eclipse.core.resources.IProject, org.eclipse.core.runtime.IProgressMonitor)
134
	 */
135
	public void checkProject(IProject project, IProgressMonitor monitor) {
136
		if (project == null || fInitializedProjects.contains(project)) {
137
			return;
138
		}
139
		try {
140
			initializeScope(project, monitor);
141
		} catch (CoreException e) {
142
			RDTLog.logError(e);
143
		}
144
	}
145
146
	/* (non-Javadoc)
147
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#computeCompletionProposals(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.ptp.internal.rdt.core.contentassist.RemoteContentAssistInvocationContext, org.eclipse.cdt.core.model.ITranslationUnit)
148
	 */
149
	public List<Proposal> computeCompletionProposals(Scope scope, RemoteContentAssistInvocationContext context, ITranslationUnit unit) {
150
		DataStore dataStore = getDataStore();
151
	    if (dataStore == null)
152
	    {
153
	    	return Collections.emptyList();
154
	    }
155
	    
156
        DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), CDTMiner.C_CONTENT_ASSIST_COMPUTE_PROPOSALS);
157
        
158
        if (queryCmd == null)
159
        {
160
	    	return Collections.emptyList();
161
        }
162
163
     	NullProgressMonitor monitor = new NullProgressMonitor();
164
     	StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore);
165
    	ArrayList<Object> args = new ArrayList<Object>();
166
167
    	// need to know the scope
168
    	DataElement dataElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, scope.getName());
169
    	args.add(dataElement);
170
171
    	// invocation context
172
    	args.add(createSerializableElement(dataStore, context));
173
    	
174
    	// translation unit
175
    	args.add(createSerializableElement(dataStore, unit));
176
    	
177
    	// execute the command
178
    	DataElement status = dataStore.command(queryCmd, args, dataStore.getDescriptorRoot());
179
    	
180
    	try
181
        {
182
        	smonitor.waitForUpdate(status, monitor);
183
        	if (monitor.isCanceled())
184
        	{
185
        		cancelOperation(monitor, status.getParent());
186
        	}
187
        }
188
        catch (Exception e)
189
        {
190
        	RDTLog.logError(e);	
191
        }
192
    	
193
    	DataElement element = status.get(0);
194
    	String data = element.getName();
195
		try
196
		{
197
			Object result = Serializer.deserialize(data);
198
			if (result == null || !(result instanceof List<?>))
199
			{
200
				return Collections.emptyList();
201
			}
202
			return (List<Proposal>) result;
203
		} catch (IOException e) {
204
			RDTLog.logError(e);	
205
		} catch (ClassNotFoundException e) {
206
			RDTLog.logError(e);	
207
		}
208
    	return Collections.emptyList();
209
	}
210
211
	/* (non-Javadoc)
212
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#computeTypeGraph(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.model.ICElement, org.eclipse.core.runtime.IProgressMonitor)
213
	 */
214
	public THGraph computeTypeGraph(Scope scope, ICElement input, IProgressMonitor monitor) {
215
		Object result = sendRequest(CDTMiner.C_TYPE_HIERARCHY_COMPUTE_TYPE_GRAPH, new Object[] { scope, getBaseURI(), input }, monitor);
216
		if (result == null) {
217
			return new THGraph();
218
		}
219
		return (THGraph) result;
220
	}
221
222
	/**
223
	 * Shutdown and clean up the subsystem 
224
	 */
225
	public void dispose() {
226
		if (fDataStoreRunner != null) {
227
			fDataStoreRunner.cancel();
228
		}
229
		ResourcesPlugin.getWorkspace().removeResourceChangeListener(fProjectOpenListener);
230
	}
231
232
	// scope management
233
234
	/* (non-Javadoc)
235
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#findInclude(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.index.IIndexFileLocation, java.lang.String, int, org.eclipse.core.runtime.IProgressMonitor)
236
	 */
237
	public IIndexIncludeValue findInclude(Scope scope, IIndexFileLocation location, String name, int offset, IProgressMonitor monitor)
238
	{
239
		Object result = sendRequest(CDTMiner.C_INCLUDES_FIND_INCLUDE, new Object[] { scope, getBaseURI(), location, name, offset}, monitor);
240
		if (result == null) 
241
		{
242
			return null;
243
		}
244
	
245
		return (IIndexIncludeValue) result;
246
	}
247
248
	/* (non-Javadoc)
249
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#findIncludedBy(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.index.IIndexFileLocation, org.eclipse.core.runtime.IProgressMonitor)
250
	 */
251
	public IIndexIncludeValue[] findIncludedBy(Scope scope, IIndexFileLocation location, IProgressMonitor monitor)
252
	{
253
		Object result = sendRequest(CDTMiner.C_INCLUDES_FIND_INCLUDED_BY, new Object[] { scope, getBaseURI(), location }, monitor);
254
		if (result == null) 
255
		{
256
			return new IIndexIncludeValue[0];
257
		}
258
	
259
		return (IIndexIncludeValue[]) result;
260
	}
261
	
262
	/* (non-Javadoc)
263
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#findIncludesTo(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.index.IIndexFileLocation, org.eclipse.core.runtime.IProgressMonitor)
264
	 */
265
	public IIndexIncludeValue[] findIncludesTo(Scope scope, IIndexFileLocation location, IProgressMonitor monitor)
266
	{
267
		Object result = sendRequest(CDTMiner.C_INCLUDES_FIND_INCLUDES_TO, new Object[] { scope, getBaseURI(), location }, monitor);
268
		if (result == null) 
269
		{
270
			return new IIndexIncludeValue[0];
271
		}
272
	
273
		return (IIndexIncludeValue[]) result;
274
	}
275
	
276
	/* (non-Javadoc)
277
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#findTypeHierarchyInput(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.model.ICElement)
278
	 */
279
	public ICElement[] findTypeHierarchyInput(Scope scope, ICElement memberInput) {
280
		Object result = sendRequest(CDTMiner.C_TYPE_HIERARCHY_FIND_INPUT1, new Object[] { scope, getBaseURI(), memberInput }, null);
281
		if (result == null) {
282
			return new ICElement[] { null, null };
283
		}
284
		return (ICElement[]) result;
285
	}
286
287
	/* (non-Javadoc)
288
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#findTypeHierarchyInput(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.model.ITranslationUnit, int, int)
289
	 */
290
	public ICElement[] findTypeHierarchyInput(Scope scope, ITranslationUnit unit, int selectionStart, int selectionLength) {
291
		Object result = sendRequest(CDTMiner.C_TYPE_HIERARCHY_FIND_INPUT2, new Object[] { scope, getBaseURI(), unit, new Integer(selectionStart), new Integer(selectionLength)}, null);
292
		if (result == null) {
293
			return new ICElement[] { null, null };
294
		}
295
		return (ICElement[]) result;
296
	}
297
298
	/* (non-Javadoc)
299
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#getCallees(org.eclipse.ptp.internal.rdt.core.model.Scope, java.lang.String, java.lang.String, int, int, org.eclipse.core.runtime.IProgressMonitor)
300
	 */
301
	public CallsToResult getCallees(Scope scope, ICElement subject, IProgressMonitor monitor) {
302
    	monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.6") + subject, 100); //$NON-NLS-1$
303
		Object result = sendRequest(CDTMiner.C_CALL_HIERARCHY_GET_CALLS, new Object[] { scope, getBaseURI(), subject }, null);
304
		if (result == null) {
305
			return new CallsToResult();
306
		}
307
		return (CallsToResult) result;
308
	}	
309
	
310
	/* (non-Javadoc)
311
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#getCallers(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.model.ICElement, org.eclipse.core.runtime.IProgressMonitor)
312
	 */
313
	public CalledByResult getCallers(Scope scope, ICElement subject, IProgressMonitor monitor) {
314
    	monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.5") + subject, 100); //$NON-NLS-1$
315
		Object result = sendRequest(CDTMiner.C_CALL_HIERARCHY_GET_CALLERS, new Object[] { scope, getBaseURI(), subject }, null);
316
		if (result == null) {
317
			return new CalledByResult();
318
		}
319
		return (CalledByResult) result;
320
	}
321
	
322
	/* (non-Javadoc)
323
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#getCHDefinitions(org.eclipse.ptp.internal.rdt.core.model.Scope, java.lang.String, java.lang.String, int, int, org.eclipse.core.runtime.IProgressMonitor)
324
	 */
325
	public ICElement[] getCHDefinitions(Scope scope, ICElement subject, IProgressMonitor monitor) {
326
    	monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.7") + subject, 100); //$NON-NLS-1$
327
		Object result = sendRequest(CDTMiner.C_CALL_HIERARCHY_GET_DEFINITIONS_FROM_ELEMENT, new Object[] { scope, getBaseURI(), subject }, null);
328
		if (result == null) {
329
			return new ICElement[0];
330
		}
331
		return (ICElement[]) result;
332
	}
333
	
334
	// call hierarchy
335
	
336
	/* (non-Javadoc)
337
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#getCHDefinitions(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.model.ITranslationUnit, int, int, org.eclipse.core.runtime.IProgressMonitor)
338
	 */
339
	public ICElement[] getCHDefinitions(Scope scope, ITranslationUnit unit, int selectionStart, int selectionLength, IProgressMonitor monitor) {
340
    	monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.7") + unit, 100); //$NON-NLS-1$
341
		Object result = sendRequest(CDTMiner.C_CALL_HIERARCHY_GET_DEFINITIONS_FROM_WORKING_COPY, new Object[] { scope, getBaseURI(), unit, selectionStart, selectionLength }, null);
342
		if (result == null) {
343
			return new ICElement[0];
344
		}
345
		return (ICElement[]) result;
346
	}
347
	
348
	/* (non-Javadoc)
349
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#getModel(org.eclipse.cdt.core.model.ITranslationUnit, org.eclipse.core.runtime.IProgressMonitor)
350
	 */
351
	public ITranslationUnit getModel(ITranslationUnit unit, IProgressMonitor monitor) {
352
		Object result = sendRequest(CDTMiner.C_MODEL_BUILDER, new Object[] {unit}, monitor);
353
		if (result == null) 
354
		{
355
			return null;
356
		}
357
		
358
		//the working copy	
359
		return (ITranslationUnit) result;
360
	}
361
	
362
	/* (non-Javadoc)
363
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#indexDelta(org.eclipse.ptp.internal.rdt.core.model.Scope, java.util.List, java.util.List, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
364
	 */
365
	public IStatus indexDelta(Scope scope,
366
			IRemoteIndexerInfoProvider provider,
367
			List<ICElement> newElements, List<ICElement> changedElements,
368
			List<ICElement> deletedElements, IProgressMonitor monitor,
369
			RemoteIndexerTask task) {
370
		DataStore dataStore = getDataStore();
371
		   
372
	    if (dataStore != null)
373
	    {
374
	     	
375
	    	DataElement result = getDataStore().createObject(null, CDTMiner.T_INDEX_STATUS_DESCRIPTOR, "index"); //$NON-NLS-1$
376
	     	StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore);
377
	     	
378
	     	int workCount = newElements.size() + changedElements.size();
379
	    	
380
	    	monitor.beginTask("Incrementally Indexing...", workCount); //$NON-NLS-1$
381
	   
382
	        DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), CDTMiner.C_INDEX_DELTA);
383
            if (queryCmd != null)
384
            {
385
                      	
386
            	ArrayList<Object> args = new ArrayList<Object>();
387
            	            	
388
            	// need to know the scope
389
               	DataElement scopeElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, scope.getName());
390
               	args.add(scopeElement);
391
               	
392
               	
393
               	String serializedProvider = null;
394
            	try {
395
					serializedProvider = Serializer.serialize(provider);
396
				} catch (IOException e) {
397
					RDTLog.logError(e);
398
				}
399
				
400
				DataElement providerElement = dataStore.createObject(null, CDTMiner.T_INDEX_SCANNER_INFO_PROVIDER, serializedProvider);
401
				args.add(providerElement);
402
				
403
				
404
               	// iterate through the additions and create an object for each addition
405
               	Iterator<ICElement> iterator = newElements.iterator();
406
               	
407
               	while(iterator.hasNext()) {
408
               		ICElement element = iterator.next();
409
               		
410
               		// figure out the path to the element on the remote machine
411
               		String remotePath = convertURIToRemotePath(element.getLocationURI());
412
               		
413
                   	DataElement addedElement = dataStore.createObject(null, CDTMiner.T_INDEX_DELTA_ADDED, remotePath);
414
                   	args.add(addedElement);
415
               	}
416
               	
417
               	// iterate through the changed elements and create an object for each change
418
               	iterator = changedElements.iterator();
419
               	
420
               	while(iterator.hasNext()) {
421
               		ICElement element = iterator.next();
422
               		
423
               		// figure out the path to the element on the remote machine
424
               		String remotePath = convertURIToRemotePath(element.getLocationURI());
425
               		
426
                   	DataElement changedElement = dataStore.createObject(null, CDTMiner.T_INDEX_DELTA_CHANGED, remotePath);
427
                   	args.add(changedElement);
428
               	}
429
               	
430
               	// iterate through the deleted elements and create an object for each change
431
               	iterator = deletedElements.iterator();
432
               	
433
               	while(iterator.hasNext()) {
434
               		ICElement element = iterator.next();
435
               		
436
               		// figure out the path to the element on the remote machine
437
               		String remotePath = convertURIToRemotePath(element.getLocationURI());
438
               		
439
                   	DataElement deletedElement = dataStore.createObject(null, CDTMiner.T_INDEX_DELTA_REMOVED, remotePath);
440
                   	args.add(deletedElement);
441
               	}
442
            	
443
                DataElement status = dataStore.command(queryCmd, args, result);   
444
                
445
                //poll for progress information until the operation is done or canceled
446
                while (!status.getName().equals("done") && !status.getName().equals("cancelled") && !monitor.isCanceled()) { //$NON-NLS-1$ //$NON-NLS-2$
447
448
                	RemoteIndexerProgress progress = getIndexerProgress(status);
449
                	task.updateProgressInformation(progress);
450
                	try {
451
						Thread.sleep(100);
452
					} catch (InterruptedException e) {
453
						RDTLog.logError(e);	
454
					}
455
                }
456
                
457
				try {
458
					smonitor.waitForUpdate(status, monitor);
459
					if (monitor.isCanceled()) 
460
						cancelOperation(monitor, status.getParent());
461
				} catch (Exception e) {
462
					RDTLog.logError(e);	
463
				}
464
465
				monitor.done();
466
			}
467
		}
468
	    
469
	    return Status.OK_STATUS;
470
	}
471
	
472
	/* (non-Javadoc)
473
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#isIndexed(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.index.IIndexFileLocation, org.eclipse.core.runtime.IProgressMonitor)
474
	 */
475
	public boolean isIndexed(Scope scope, IIndexFileLocation location, IProgressMonitor monitor)
476
	{
477
		Object result = sendRequest(CDTMiner.C_INCLUDES_IS_INDEXED, new Object[] { scope, getBaseURI(), location }, monitor);
478
		if (result != null) 
479
		{
480
			return Boolean.parseBoolean(result.toString());
481
		}
482
		
483
		return false;
484
	}
485
	
486
	/* (non-Javadoc)
487
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#moveIndexFile(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
488
	 */
489
	public String moveIndexFile(String scopeName, String newIndexLocation, IProgressMonitor monitor) {
490
		String actualLocation = sendRequestStringResult(CDTMiner.C_MOVE_INDEX_FILE, new Object[] {scopeName, newIndexLocation}, monitor);
491
		return actualLocation;
492
	}
493
	
494
	/* (non-Javadoc)
495
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#openDeclaration(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.model.ITranslationUnit, java.lang.String, int, int, org.eclipse.core.runtime.IProgressMonitor)
496
	 */
497
	public OpenDeclarationResult openDeclaration(Scope scope, ITranslationUnit unit, String selectedText, int selectionStart, int selectionLength, IProgressMonitor monitor) {
498
		monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.9"), 100); //$NON-NLS-1$
499
		Object result = sendRequest(CDTMiner.C_NAVIGATION_OPEN_DECLARATION, new Object[] {scope, unit, selectedText, selectionStart, selectionLength}, monitor);
500
		if(result == null)
501
			return OpenDeclarationResult.failureUnexpectedError();
502
		return (OpenDeclarationResult)result;
503
	}
504
	
505
	/* (non-Javadoc)
506
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#registerScope(org.eclipse.ptp.internal.rdt.core.model.Scope, java.lang.String[], org.eclipse.core.runtime.IProgressMonitor)
507
	 */
508
	public IStatus registerScope(Scope scope, List<ICElement> elements, String configLocation, IProgressMonitor monitor)
509
	{
510
		DataStore dataStore = getDataStore();
511
		   
512
	    if (dataStore != null)
513
	    {
514
	    	
515
	     	StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore);
516
517
	     	monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.3"), 100); //$NON-NLS-1$
518
	   
519
	        DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), CDTMiner.C_SCOPE_REGISTER);
520
            if (queryCmd != null)
521
            {
522
                      	
523
            	ArrayList<Object> args = new ArrayList<Object>();
524
            	            	
525
            	// need to know the scope
526
            	DataElement scopeElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, scope.getName());
527
            	args.add(scopeElement);
528
            	
529
            	// need to know where to find the pdom file for the scope
530
            	DataElement configElement = dataStore.createObject(null, CDTMiner.T_SCOPE_CONFIG_LOCATION, configLocation);
531
            	args.add(configElement);
532
            
533
            	// add in the filenames
534
            	for(ICElement element : elements) {
535
            		addElement(dataStore, args, element);
536
            	}
537
            	
538
            	// execute the command
539
            	DataElement status = dataStore.command(queryCmd, args, dataStore.getDescriptorRoot());
540
            	
541
            	try
542
                {
543
                	smonitor.waitForUpdate(status, monitor);
544
                	if (monitor.isCanceled())
545
                	{
546
                		cancelOperation(monitor, status.getParent());
547
                	}
548
                }
549
                catch (Exception e)
550
                {                	
551
                }
552
            	
553
            	int i=0;
554
            	i++;
555
            }	
556
            
557
            
558
	    }
559
	    
560
	    return Status.OK_STATUS;
561
562
	}
563
	
564
	/*
565
	 * (non-Javadoc)
566
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#reindexScope(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.ptp.internal.rdt.core.IRemoteIndexerInfoProvider, org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ptp.internal.rdt.core.index.RemoteIndexerTask)
567
	 */
568
	public IStatus reindexScope(Scope scope, IRemoteIndexerInfoProvider provider, String indexLocation, IProgressMonitor monitor, RemoteIndexerTask task)
569
	{
570
		DataStore dataStore = getDataStore();
571
		   
572
	    if (dataStore != null)
573
	    {
574
	     	
575
	    	DataElement result = getDataStore().createObject(null, CDTMiner.T_INDEX_STATUS_DESCRIPTOR, "index"); //$NON-NLS-1$
576
	     	StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore);
577
	     	
578
//	     	int count = 0;
579
//	    	DataElement countCmd = dataStore.localDescriptorQuery(datastore.getDescriptorRoot(), CDTMiner.C_SCOPE_COUNT_ELEMENTS);
580
//	    	if (countCmd != null)
581
//	    	{
582
//	    		DataElement countStatus  = dataStore.command(countCmd, result, true);
583
//	    		try
584
//                {
585
//                	smonitor.waitForUpdate(countStatus, monitor, 5000);
586
//                	if (monitor.isCanceled())
587
//                	{
588
//                		cancelOperation(monitor, countStatus.getParent());
589
//                	}
590
//                }
591
//                catch (Exception e)
592
//                {                	
593
//                } 
594
//                count = Integer.parseInt(countStatus.getSource());
595
//	    	}
596
//	    	
597
//	    	monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.1"), count); //$NON-NLS-1$
598
	     	
599
	     	monitor.beginTask("Rebuilding indexing...", 100); //$NON-NLS-1$
600
	   
601
	        DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), CDTMiner.C_INDEX_REINDEX);
602
            if (queryCmd != null)
603
            {
604
                      	
605
            	ArrayList<Object> args = new ArrayList<Object>();
606
            	            	
607
            	// need to know the scope
608
            	DataElement scopeElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, scope.getName());
609
               	args.add(scopeElement);
610
            	
611
            	String serializedProvider = null;
612
            	try {
613
					serializedProvider = Serializer.serialize(provider);
614
				} catch (IOException e) {
615
					RDTLog.logError(e);
616
				}
617
				
618
				DataElement providerElement = dataStore.createObject(null, CDTMiner.T_INDEX_SCANNER_INFO_PROVIDER, serializedProvider);
619
				args.add(providerElement);
620
            	
621
				// need to know the scope config location
622
            	DataElement indexLocationElement = dataStore.createObject(null, CDTMiner.T_SCOPE_CONFIG_LOCATION, indexLocation);
623
               	args.add(indexLocationElement);
624
				
625
                DataElement status = dataStore.command(queryCmd, args, result);   
626
627
                //poll for progress information until the operation is done or canceled
628
                while (!status.getName().equals("done") && !status.getName().equals("cancelled") && !monitor.isCanceled()) { //$NON-NLS-1$ //$NON-NLS-2$
629
630
                	RemoteIndexerProgress progress = getIndexerProgress(status);
631
                	task.updateProgressInformation(progress);
632
                	try {
633
						Thread.sleep(100);
634
					} catch (InterruptedException e) {
635
						RDTLog.logError(e);	
636
					}
637
                }
638
                
639
				try {
640
					smonitor.waitForUpdate(status, monitor);
641
					if (monitor.isCanceled()) 
642
						cancelOperation(monitor, status.getParent());
643
				} catch (Exception e) {
644
					RDTLog.logError(e);	
645
				}
646
647
				monitor.done();
648
            }
649
	    }
650
	    
651
	    return Status.OK_STATUS;
652
653
	}
654
	
655
	/* (non-Javadoc)
656
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#removeIndexFile(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.core.runtime.IProgressMonitor)
657
	 */
658
	public IStatus removeIndexFile(Scope scope, IProgressMonitor monitor) {
659
		sendRequest(CDTMiner.C_REMOVE_INDEX_FILE, new Object[] {scope}, monitor);
660
		return Status.OK_STATUS;
661
	}
662
	
663
	
664
	/* (non-Javadoc)
665
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#runQuery(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.ptp.internal.rdt.core.search.RemoteSearchQuery, org.eclipse.core.runtime.IProgressMonitor)
666
	 */
667
	@SuppressWarnings("unchecked")
668
	public List<RemoteSearchMatch> runQuery(Scope scope, RemoteSearchQuery query, IProgressMonitor monitor) {
669
    	monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.8") + query.getScopeDescription(), 100); //$NON-NLS-1$
670
		Object result = sendRequest(CDTMiner.C_SEARCH_RUN_QUERY, new Object[] { scope, getBaseURI(), query  }, null);
671
		if (result == null) {
672
			return Collections.emptyList();
673
		}
674
		return (List<RemoteSearchMatch>) result;
675
	}
676
	
677
	/**
678
	 * @param requestType
679
	 * @param arguments
680
	 * @param monitor
681
	 * @return
682
	 */
683
	public Object sendRequest(String requestType, Object[] arguments, IProgressMonitor monitor) {
684
		return sendRequest(requestType, arguments, monitor, true);
685
	}
686
	
687
	/**
688
	 * @param requestType
689
	 * @param arguments
690
	 * @param monitor
691
	 * @return
692
	 */
693
	public String sendRequestStringResult(String requestType, Object[] arguments, IProgressMonitor monitor) {
694
		return (String) sendRequest(requestType, arguments, monitor, false);
695
	}
696
	
697
	/* (non-Javadoc)
698
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#startIndexOfScope(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.core.runtime.IProgressMonitor)
699
	 */
700
	public IStatus startIndexOfScope(Scope scope, IRemoteIndexerInfoProvider provider, IProgressMonitor monitor)
701
	{
702
		DataStore dataStore = getDataStore();
703
		   
704
	    if (dataStore != null)
705
	    {
706
	    	
707
	     	StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore);
708
	    	
709
	    	monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.0"), 100); //$NON-NLS-1$
710
	   
711
	        DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), CDTMiner.C_INDEX_START);
712
            if (queryCmd != null)
713
            {
714
                      	
715
            	ArrayList<Object> args = new ArrayList<Object>();
716
            	            	
717
            	// need to know the scope
718
            	DataElement scopeElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, scope.getName());
719
            	args.add(scopeElement);
720
            	
721
            	String serializedProvider = null;
722
            	try {
723
					serializedProvider = Serializer.serialize(provider);
724
				} catch (IOException e) {
725
					RDTLog.logError(e);
726
				}
727
				
728
				DataElement providerElement = dataStore.createObject(null, CDTMiner.T_INDEX_SCANNER_INFO_PROVIDER, serializedProvider);
729
				args.add(providerElement);
730
            
731
           	
732
            	// execute the command
733
            	//DataElement status = dataStore.command(queryCmd, dataStore.getDescriptorRoot(), true); 
734
            	DataElement status = dataStore.command(queryCmd, args, dataStore.getDescriptorRoot());
735
            	
736
            	try
737
                {
738
                	smonitor.waitForUpdate(status, monitor);
739
                	if (monitor.isCanceled())
740
                	{
741
                		cancelOperation(monitor, status.getParent());
742
                	}
743
                }
744
                catch (Exception e)
745
                {                	
746
                }
747
            	
748
            }	
749
                    
750
	    }
751
	    
752
	    return Status.OK_STATUS;
753
754
	}
755
756
	/* (non-Javadoc)
757
	 * @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#unregisterScope(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.core.runtime.IProgressMonitor)
758
	 */
759
	public IStatus unregisterScope(Scope scope, IProgressMonitor monitor) {
760
	    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(scope.getName());
761
		fInitializedProjects.remove(project);
762
		
763
		DataStore dataStore = getDataStore();
764
		   
765
	    if (dataStore != null)
766
	    {
767
	     	
768
//	    	DataElement result = dataStore.createObject(null, CDTMiner.T_INDEX_STATUS_DESCRIPTOR, name);
769
//	    	DataElement statusDescriptor = dataStore.createObjectDescriptor(null, CDTMiner.T_INDEX_STATUS_DESCRIPTOR);
770
	    	
771
//	    	result.setDescriptor(statusDescriptor);
772
	    	
773
	     	StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore);
774
	    	
775
	    	monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.4"), 100); //$NON-NLS-1$
776
	   
777
	        DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), CDTMiner.C_SCOPE_UNREGISTER);
778
            if (queryCmd != null)
779
            {
780
                      	
781
            	ArrayList<Object> args = new ArrayList<Object>();
782
            	            	
783
            	// need to know the scope
784
            	DataElement scopeElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, scope.getName());
785
            	args.add(scopeElement);
786
            
787
            	
788
            	// execute the command
789
            	//DataElement status = dataStore.command(queryCmd, dataStore.getDescriptorRoot(), true); 
790
            	DataElement status = dataStore.command(queryCmd, args, dataStore.getDescriptorRoot());
791
            	
792
            	try
793
                {
794
                	smonitor.waitForUpdate(status, monitor);
795
                	if (monitor.isCanceled())
796
                	{
797
                		cancelOperation(monitor, status.getParent());
798
                	}
799
                }
800
                catch (Exception e)
801
                {                	
802
                }
803
            	
804
805
            }	
806
            
807
            
808
	    }
809
		
810
		return Status.OK_STATUS;
811
	}
812
	
813
	private DataElement createSerializableElement(DataStore dataStore, Object object) {
814
    	try {
815
        	String serialized = Serializer.serialize(object);
816
        	return dataStore.createObject(null, CDTMiner.T_INDEX_STRING_DESCRIPTOR, serialized);
817
    	} catch (IOException e) {
818
    		RDTLog.logError(e);	
819
    		return null;
820
    	}
821
	}
822
	
823
	private RemoteIndexerProgress getIndexerProgress(DataElement status) {
824
		int num = status.getNestedSize();
825
    	if (num > 0) {    		
826
			DataElement element = status.get(num-1);
827
    		String data = element.getName();
828
    		try
829
    		{
830
    			Object result = Serializer.deserialize(data);
831
    			if (result == null || !(result instanceof RemoteIndexerProgress))
832
    			{
833
    				return null;
834
    			}
835
    			RemoteIndexerProgress info = (RemoteIndexerProgress) result;
836
    			return info;
837
    		} catch (IOException e) {
838
    			RDTLog.logError(e);	
839
    		} catch (ClassNotFoundException e) {
840
    			RDTLog.logError(e);	
841
    		}    		
842
    	}
843
    	return null;
844
	}
845
		
846
	private void initializeScope(IProject project, IProgressMonitor monitor) throws CoreException {
847
		// get the service model configuration for this project
848
		final ServiceModelManager serviceModelManager = ServiceModelManager.getInstance();
849
		IServiceConfiguration config = serviceModelManager.getActiveConfiguration(project);
850
851
		// is the indexing service associated with our service provider?
852
		IService service = serviceModelManager.getService(RemoteCIndexServiceProvider2.SERVICE_ID);
853
		IServiceProvider provider = config.getServiceProvider(service);
854
855
856
		// if so, initialize a scope for the project consisting of all
857
		// its translation units
858
		final List<ICElement> cElements = new LinkedList<ICElement>();
859
860
		IResourceVisitor fileCollector = new IResourceVisitor() {
861
862
			public boolean visit(IResource resource) throws CoreException {
863
				if (resource instanceof IFile) {
864
					// add the path
865
					ITranslationUnit tu = CoreModelUtil.findTranslationUnit((IFile) resource);
866
					if (tu != null) {
867
						cElements.add(tu);
868
						return false;
869
					}
870
				}
871
				return true;
872
			}
873
		};
874
875
		// collect the translation units
876
		project.accept(fileCollector);
877
878
		String configLocation = ((IIndexServiceProvider)provider).getIndexLocation();
879
		Scope scope = new Scope(project.getName());
880
881
		// unregister the scope if there already is one
882
		unregisterScope(scope, monitor);
883
884
		// register the new scope
885
		registerScope(scope, cElements, configLocation, monitor);
886
		
887
		fInitializedProjects.add(project);
888
889
	}
890
891
	/**
892
	 * Sends a request in a set format of arguments.
893
	 * 
894
	 * @param deserializeResult If true the result will be deserialized, if false it will treat the result as a raw string.
895
	 */
896
	private Object sendRequest(String requestType, Object[] arguments, IProgressMonitor monitor, boolean deserializeResult) {
897
		DataStore dataStore = getDataStore();
898
	    if (dataStore == null)
899
	    	return null;
900
	    
901
        DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), requestType);
902
        if (queryCmd == null)
903
	    	return null;        
904
905
     	StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore);
906
    	ArrayList<Object> args = new ArrayList<Object>();
907
908
    	for (Object argument : arguments) {
909
    		if (argument instanceof Scope) {
910
    	    	DataElement dataElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, ((Scope) argument).getName());
911
    	    	args.add(dataElement);
912
    		} else if (argument instanceof String) {
913
            	DataElement dataElement = dataStore.createObject(null, CDTMiner.T_INDEX_STRING_DESCRIPTOR, (String) argument);
914
            	args.add(dataElement);
915
    		} else if (argument instanceof Integer
916
    				|| argument instanceof Boolean
917
    				|| argument instanceof Character
918
    				|| argument instanceof Double
919
    				|| argument instanceof Float) {
920
            	DataElement dataElement = dataStore.createObject(null, CDTMiner.T_INDEX_STRING_DESCRIPTOR, argument.toString());
921
            	args.add(dataElement);
922
    		} else {
923
    	    	args.add(createSerializableElement(dataStore, argument));
924
    		}
925
    	}
926
    	
927
    	// execute the command
928
    	DataElement status = dataStore.command(queryCmd, args, dataStore.getDescriptorRoot());
929
    	
930
    	try
931
        {
932
    		monitor = monitor == null ? new NullProgressMonitor() : monitor;
933
        	smonitor.waitForUpdate(status, monitor);
934
        	if (monitor.isCanceled()) {
935
        		cancelOperation(monitor, status.getParent());
936
        	}
937
        }
938
        catch (Exception e) {
939
        	RDTLog.logError(e);	
940
        }
941
    	
942
    	DataElement element = status.get(0);
943
    	if (element == null) {
944
    		return null;
945
    	}
946
    	
947
    	if(DataStoreResources.model_error.equals(element.getType())) { // Error occurred on the server
948
    		RDTLog.logError(status.getValue()); // prints the server error stack trace to the log
949
    		return null;
950
    	}
951
    	
952
    	String data = element.getName();
953
    	if(!deserializeResult)
954
    		return data;
955
    	
956
		try
957
		{
958
			Object result = Serializer.deserialize(data);
959
			return result;
960
		} catch (IOException e) {
961
			RDTLog.logError(e);	
962
		} catch (ClassNotFoundException e) {
963
			RDTLog.logError(e);	
964
		}
965
    	return null;
966
	}
967
968
969
970
	/**
971
	 * @param dataStore
972
	 * @param args
973
	 * @param filePath
974
	 * @param element
975
	 */
976
	protected void addElement(DataStore dataStore, ArrayList<Object> args, ICElement element) {
977
		
978
   		String filePath = null;
979
		
980
		// if it's a translation unit, we can just add it
981
		if(element instanceof ITranslationUnit) {
982
			filePath = convertURIToRemotePath(element.getLocationURI());
983
		}
984
		
985
		else {
986
			// if it's a container or a project, add the child elements
987
			if(element instanceof ICContainer || element instanceof ICProject) {
988
				try {
989
					ICElement[] children = ((IParent) element).getChildren();
990
					
991
					for(int k = 0; k < children.length; k++)
992
						addElement(dataStore, args, children[k]);
993
					
994
				} catch (CModelException e) {
995
					RDTLog.logError(e);	
996
				}
997
			}
998
			
999
		}
1000
		
1001
		if (filePath != null) {
1002
			DataElement fileElement = dataStore.createObject(null,
1003
					CDTMiner.T_INDEX_FILENAME_DESCRIPTOR, filePath);
1004
			args.add(fileElement);
1005
		}
1006
	}
1007
1008
	protected void cancelOperation(IProgressMonitor monitor, DataElement cmd) throws InvocationTargetException, InterruptedException
1009
	{
1010
		DataStore dataStore = cmd.getDataStore();
1011
		DataElement commandDescriptor = dataStore.findCommandDescriptor(DataStoreSchema.C_CANCEL);
1012
		if (commandDescriptor != null)
1013
		{
1014
			dataStore.command(commandDescriptor, cmd, false, true);
1015
		}	
1016
	}
1017
1018
	protected URI convertRemotePathToURI(String path) throws URISyntaxException {
1019
		return fProvider.getRemoteServices().getFileManager(fProvider.getRemoteConnection()).toURI(path);
1020
	}
1021
	
1022
	protected String convertURIToRemotePath(URI locationURI) {
1023
		return fProvider.getRemoteServices().getFileManager(fProvider.getRemoteConnection()).toPath(locationURI).toString();
1024
	}
1025
	
1026
	protected String getBaseURI() {
1027
		try {
1028
			return convertRemotePathToURI("/").toString(); //$NON-NLS-1$
1029
		} catch (URISyntaxException e) {
1030
			throw new AssertionFailedException(e.getLocalizedMessage());
1031
		}
1032
	}
1033
	
1034
	protected DataStore getDataStore() {
1035
		DataStore dataStore = null;
1036
		if (fDataStoreRunner == null) {
1037
			fDataStoreRunner = DStoreServerManager.getInstance().getServer(fProvider.getRemoteServices(), fProvider.getRemoteConnection());
1038
			fDataStoreRunner.setWorkDir(fProvider.getDStoreLocation());
1039
			fDataStoreRunner.setCommand(fProvider.getDStoreCommand());
1040
			fDataStoreRunner.setEnv(fProvider.getDStoreEnv());
1041
		}
1042
		dataStore = fDataStoreRunner.getDataStore();
1043
		if (!dataStore.isConnected()) {
1044
			if (fDataStoreRunner.startServer()) {
1045
				DataElement status = dataStore.activateMiner("org.eclipse.ptp.internal.rdt.core.miners.CDTMiner"); //$NON-NLS-1$
1046
		     	StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore);
1047
	        	try {
1048
					smonitor.waitForUpdate(status, new NullProgressMonitor());
1049
				} catch (InterruptedException e) {
1050
					// Data store will be disconnected if error occurs
1051
				}
1052
			}
1053
		}
1054
		return dataStore;
1055
	}
1056
	
1057
}
(-).options (+7 lines)
Added Link Here
1
# Debugging options for the org.eclipse.ptp.rdt.ui
2
3
# Also displays overall startup time.
4
org.eclipse.ptp.rdt.ui/debug=false
5
6
# Enables dstore server tracing
7
org.eclipse.ptp.rdt.ui/debug/dstore/tracing=false
(-)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.internal.ui.wizards.ICDTCommonProjectWizard;
28
import org.eclipse.cdt.ui.CUIPlugin;
29
import org.eclipse.cdt.ui.newui.UIMessages;
30
import org.eclipse.cdt.ui.wizards.CWizardHandler;
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/subsystems/DStoreServerManager.java (+40 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
package org.eclipse.ptp.rdt.ui.subsystems;
9
10
import java.util.HashMap;
11
import java.util.Map;
12
13
import org.eclipse.ptp.remote.core.IRemoteConnection;
14
import org.eclipse.ptp.remote.core.IRemoteServices;
15
16
public class DStoreServerManager {
17
	private final static Map<String, DStoreServerRunner> fServers = new HashMap<String, DStoreServerRunner>();
18
	
19
	private static DStoreServerManager fInstance;
20
	
21
	public static synchronized DStoreServerManager getInstance() {
22
		if(fInstance == null) {
23
			fInstance = new DStoreServerManager();
24
		}
25
		return fInstance;
26
	}
27
	
28
	private String getKey(IRemoteServices services, IRemoteConnection connection) {
29
		return services.getId() + connection.getName();
30
	}
31
	
32
	public DStoreServerRunner getServer(IRemoteServices services, IRemoteConnection connection) {
33
		DStoreServerRunner server = fServers.get(getKey(services, connection));
34
		if (server == null) {
35
			server = new DStoreServerRunner(services, connection);
36
			fServers.put(getKey(services, connection), server);
37
		}
38
		return server;
39
	}
40
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/DStoreEnvironmentPage.java (+260 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
package org.eclipse.ptp.rdt.ui.wizards;
9
10
import org.eclipse.core.runtime.ListenerList;
11
import org.eclipse.jface.dialogs.Dialog;
12
import org.eclipse.jface.dialogs.IDialogConstants;
13
import org.eclipse.jface.window.Window;
14
import org.eclipse.ptp.rdt.ui.wizards.DStoreServerWidget.FieldModifier;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.events.ModifyEvent;
17
import org.eclipse.swt.events.ModifyListener;
18
import org.eclipse.swt.events.SelectionAdapter;
19
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.layout.GridLayout;
22
import org.eclipse.swt.widgets.Button;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.Event;
26
import org.eclipse.swt.widgets.Group;
27
import org.eclipse.swt.widgets.Label;
28
import org.eclipse.swt.widgets.Shell;
29
import org.eclipse.swt.widgets.Table;
30
import org.eclipse.swt.widgets.TableColumn;
31
import org.eclipse.swt.widgets.TableItem;
32
import org.eclipse.swt.widgets.Text;
33
34
public class DStoreEnvironmentPage extends Composite {
35
	public class EnvInputDialog extends Dialog {
36
	    private Text variableText;
37
	    private Text valueText;
38
	    
39
	    private String variable;
40
	    private String value;
41
42
	    public EnvInputDialog(Shell parentShell) {
43
	        super(parentShell);
44
	    }
45
46
	    public String getValue() {
47
	        return value;
48
	    }
49
50
	    public String getVariable() {
51
	        return variable;
52
	    }
53
54
	    /*
55
	     * (non-Javadoc) Method declared on Dialog.
56
	     */
57
	    protected void buttonPressed(int buttonId) {
58
	        if (buttonId == IDialogConstants.OK_ID) {
59
	            value = valueText.getText();
60
	            variable = variableText.getText();
61
	        } else {
62
	            value = null;
63
	            variable = null;
64
	        }
65
	        super.buttonPressed(buttonId);
66
	    }
67
68
	    /*
69
	     * (non-Javadoc)
70
	     * 
71
	     * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
72
	     */
73
	    protected void createButtonsForButtonBar(Composite parent) {
74
	        // create OK and Cancel buttons by default
75
	        createButton(parent, IDialogConstants.OK_ID,
76
	                IDialogConstants.OK_LABEL, true);
77
	        createButton(parent, IDialogConstants.CANCEL_ID,
78
	                IDialogConstants.CANCEL_LABEL, false);
79
	    }
80
	    
81
	    /*
82
	     * (non-Javadoc) Method declared on Dialog.
83
	     */
84
	    protected Control createDialogArea(Composite parent) {
85
	        // create composite
86
	        Composite composite = (Composite) super.createDialogArea(parent);
87
	        // create message
88
            Label variableLabel = new Label(composite, SWT.WRAP);
89
            variableLabel.setText("Variable"); //$NON-NLS-1$
90
            GridData data = new GridData(GridData.GRAB_HORIZONTAL
91
                    | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL
92
                    | GridData.VERTICAL_ALIGN_CENTER);
93
            data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
94
            variableLabel.setLayoutData(data);
95
            variableLabel.setFont(parent.getFont());
96
97
            variableText = new Text(composite, SWT.SINGLE | SWT.BORDER);
98
            variableText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
99
	                | GridData.HORIZONTAL_ALIGN_FILL));
100
            Label valueLabel = new Label(composite, SWT.WRAP);
101
            valueLabel.setText("Variable"); //$NON-NLS-1$
102
            data = new GridData(GridData.GRAB_HORIZONTAL
103
                    | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL
104
                    | GridData.VERTICAL_ALIGN_CENTER);
105
            data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
106
            valueLabel.setLayoutData(data);
107
            valueLabel.setFont(parent.getFont());
108
109
            valueText = new Text(composite, SWT.SINGLE | SWT.BORDER);
110
            valueText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
111
	                | GridData.HORIZONTAL_ALIGN_FILL));
112
	        applyDialogFont(composite);
113
	        return composite;
114
	    }
115
	}
116
117
	///private final Label label;
118
	private Table table;
119
	private Button addButton;
120
	private Button removeButton;
121
	
122
	private ListenerList modifyListeners = new ListenerList();
123
	
124
	public DStoreEnvironmentPage(Composite parent, int style) {
125
		super(parent, style);
126
		
127
		GridLayout layout = new GridLayout(1, false);
128
		setLayout(layout);
129
		setLayoutData(new GridData(GridData.FILL_BOTH));
130
		
131
		Group group = new Group(this, SWT.NONE);
132
		group.setText("Environment Variables"); //$NON-NLS-1$
133
		group.setLayout(new GridLayout(2, false));
134
		group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
135
136
		Composite tableComp = new Composite(group, SWT.NONE);
137
		tableComp.setLayout(new GridLayout(2, false));
138
		tableComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
139
140
		table = new Table(tableComp, SWT.BORDER);
141
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
142
		table.setLayoutData(data);
143
		table.setHeaderVisible(true);
144
		table.setLinesVisible(true);
145
		
146
		TableColumn col1 = new TableColumn(table, SWT.NONE);
147
		col1.setText("Variable"); //$NON-NLS-1$
148
		col1.setWidth(100);
149
		col1.setResizable(true);
150
		
151
		TableColumn col2 = new TableColumn(table, SWT.NONE);
152
		col2.setText("Value"); //$NON-NLS-1$
153
		col2.setWidth(200);
154
		col2.setResizable(true);
155
156
		Composite buttonComp = new Composite(group, SWT.NONE);
157
		buttonComp.setLayout(new GridLayout(1, false));
158
		buttonComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
159
160
		addButton = new Button(buttonComp, SWT.NONE);
161
		addButton.setText("Add..."); //$NON-NLS-1$
162
		GridData addButtonData = new GridData(SWT.FILL, SWT.FILL, false, false);
163
		addButtonData.widthHint = 80;
164
		addButton.setLayoutData(addButtonData);
165
		addButton.addSelectionListener(new SelectionAdapter() {
166
			/* (non-Javadoc)
167
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
168
			 */
169
			@Override
170
			public void widgetSelected(SelectionEvent e) {
171
				handleAddButtonSelected();
172
			}
173
		});
174
175
		removeButton = new Button(buttonComp, SWT.NONE);
176
		removeButton.setText("Remove"); //$NON-NLS-1$
177
		GridData removeButtonData = new GridData(SWT.FILL, SWT.FILL, false, false);
178
		removeButtonData.widthHint = 80;
179
		removeButton.setLayoutData(removeButtonData);
180
		removeButton.addSelectionListener(new SelectionAdapter() {
181
			/* (non-Javadoc)
182
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
183
			 */
184
			@Override
185
			public void widgetSelected(SelectionEvent e) {
186
				handleRemoveButtonSelected();
187
			}		
188
		});
189
190
	}
191
	
192
	public void addModifyListener(ModifyListener listener) {
193
		modifyListeners.add(listener);
194
	}
195
	
196
	public void removeModifyListener(ModifyListener listener) {
197
		modifyListeners.remove(listener);
198
	}
199
	
200
	public String getEnvironment() {
201
		String env = ""; //$NON-NLS-1$
202
		
203
		for (int i = 0; i < table.getItemCount(); i++) {
204
			if (i > 0) {
205
				env += "\n"; //$NON-NLS-1$
206
			}
207
			TableItem item = table.getItem(i);
208
			env += item.getText(0) + "=" + item.getText(1); //$NON-NLS-1$
209
		}
210
		
211
		return env;
212
	}
213
	
214
	public void setEnvironment(String env) {
215
		table.clearAll();
216
		if (env != null) {
217
			for (String envs : env.split("\n")) { //$NON-NLS-1$
218
				String[] envVar = envs.split("="); //$NON-NLS-1$
219
				if (envVar.length == 2) {
220
					TableItem item = new TableItem(table, SWT.NONE);
221
					item.setText(0, envVar[0]);
222
					item.setText(1, envVar[1]);
223
				}
224
			}
225
		}
226
	}
227
	
228
	protected void handleAddButtonSelected() {
229
		EnvInputDialog dialog = new EnvInputDialog(getShell()); 
230
		if (dialog.open() != Window.OK) {
231
			return;
232
		}
233
		
234
		String var = dialog.getVariable();
235
		String value = dialog.getValue();
236
		
237
		if (var != null && value != null && var.length() > 0 && value.length() >0) {
238
			TableItem item = new TableItem(table, SWT.NONE);
239
			item.setText(0, var.trim());
240
			item.setText(1, value.trim());
241
		}
242
		
243
		Event e = new Event();
244
		e.data = FieldModifier.VALUE_DSTORE_ENV;
245
		notifyListeners(new ModifyEvent(e));
246
	}
247
	
248
	protected void handleRemoveButtonSelected() {
249
		int index = table.getSelectionIndex();
250
		if (index >= 0) {
251
			table.remove(index);
252
		}
253
	}
254
	
255
	private void notifyListeners(ModifyEvent e) {
256
		for (Object listener : modifyListeners.getListeners()) {
257
			((ModifyListener)listener).modifyText(e);
258
		}
259
	}
260
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/DStoreServerWidget.java (+131 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
package org.eclipse.ptp.rdt.ui.wizards;
9
10
import org.eclipse.core.runtime.ListenerList;
11
import org.eclipse.ptp.remote.core.IRemoteConnection;
12
import org.eclipse.ptp.remote.core.IRemoteServices;
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.events.ModifyEvent;
15
import org.eclipse.swt.events.ModifyListener;
16
import org.eclipse.swt.layout.GridData;
17
import org.eclipse.swt.layout.GridLayout;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.TabFolder;
20
import org.eclipse.swt.widgets.TabItem;
21
22
public class DStoreServerWidget extends Composite {
23
	public enum FieldModifier {
24
		VALUE_DSTORE_LOCATION, 
25
		VALUE_DSTORE_COMMAND,
26
		VALUE_DSTORE_ENV,
27
		VALUE_INDEX_LOCATION
28
	}
29
	
30
	private ListenerList modifyListeners = new ListenerList();
31
	
32
	private DStoreServerPage fServerPage;
33
	private DStoreEnvironmentPage fEnvironmentPage;
34
	private DStoreIndexPage fIndexPage;
35
	
36
	public DStoreServerWidget(Composite parent, int style) {
37
		super(parent, style);
38
		
39
		setFont(parent.getFont());
40
		GridLayout layout = new GridLayout(1, false);
41
		layout.marginHeight = 0;
42
		layout.marginWidth = 0;
43
		setLayout(layout);
44
		setLayoutData(new GridData(GridData.FILL_BOTH));
45
46
		TabFolder folder= new TabFolder(this, SWT.NONE);
47
		folder.setLayoutData(new GridData(GridData.FILL_BOTH));
48
		folder.setFont(this.getFont());
49
50
		fServerPage = new DStoreServerPage(folder, SWT.NONE);
51
		fServerPage.addModifyListener(new ModifyListener() {
52
			public void modifyText(ModifyEvent e) {
53
				notifyListeners(e);
54
			}
55
		});
56
		TabItem item = new TabItem(folder, SWT.NONE);
57
        item.setText("Server"); //$NON-NLS-1$
58
        item.setControl(fServerPage);
59
        
60
        fEnvironmentPage = new DStoreEnvironmentPage(folder, SWT.NONE);
61
        fEnvironmentPage.addModifyListener(new ModifyListener() {
62
			public void modifyText(ModifyEvent e) {
63
				notifyListeners(e);
64
			}
65
		});
66
		item = new TabItem(folder, SWT.NONE);
67
        item.setText("Environment"); //$NON-NLS-1$
68
        item.setControl(fEnvironmentPage);
69
70
        fIndexPage = new DStoreIndexPage(folder, SWT.NONE);
71
        fIndexPage.addModifyListener(new ModifyListener() {
72
			public void modifyText(ModifyEvent e) {
73
				notifyListeners(e);
74
			}
75
		});
76
		item = new TabItem(folder, SWT.NONE);
77
        item.setText("Index"); //$NON-NLS-1$
78
        item.setControl(fIndexPage);
79
	}
80
	
81
	public void addModifyListener(ModifyListener listener) {
82
		modifyListeners.add(listener);
83
	}
84
	
85
	public String getDStoreCommand() {
86
		return fServerPage.getServerCommand();
87
	}
88
89
	public String getDStoreEnvironment() {
90
		return fEnvironmentPage.getEnvironment();
91
	}
92
	
93
	public String getDStoreLocation() {
94
		return fServerPage.getLocationPath();
95
	}
96
	
97
	public String getIndexLocation() {
98
		return fIndexPage.getLocationPath();
99
	}
100
	
101
	public void removeModifyListener(ModifyListener listener) {
102
		modifyListeners.remove(listener);
103
	}
104
	
105
	public void setConnection(IRemoteServices services, IRemoteConnection conn) {
106
		fServerPage.setConnection(services, conn);
107
		fIndexPage.setConnection(services, conn);
108
	}
109
	
110
	public void setDStoreCommand(String command) {
111
		fServerPage.setServerCommand(command);
112
	}
113
	
114
	public void setDStoreEnvironment(String env) {
115
		fEnvironmentPage.setEnvironment(env);
116
	}
117
	
118
	public void setDStoreLocation(String path) {
119
		fServerPage.setLocationPath(path);
120
	}
121
	
122
	public void setIndexLocation(String path) {
123
		fIndexPage.setLocationPath(path);
124
	}
125
	
126
	private void notifyListeners(ModifyEvent e) {
127
		for (Object listener : modifyListeners.getListeners()) {
128
			((ModifyListener)listener).modifyText(e);
129
		}
130
	}
131
}
(-)data/dstore-server.properties (+2 lines)
Added Link Here
1
COMMAND=java -Xms64m -Xmx128m -Xss2m -DA_PLUGIN_PATH=. -DDSTORE_TRACING_ON=false -Dclient.username=$USER -DDSTORE_SPIRIT_ON=true org.eclipse.dstore.core.server.Server 0 60000
2
CLASSPATH=.:dstore_extra_server.jar:dstore_core.jar:dstore_miners.jar:clientserver.jar:cdtminer.jar:cdtmodel.jar:cdtparser.jar:org.eclipse.core.runtime_3.5.0.v20090525.jar:org.eclipse.equinox.common_3.5.0.v20090520-1800.jar:org.eclipse.core.filesystem_1.2.0.v20090507.jar:com.ibm.icu.base_4.0.1.v20090415.jar:stubs.jar:lrparser.jar:xlcparser.jar:net.sourceforge.lpg.lpgjavaruntime_1.1.0.v200803061910.jar
(-)src/org/eclipse/ptp/rdt/ui/serviceproviders/RemoteCIndexServiceProvider2.java (+324 lines)
Added 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.serviceproviders;
12
13
import org.eclipse.core.runtime.IPath;
14
import org.eclipse.core.runtime.Path;
15
import org.eclipse.ptp.internal.rdt.core.callhierarchy.ICallHierarchyService;
16
import org.eclipse.ptp.internal.rdt.core.callhierarchy.RemoteCallHierarchyService;
17
import org.eclipse.ptp.internal.rdt.core.includebrowser.IIncludeBrowserService;
18
import org.eclipse.ptp.internal.rdt.core.includebrowser.RemoteIncludeBrowserService;
19
import org.eclipse.ptp.internal.rdt.core.index.IIndexLifecycleService;
20
import org.eclipse.ptp.internal.rdt.core.index.RemoteIndexLifecycleService;
21
import org.eclipse.ptp.internal.rdt.core.model.IModelBuilderService;
22
import org.eclipse.ptp.internal.rdt.core.model.RemoteModelBuilderService;
23
import org.eclipse.ptp.internal.rdt.core.navigation.INavigationService;
24
import org.eclipse.ptp.internal.rdt.core.navigation.RemoteNavigationService;
25
import org.eclipse.ptp.internal.rdt.core.typehierarchy.ITypeHierarchyService;
26
import org.eclipse.ptp.internal.rdt.core.typehierarchy.RemoteTypeHierarchyService;
27
import org.eclipse.ptp.internal.rdt.ui.contentassist.IContentAssistService;
28
import org.eclipse.ptp.internal.rdt.ui.contentassist.RemoteContentAssistService;
29
import org.eclipse.ptp.internal.rdt.ui.search.ISearchService;
30
import org.eclipse.ptp.internal.rdt.ui.search.RemoteSearchService;
31
import org.eclipse.ptp.rdt.core.messages.Messages;
32
import org.eclipse.ptp.rdt.ui.subsystems.RemoteCIndexSubsystem2;
33
import org.eclipse.ptp.remote.core.IRemoteConnection;
34
import org.eclipse.ptp.remote.core.IRemoteServices;
35
import org.eclipse.ptp.remote.core.PTPRemoteCorePlugin;
36
import org.eclipse.ptp.services.core.ServiceProvider;
37
38
public class RemoteCIndexServiceProvider2 extends ServiceProvider implements IIndexServiceProvider2 {
39
40
	protected boolean fIsConfigured;
41
42
	protected IIndexLifecycleService fIndexLifecycleService;
43
	protected INavigationService fNavigationService;
44
	protected ICallHierarchyService fCallHierarchyService;
45
	protected ITypeHierarchyService fTypeHierarchyService;
46
	protected IIncludeBrowserService fIncludeBrowserService;
47
	protected IModelBuilderService fModelBuilderService;
48
	protected RemoteSearchService fSearchService;
49
	protected IContentAssistService fContentAssistService;
50
	protected RemoteCIndexSubsystem2 fSubsystem = null;
51
	protected String indexLocation;
52
	
53
	public static final String ID = "org.eclipse.ptp.rdt.ui.RemoteCIndexServiceProvider2"; //$NON-NLS-1$
54
	public static final String NAME = Messages.RemoteCIndexServiceProvider_0;
55
	public static final String SERVICE_ID = "org.eclipse.ptp.rdt.core.CIndexingService"; //$NON-NLS-1$
56
	
57
	private static final String SERVICE_ID_KEY = "service-name"; //$NON-NLS-1$
58
	private static final String CONNECTION_NAME_KEY = "connection-name"; //$NON-NLS-1$
59
	private static final String INDEX_LOCATION_KEY = "index-location"; //$NON-NLS-1$
60
	private static final String DSTORE_LOCATION_KEY = "dstore-location"; //$NON-NLS-1$
61
	private static final String DSTORE_COMMAND_KEY = "dstore-command"; //$NON-NLS-1$
62
	private static final String DSTORE_ENV_KEY = "dstore-env"; //$NON-NLS-1$
63
	
64
	/* (non-Javadoc)
65
	 * @see org.eclipse.ptp.rdt.core.serviceproviders.IIndexServiceProvider#getCallHierarchyService()
66
	 */
67
	public synchronized ICallHierarchyService getCallHierarchyService() {
68
		if(!isConfigured())
69
			return null;
70
		
71
		if(fCallHierarchyService== null)
72
			fCallHierarchyService = new RemoteCallHierarchyService(fSubsystem);
73
		
74
		return fCallHierarchyService;
75
	}
76
	
77
	/**
78
	 * Get the host name for this connection.
79
	 * 
80
	 * @return host name
81
	 */
82
	public String getConnectionName() {
83
		return getString(CONNECTION_NAME_KEY, null);
84
	}
85
	
86
	/* (non-Javadoc)
87
	 * @see org.eclipse.ptp.rdt.ui.serviceproviders.IIndexServiceProvider2#getContentAssistService()
88
	 */
89
	public IContentAssistService getContentAssistService() {
90
		if(!isConfigured())
91
			return null;
92
		
93
		if(fContentAssistService == null)
94
			fContentAssistService = new RemoteContentAssistService(fSubsystem);
95
		
96
		return fContentAssistService;
97
	}
98
	
99
	public String getDStoreEnv() {
100
		initialize();
101
		return getString(DSTORE_ENV_KEY, ""); //$NON-NLS-1$
102
	}
103
	
104
	public String getDStoreCommand() {
105
		initialize();
106
		return getString(DSTORE_COMMAND_KEY, ""); //$NON-NLS-1$
107
	}
108
	
109
	public String getDStoreLocation() {
110
		initialize();
111
		return getString(DSTORE_LOCATION_KEY, ""); //$NON-NLS-1$
112
	}
113
	
114
	/* (non-Javadoc)
115
	 * @see org.eclipse.ptp.rdt.core.serviceproviders.IIndexServiceProvider#getIncludeBrowserService()
116
	 */
117
	public synchronized IIncludeBrowserService getIncludeBrowserService() {
118
		if(!isConfigured())
119
			return null;
120
		
121
		if(fIncludeBrowserService== null)
122
			fIncludeBrowserService = new RemoteIncludeBrowserService(fSubsystem);
123
		
124
		return fIncludeBrowserService;
125
	}
126
127
	/* (non-Javadoc)
128
	 * @see org.eclipse.ptp.rdt.core.serviceproviders.IIndexServiceProvider#getIndexLifeCycleService()
129
	 */
130
	public synchronized IIndexLifecycleService getIndexLifeCycleService() {
131
		if(!isConfigured())
132
			return null;
133
		
134
		if(fIndexLifecycleService == null)
135
			fIndexLifecycleService = new RemoteIndexLifecycleService(fSubsystem);
136
		
137
		return fIndexLifecycleService;
138
	}
139
	
140
	/* (non-Javadoc)
141
	 * @see org.eclipse.ptp.rdt.core.serviceproviders.IIndexServiceProvider#getIndexLocation()
142
	 */
143
	public String getIndexLocation() {
144
		initialize();
145
		return getString(INDEX_LOCATION_KEY, ""); //$NON-NLS-1$
146
	}
147
148
	/* (non-Javadoc)
149
	 * @see org.eclipse.ptp.rdt.core.serviceproviders.IIndexServiceProvider#getModelBuilderService()
150
	 */
151
	public synchronized IModelBuilderService getModelBuilderService() {
152
		if(!isConfigured())
153
			return null;
154
		
155
		if(fModelBuilderService== null)
156
			fModelBuilderService = new RemoteModelBuilderService(fSubsystem);
157
		
158
		return fModelBuilderService;
159
	}
160
161
	/* (non-Javadoc)
162
	 * @see org.eclipse.ptp.rdt.core.serviceproviders.IIndexServiceProvider#getNavigationService()
163
	 */
164
	public synchronized INavigationService getNavigationService() {
165
		if(!isConfigured())
166
			return null;
167
		
168
		if(fNavigationService== null)
169
			fNavigationService = new RemoteNavigationService(fSubsystem);
170
		
171
		return fNavigationService;
172
	}
173
	
174
	public IRemoteConnection getRemoteConnection() {
175
		if (!isConfigured()) {
176
			return null;
177
		}
178
		return getRemoteServices().getConnectionManager().getConnection(getConnectionName());
179
	}
180
	
181
	public IRemoteServices getRemoteServices() {
182
		if (!isConfigured()) {
183
			return null;
184
		}
185
		return PTPRemoteCorePlugin.getDefault().getRemoteServices(getServiceId());
186
	}
187
	
188
 	/* (non-Javadoc)
189
	 * @see org.eclipse.ptp.rdt.ui.serviceproviders.IIndexServiceProvider2#getSearchService()
190
	 */
191
	public ISearchService getSearchService() {
192
		if(!isConfigured())
193
			return null;
194
		
195
		if(fSearchService == null)
196
			fSearchService = new RemoteSearchService(fSubsystem);
197
		
198
		return fSearchService;
199
	}
200
	
201
	/* (non-Javadoc)
202
	 * @see org.eclipse.ptp.services.core.ServiceProvider#getServiceId()
203
	 */
204
	@Override
205
	public String getServiceId() {
206
		return getString(SERVICE_ID_KEY, null);
207
	}
208
	
209
	/* (non-Javadoc)
210
	 * @see org.eclipse.ptp.rdt.core.serviceproviders.IIndexServiceProvider#getTypeHierarchyService()
211
	 */
212
	public synchronized ITypeHierarchyService getTypeHierarchyService() {
213
		if(!isConfigured())
214
			return null;
215
		
216
		if(fTypeHierarchyService== null)
217
			fTypeHierarchyService = new RemoteTypeHierarchyService(fSubsystem);
218
		
219
		return fTypeHierarchyService;
220
	}
221
222
	/* (non-Javadoc)
223
	 * @see org.eclipse.ptp.services.core.IServiceProvider#isConfigured()
224
	 */
225
	public boolean isConfigured() {
226
		initialize();
227
		return fIsConfigured;
228
	}
229
	
230
	/**
231
 	 * @param isConfigured
232
 	 */
233
 	public void setConfigured(boolean isConfigured) {
234
		fIsConfigured = isConfigured;
235
	}
236
	
237
	/**
238
	 * Set a new connection for this service provider. This will reset the index
239
	 * and DStore server locations to their default values.
240
	 * 
241
	 * @param services new remote service provider
242
	 * @param connection new connection
243
	 */
244
	public void setConnection(IRemoteServices services, IRemoteConnection connection) {
245
		setConnection(services, connection, true);
246
	}
247
	
248
	/**
249
	 * Set the host name for this connection
250
	 * 
251
	 * @param hostName
252
	 */
253
	public void setConnectionName(String connectionName) {
254
		putString(CONNECTION_NAME_KEY, connectionName);
255
 	}
256
	
257
	public void setDStoreEnv(String env) {
258
		putString(DSTORE_ENV_KEY, env);
259
	}
260
	
261
	public void setDStoreCommand(String command) {
262
		putString(DSTORE_COMMAND_KEY, command);
263
	}
264
	
265
	public void setDStoreLocation(String path) {
266
		putString(DSTORE_LOCATION_KEY, path);
267
	}
268
	
269
	/* (non-Javadoc)
270
	 * @see org.eclipse.ptp.rdt.core.serviceproviders.IIndexServiceProvider#setIndexLocation(java.lang.String)
271
	 */
272
	public void setIndexLocation(String path) {
273
		putString(INDEX_LOCATION_KEY, path);
274
	}
275
	
276
	/**
277
	 * @param serviceId
278
	 */
279
	public void setServiceId(String serviceId) {
280
		putString(SERVICE_ID_KEY, serviceId);
281
 	}
282
	
283
	/* (non-Javadoc)
284
	 * @see java.lang.Object#toString()
285
	 */
286
	@Override
287
	public String toString() {
288
		return "RemoteCIndexServiceProvider2(" + getIndexLocation() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
289
	}
290
	
291
	private void initialize() {
292
		if (fSubsystem == null && getServiceId() != null) {
293
			IRemoteServices services = PTPRemoteCorePlugin.getDefault().getRemoteServices(getServiceId());
294
			if (services != null && getConnectionName() != null) {
295
				IRemoteConnection connection = services.getConnectionManager().getConnection(getConnectionName());
296
				setConnection(services, connection, false);
297
			}
298
		}
299
	}
300
	
301
	/**
302
	 * Set a new connection for this service provider. If reset is true the index
303
	 * and DStore server locations will be reset to their default values.
304
	 * 
305
	 * @param services new remote service provider
306
	 * @param connection new connection
307
	 * @param reset reset locations to defaults
308
	 */
309
	private void setConnection(IRemoteServices services, IRemoteConnection connection, boolean reset) {
310
		setServiceId(services.getId());
311
		setConnectionName(connection.getName());
312
		if (reset) {
313
			IPath workingDir = new Path(services.getFileManager(connection).getWorkingDirectory());
314
			setIndexLocation(workingDir.append(".eclipsesettings").toString()); //$NON-NLS-1$
315
			setDStoreLocation(workingDir.toString());
316
		}
317
		if (fSubsystem != null) {
318
			fSubsystem.dispose();
319
		}
320
		fSubsystem = new RemoteCIndexSubsystem2(this);
321
		setConfigured(true);
322
	}
323
324
}
(-)src/org/eclipse/ptp/rdt/ui/wizards/RemoteCIndexServiceProvider2Contributer.java (+255 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
 *    IBM Corporation - 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.wizard.IWizard;
17
import org.eclipse.jface.wizard.IWizardPage;
18
import org.eclipse.jface.wizard.WizardPage;
19
import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteCIndexServiceProvider2;
20
import org.eclipse.ptp.rdt.ui.wizards.DStoreServerWidget.FieldModifier;
21
import org.eclipse.ptp.remote.core.IRemoteConnection;
22
import org.eclipse.ptp.remote.core.IRemoteServices;
23
import org.eclipse.ptp.remote.core.PTPRemoteCorePlugin;
24
import org.eclipse.ptp.remote.ui.IRemoteUIConnectionManager;
25
import org.eclipse.ptp.remote.ui.PTPRemoteUIPlugin;
26
import org.eclipse.ptp.services.core.IServiceProvider;
27
import org.eclipse.ptp.services.ui.IServiceProviderContributor;
28
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.events.ModifyEvent;
30
import org.eclipse.swt.events.ModifyListener;
31
import org.eclipse.swt.events.SelectionAdapter;
32
import org.eclipse.swt.events.SelectionEvent;
33
import org.eclipse.swt.layout.GridData;
34
import org.eclipse.swt.layout.GridLayout;
35
import org.eclipse.swt.widgets.Button;
36
import org.eclipse.swt.widgets.Combo;
37
import org.eclipse.swt.widgets.Composite;
38
import org.eclipse.swt.widgets.Group;
39
import org.eclipse.swt.widgets.Label;
40
41
42
public class RemoteCIndexServiceProvider2Contributer implements IServiceProviderContributor {
43
44
	private RemoteCIndexServiceProvider2 fProvider;
45
	
46
	private Map<Integer, IRemoteServices> fComboIndexToRemoteServicesProviderMap = new HashMap<Integer, IRemoteServices>();
47
	private IRemoteServices fSelectedServices;
48
	private Map<Integer, IRemoteConnection> fComboIndexToRemoteConnectionMap = new HashMap<Integer, IRemoteConnection>();
49
	private IRemoteConnection fSelectedConnection;
50
	private DStoreServerWidget fServerWidget;
51
	private String fDStorePath;
52
	private String fDStoreCommand;
53
	private String fDStoreEnv;
54
	private String fConfigPath;
55
	
56
	/* (non-Javadoc)
57
	 * @see org.eclipse.ptp.services.ui.IServiceProviderContributor#configureServiceProvider(org.eclipse.ptp.services.core.IServiceProvider, org.eclipse.swt.widgets.Composite)
58
	 */
59
	public void configureServiceProvider(IServiceProvider sp, final Composite container) {
60
		if(!(sp instanceof RemoteCIndexServiceProvider2))
61
			throw new IllegalArgumentException(); // should never happen
62
		
63
		fProvider = (RemoteCIndexServiceProvider2) sp;
64
65
		container.setLayout(new GridLayout(1, false));
66
		
67
		Group connectionGroup = new Group(container, SWT.NONE);
68
		connectionGroup.setText("Connection"); //$NON-NLS-1$
69
		connectionGroup.setLayout(new GridLayout(3, false));
70
		connectionGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
71
		
72
        // Label for "Provider:"
73
        Label providerLabel = new Label(connectionGroup, SWT.LEFT);
74
        providerLabel.setText("Provider:"); //$NON-NLS-1$
75
        
76
        // combo for providers
77
        final Combo providerCombo = new Combo(connectionGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
78
        // set layout to grab horizontal space
79
        GridData data = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
80
        data.horizontalSpan = 2;
81
        providerCombo.setLayoutData(data);
82
        
83
        populateProviderCombo(providerCombo);
84
            
85
        // connection combo
86
        // Label for "Connection:"
87
        Label connectionLabel = new Label(connectionGroup, SWT.LEFT);
88
        connectionLabel.setText("Connection:"); //$NON-NLS-1$
89
        
90
        // combo for providers
91
        final Combo connectionCombo = new Combo(connectionGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
92
        // set layout to grab horizontal space
93
        connectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
94
        
95
        // populate the combo with a list of providers
96
        populateConnectionCombo(connectionCombo);
97
           
98
        // new connection button
99
        final Button newConnectionButton = new Button(connectionGroup, SWT.PUSH);
100
        newConnectionButton.setText("New..."); //$NON-NLS-1$
101
        updateNewConnectionButtonEnabled(newConnectionButton);
102
        
103
        newConnectionButton.addSelectionListener(new SelectionAdapter() {
104
			public void widgetSelected(SelectionEvent e) {
105
				IRemoteUIConnectionManager connectionManager = getUIConnectionManager();
106
				if(connectionManager != null) {
107
					connectionManager.newConnection(container.getShell());
108
				}
109
				// refresh list of connections
110
				populateConnectionCombo(connectionCombo);
111
			}
112
        });
113
        
114
        providerCombo.addSelectionListener(new SelectionAdapter() {
115
			public void widgetSelected(SelectionEvent e) {
116
				int selectionIndex = providerCombo.getSelectionIndex();
117
				fSelectedServices = fComboIndexToRemoteServicesProviderMap.get(selectionIndex);
118
				populateConnectionCombo(connectionCombo);
119
				updateNewConnectionButtonEnabled(newConnectionButton);
120
				fServerWidget.setConnection(fSelectedServices, fSelectedConnection);
121
			}
122
        });
123
        
124
        connectionCombo.addSelectionListener(new SelectionAdapter() {
125
			public void widgetSelected(SelectionEvent e) {
126
				int selectionIndex = connectionCombo.getSelectionIndex();
127
				fSelectedConnection = fComboIndexToRemoteConnectionMap.get(selectionIndex);
128
				updateNewConnectionButtonEnabled(newConnectionButton);
129
				fProvider.setConnection(fSelectedServices, fSelectedConnection);
130
				fServerWidget.setConnection(fSelectedServices, fSelectedConnection);
131
			}
132
        });
133
        
134
        fServerWidget = new DStoreServerWidget(container, SWT.NONE);
135
        data = new GridData(SWT.FILL, SWT.FILL, true, false);
136
        data.horizontalSpan = 3;
137
        fServerWidget.setLayoutData(data); // set layout to grab horizontal space
138
        
139
        /*
140
         * Set connection information before updating widget with
141
         * saved data.
142
         */
143
		fServerWidget.setConnection(fSelectedServices, fSelectedConnection);
144
		
145
        fServerWidget.addModifyListener(new ModifyListener() {
146
			public void modifyText(ModifyEvent e) {
147
				if (e.data == FieldModifier.VALUE_DSTORE_LOCATION) {
148
					fDStorePath = fServerWidget.getDStoreLocation();
149
					fProvider.setDStoreLocation(fDStorePath);
150
				}
151
				if (e.data == FieldModifier.VALUE_DSTORE_COMMAND) {
152
			        fDStoreCommand = fServerWidget.getDStoreCommand();
153
					fProvider.setDStoreCommand(fDStoreCommand);
154
				}
155
				if (e.data == FieldModifier.VALUE_DSTORE_ENV) {
156
					fDStoreEnv = fServerWidget.getDStoreEnvironment();
157
					fProvider.setDStoreEnv(fDStoreEnv);
158
				}
159
				if (e.data == FieldModifier.VALUE_INDEX_LOCATION) {
160
					fConfigPath = fServerWidget.getIndexLocation();
161
					fProvider.setIndexLocation(fConfigPath);
162
				}
163
			}
164
		});
165
 
166
		/*
167
         * Initialize widget with default values. This will trigger
168
         * ModifyEvents on the widget to update the field variables.
169
         */
170
        fServerWidget.setDStoreCommand(fProvider.getDStoreCommand());
171
        fServerWidget.setDStoreEnvironment(fProvider.getDStoreEnv());
172
        fServerWidget.setDStoreLocation(fProvider.getDStoreLocation());
173
        fServerWidget.setIndexLocation(fProvider.getIndexLocation());
174
	}
175
	
176
	/* (non-Javadoc)
177
	 * @see org.eclipse.ptp.services.ui.IServiceProviderContributor#getWizard(org.eclipse.ptp.services.core.IServiceProvider, org.eclipse.jface.wizard.IWizardPage)
178
	 */
179
	public IWizard getWizard(IServiceProvider provider, IWizardPage page) {
180
		// TODO Auto-generated method stub
181
		return null;
182
	}
183
	
184
	/* (non-Javadoc)
185
     * @see org.eclipse.ptp.services.ui.IServiceProviderContributor#getWizardPages(org.eclipse.jface.wizard.IWizard, org.eclipse.ptp.services.core.IServiceProvider)
186
     */
187
    public WizardPage[] getWizardPages(IWizard wizard, IServiceProvider provider) {
188
		// TODO Auto-generated method stub
189
		return null;
190
	}
191
	
192
    private IRemoteUIConnectionManager getUIConnectionManager() {
193
		IRemoteUIConnectionManager connectionManager = 
194
			PTPRemoteUIPlugin.getDefault().getRemoteUIServices(fSelectedServices).getUIConnectionManager();
195
		return connectionManager;
196
	}
197
    
198
	private void populateConnectionCombo(final Combo connectionCombo) {
199
		connectionCombo.removeAll();
200
		
201
		//attempt to restore settings from saved state
202
        IRemoteConnection connectionSelected = null;
203
	    if (fProvider.getServiceId() != null) {
204
		    IRemoteServices providerSelected = PTPRemoteCorePlugin.getDefault().getRemoteServices(fProvider.getServiceId()); 
205
	        if (providerSelected != null && fProvider.getConnectionName() != null) {
206
	        	connectionSelected = providerSelected.getConnectionManager().getConnection(fProvider.getConnectionName());
207
	        }
208
	    }
209
	    
210
		IRemoteConnection[] connections = fSelectedServices.getConnectionManager().getConnections();
211
		int toSelect = 0;
212
        
213
        for(int k = 0; k < connections.length; k++) {
214
        	connectionCombo.add(connections[k].getName(), k);
215
        	fComboIndexToRemoteConnectionMap.put(k, connections[k]);
216
        	if (connectionSelected != null && connectionSelected.getName().equals(connections[k].getName())) {
217
        		toSelect = k;
218
        	}
219
        }
220
        
221
        // set selected connection to be the first one if we're not restoring from settings
222
        connectionCombo.select(toSelect);
223
        fSelectedConnection = fComboIndexToRemoteConnectionMap.get(toSelect);
224
	}
225
	
226
	private void populateProviderCombo(final Combo providerCombo) {
227
        //attempt to restore settings from saved state
228
        IRemoteServices providerSelected = null;
229
        if (fProvider.getServiceId() != null) {
230
        	providerSelected = PTPRemoteCorePlugin.getDefault().getRemoteServices(fProvider.getServiceId()); 
231
        }
232
233
        // populate the combo with a list of providers
234
        IRemoteServices[] providers = PTPRemoteCorePlugin.getDefault().getAllRemoteServices();
235
        int toSelect = 0;
236
        
237
        for(int k = 0; k < providers.length; k++) {
238
        	providerCombo.add(providers[k].getName(), k);
239
        	fComboIndexToRemoteServicesProviderMap.put(k, providers[k]);
240
        	
241
        	if (providerSelected != null && providerSelected.getId().compareTo(providers[k].getId()) == 0) {
242
        		toSelect = k;
243
        	}
244
        }
245
        
246
        // set selected host to be the first one if we're not restoring from settings
247
        providerCombo.select(toSelect);
248
        fSelectedServices = fComboIndexToRemoteServicesProviderMap.get(toSelect);
249
	}
250
	
251
	private void updateNewConnectionButtonEnabled(Button button) {
252
    	IRemoteUIConnectionManager connectionManager = getUIConnectionManager();
253
    	button.setEnabled(connectionManager != null);  	
254
    }
255
}
(-)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.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.Path;
23
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.core.runtime.Status;
25
import org.eclipse.jface.dialogs.ErrorDialog;
26
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
27
import org.eclipse.jface.operation.IRunnableWithProgress;
28
import org.eclipse.ptp.rdt.ui.UIPlugin;
29
import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteBuildServiceProvider;
30
import org.eclipse.ptp.remote.core.IRemoteConnection;
31
import org.eclipse.ptp.remote.core.IRemoteServices;
32
import org.eclipse.ptp.remote.core.PTPRemoteCorePlugin;
33
import org.eclipse.ptp.remote.core.exception.RemoteConnectionException;
34
import org.eclipse.ptp.remote.ui.IRemoteUIConnectionManager;
35
import org.eclipse.ptp.remote.ui.IRemoteUIConstants;
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
								String selectedPath = fileMgr.browseDirectory(fLocationText.getShell(), "Project Location (" + fSelectedConnection.getName() + ")", correctPath, IRemoteUIConstants.NONE); //$NON-NLS-1$ //$NON-NLS-2$
443
								if (selectedPath != null) {
444
									fLocationText.setText(selectedPath);
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 293929