View | Details | Raw Unified | Return to bug 264788 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/xsl/core/internal/util/XMLContentType.java (+93 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009  Standards for Technology in Automotive Retail 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
 *     David Carver (bug 264788) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.wst.xsl.core.internal.util;
12
13
import java.util.*;
14
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.content.*;
17
18
/**
19
 * XMLContetType handles the gathering of XML content type related information
20
 * between the platforms xml content type and WTP's specific version.
21
 *  
22
 * @author David Carver
23
 * @since 1.0
24
 *
25
 */
26
public class XMLContentType {
27
	private static final String XMLSOURCE_CONTENTTYPE = "org.eclipse.wst.xml.core.xmlsource";
28
	private static final String PLATFORM_XMLSOURCE_CONTENTTYPE = "org.eclipse.core.runtime.xml";
29
30
	private IContentTypeManager contentTypeManager = null;
31
32
	public XMLContentType() {
33
		contentTypeManager = Platform.getContentTypeManager();
34
		IContentType contentType;
35
	}
36
	
37
	/**
38
	 * Returns all the extensions associated with an XML Content Type. 
39
	 * @return The array of file extensions
40
	 * @since 1.0
41
	 */
42
	public String[] getFileExtensions() {
43
		String[] platformXMLContentTypes = getPlatformFileExtensions();
44
		String[] xmlContentTypes = getWTPFileExtensions();
45
		
46
		xmlContentTypes = combineAvailableContentTypes(platformXMLContentTypes, xmlContentTypes);
47
		
48
		return xmlContentTypes;
49
	}
50
	
51
52
	private String[] combineAvailableContentTypes(String[] conentTypesToAdd,
53
			String[] originalConentTypes) {
54
		
55
		ArrayList<String> arrayList = new ArrayList<String>();
56
		if (conentTypesToAdd != null && conentTypesToAdd.length > 0) {
57
			arrayList = new ArrayList<String>(Arrays.asList(originalConentTypes));
58
			for (int cnt = 0; cnt < conentTypesToAdd.length; cnt++) {
59
				if (!arrayList.contains(conentTypesToAdd[cnt])) {
60
					arrayList.add(conentTypesToAdd[cnt]);
61
				}
62
			}
63
		}
64
		
65
		String[] xmlContentTypes = new String[arrayList.size()];
66
		arrayList.toArray(xmlContentTypes);
67
		
68
		return xmlContentTypes;
69
	}
70
71
	/**
72
	 * Gets all the Eclipse Platform file extensions for the core XML content type.
73
	 * @return An array of Extensions.
74
	 * @since 1.0
75
	 */
76
	public String[] getPlatformFileExtensions() {
77
		IContentType contentType = contentTypeManager.getContentType(PLATFORM_XMLSOURCE_CONTENTTYPE); 
78
		String[] xmlContentTypes = contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
79
		return xmlContentTypes;
80
	}
81
82
	/**
83
	 * Gets all the file extensions that correspond to the base WTP XML content type.
84
	 * @return Retuns an array of extensions.
85
	 * @since 1.0
86
	 */
87
	public String[] getWTPFileExtensions() {
88
		IContentType contentType = contentTypeManager.getContentType(XMLSOURCE_CONTENTTYPE); 
89
		String[] xmlContentTypes = contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
90
		return xmlContentTypes;
91
	}
92
93
}
(-)src/org/eclipse/wst/xsl/internal/debug/ui/tabs/main/InputFileBlock.java (-9 / +14 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Doug Satchwell (Chase Technology Ltd) - initial API and implementation
9
 *     Doug Satchwell (Chase Technology Ltd) - initial API and implementation
10
 *     Stuart Harper - added "open files" selector
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.wst.xsl.internal.debug.ui.tabs.main;
12
package org.eclipse.wst.xsl.internal.debug.ui.tabs.main;
12
13
Lines 30-36 Link Here
30
31
31
public class InputFileBlock extends ResourceSelectionBlock
32
public class InputFileBlock extends ResourceSelectionBlock
32
{
33
{
33
	private static final String XMLSOURCE_CONTENTTYPE = "org.eclipse.wst.xml.core.xmlsource";
34
//	private static final String XMLSOURCE_CONTENTTYPE = "org.eclipse.wst.xml.core.xmlsource";
34
	private final IFile defaultFile;
35
	private final IFile defaultFile;
35
	IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
36
	IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
36
37
Lines 40-53 Link Here
40
		this.defaultFile = defaultFile;
41
		this.defaultFile = defaultFile;
41
	}
42
	}
42
43
43
	@Override
44
//	@Override
44
	protected String[] getFileExtensions()
45
//	protected String[] getFileExtensions()
45
	{
46
//	{
46
		IContentType contentType = contentTypeManager.getContentType(XMLSOURCE_CONTENTTYPE); 
47
//		IContentType contentType = contentTypeManager.getContentType(XMLSOURCE_CONTENTTYPE); 
47
		String[] xmlContentTypes = contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
48
//		String[] xmlContentTypes = contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
48
		
49
//		
49
		return xmlContentTypes;
50
//		return xmlContentTypes;
50
	}
51
//	}
51
52
52
	public void setDefaults(ILaunchConfigurationWorkingCopy configuration)
53
	public void setDefaults(ILaunchConfigurationWorkingCopy configuration)
53
	{
54
	{
Lines 135-140 Link Here
135
				return Messages.InputFileBlock_WORKSPACE_BUTTON;
136
				return Messages.InputFileBlock_WORKSPACE_BUTTON;
136
			case WORKSPACE_DIALOG_TITLE:
137
			case WORKSPACE_DIALOG_TITLE:
137
				return Messages.InputFileBlock_WORKSPACE_DIALOG_TITLE;
138
				return Messages.InputFileBlock_WORKSPACE_DIALOG_TITLE;
139
			case OPENFILES_BUTTON:
140
				return Messages.InputFileBlock_OPENFILES_BUTTON;
141
			case OPENFILES_DIALOG_TITLE:
142
				return Messages.InputFileBlock_OPENFILES_DIALOG;	
138
		}
143
		}
139
		return "" + type; //$NON-NLS-1$
144
		return "" + type; //$NON-NLS-1$
140
	}
145
	}
(-)src/org/eclipse/wst/xsl/debug/ui/Messages.java (+5 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     Doug Satchwell (Chase Technology Ltd) - initial API and implementation
9
 *     Doug Satchwell (Chase Technology Ltd) - initial API and implementation
10
 *     David Carver (STAR) - updated to meet Galileo requirements
10
 *     David Carver (STAR) - updated to meet Galileo requirements
11
 *     Stuart Harper - added "open files" selector
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.wst.xsl.debug.ui;
13
package org.eclipse.wst.xsl.debug.ui;
13
14
Lines 125-130 Link Here
125
	public static String InputFileBlock_FILE_SYSTEM_BUTTON;
126
	public static String InputFileBlock_FILE_SYSTEM_BUTTON;
126
127
127
	public static String InputFileBlock_WORKSPACE_BUTTON;
128
	public static String InputFileBlock_WORKSPACE_BUTTON;
129
	
130
	public static String InputFileBlock_OPENFILES_BUTTON;
131
	
132
	public static String InputFileBlock_OPENFILES_DIALOG;
128
133
129
	public static String InputFileBlock_Name;
134
	public static String InputFileBlock_Name;
130
135
(-)src/org/eclipse/wst/xsl/debug/ui/messages.properties (+2 lines)
Lines 41-46 Link Here
41
InputFileBlock_VARIABLES_BUTTON=Variables...
41
InputFileBlock_VARIABLES_BUTTON=Variables...
42
InputFileBlock_FILE_SYSTEM_BUTTON=File System...
42
InputFileBlock_FILE_SYSTEM_BUTTON=File System...
43
InputFileBlock_WORKSPACE_BUTTON=Workspace...
43
InputFileBlock_WORKSPACE_BUTTON=Workspace...
44
InputFileBlock_OPENFILES_BUTTON=Open Files...
45
InputFileBlock_OPENFILES_DIALOG=Select File
44
InputFileBlock_Name=XML Input File
46
InputFileBlock_Name=XML Input File
45
InputFileBlock_Exception_occurred_reading_configuration=Exception occurred reading configuration
47
InputFileBlock_Exception_occurred_reading_configuration=Exception occurred reading configuration
46
InputFileBlock_WORKSPACE_DIALOG_TITLE=File Selection
48
InputFileBlock_WORKSPACE_DIALOG_TITLE=File Selection
(-)src/org/eclipse/wst/xsl/internal/debug/ui/ResourceSelectionBlock.java (-3 / +93 lines)
Lines 7-16 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Doug Satchwell (Chase Technology Ltd) - initial API and implementation
9
 *     Doug Satchwell (Chase Technology Ltd) - initial API and implementation
10
 *     Stuart Harper - bug 264788 - added "open files" selector
11
 *     David Carver (STAR) - bug 264788 - pulled up getFileExtensions from InputFileBlock
10
 *******************************************************************************/
12
 *******************************************************************************/
11
package org.eclipse.wst.xsl.internal.debug.ui;
13
package org.eclipse.wst.xsl.internal.debug.ui;
12
14
13
import java.io.File;
15
import java.io.File;
16
import java.lang.reflect.Array;
17
import java.util.ArrayList;
18
import java.util.Arrays;
14
19
15
import org.eclipse.core.resources.IContainer;
20
import org.eclipse.core.resources.IContainer;
16
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IFile;
Lines 20-31 Link Here
20
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IPath;
26
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.IStatus;
28
import org.eclipse.core.runtime.Path;
29
import org.eclipse.core.runtime.Platform;
23
import org.eclipse.core.runtime.Status;
30
import org.eclipse.core.runtime.Status;
31
import org.eclipse.core.runtime.content.IContentType;
32
import org.eclipse.core.runtime.content.IContentTypeManager;
24
import org.eclipse.core.variables.IStringVariableManager;
33
import org.eclipse.core.variables.IStringVariableManager;
25
import org.eclipse.core.variables.VariablesPlugin;
34
import org.eclipse.core.variables.VariablesPlugin;
26
import org.eclipse.debug.core.ILaunchConfiguration;
35
import org.eclipse.debug.core.ILaunchConfiguration;
27
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
36
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
28
import org.eclipse.debug.ui.StringVariableSelectionDialog;
37
import org.eclipse.debug.ui.StringVariableSelectionDialog;
38
import org.eclipse.jface.viewers.LabelProvider;
29
import org.eclipse.jface.viewers.Viewer;
39
import org.eclipse.jface.viewers.Viewer;
30
import org.eclipse.jface.viewers.ViewerFilter;
40
import org.eclipse.jface.viewers.ViewerFilter;
31
import org.eclipse.jface.window.Window;
41
import org.eclipse.jface.window.Window;
Lines 43-53 Link Here
43
import org.eclipse.swt.widgets.Group;
53
import org.eclipse.swt.widgets.Group;
44
import org.eclipse.swt.widgets.Label;
54
import org.eclipse.swt.widgets.Label;
45
import org.eclipse.swt.widgets.Text;
55
import org.eclipse.swt.widgets.Text;
56
import org.eclipse.ui.IEditorInput;
57
import org.eclipse.ui.IEditorPart;
58
import org.eclipse.ui.IEditorReference;
59
import org.eclipse.ui.PlatformUI;
60
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
46
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
61
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
47
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
62
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
48
import org.eclipse.ui.model.WorkbenchContentProvider;
63
import org.eclipse.ui.model.WorkbenchContentProvider;
49
import org.eclipse.ui.model.WorkbenchLabelProvider;
64
import org.eclipse.ui.model.WorkbenchLabelProvider;
50
import org.eclipse.ui.views.navigator.ResourceComparator;
65
import org.eclipse.ui.views.navigator.ResourceComparator;
66
import org.eclipse.wst.xsl.core.internal.util.XMLContentType;
51
import org.eclipse.wst.xsl.debug.ui.Messages;
67
import org.eclipse.wst.xsl.debug.ui.Messages;
52
68
53
69
Lines 71-80 Link Here
71
	protected static final int FILE_SYSTEM_BUTTON = 9;
87
	protected static final int FILE_SYSTEM_BUTTON = 9;
72
	protected static final int WORKSPACE_BUTTON = 10;
88
	protected static final int WORKSPACE_BUTTON = 10;
73
	protected static final int WORKSPACE_DIALOG_TITLE = 11;
89
	protected static final int WORKSPACE_DIALOG_TITLE = 11;
90
	protected static final int OPENFILES_BUTTON = 12;
91
	protected static final int OPENFILES_DIALOG_TITLE = 13;
74
92
75
	protected Button fWorkspaceButton;
93
	protected Button fWorkspaceButton;
76
	protected Button fFileSystemButton;
94
	protected Button fFileSystemButton;
77
	protected Button fVariablesButton;
95
	protected Button fVariablesButton;
96
	protected Button fOpenFilesButton;
78
	protected Button useDefaultCheckButton;
97
	protected Button useDefaultCheckButton;
79
	protected Text resourceText;
98
	protected Text resourceText;
80
	protected WidgetListener widgetListener = new WidgetListener();
99
	protected WidgetListener widgetListener = new WidgetListener();
Lines 85-91 Link Here
85
	protected boolean required;
104
	protected boolean required;
86
	protected String defaultResource;
105
	protected String defaultResource;
87
	protected String resource;
106
	protected String resource;
88
	protected String fileLabel = Messages.ResourceSelectionBlock_0; 
107
	protected String fileLabel = Messages.ResourceSelectionBlock_0;
108
	private static final String XMLSOURCE_CONTENTTYPE = "org.eclipse.wst.xml.core.xmlsource";
109
	private static final String PLATFORM_XMLSOURCE_CONTENTTYPE = "org.eclipse.core.runtime.xml";
110
111
	
112
	IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
113
89
114
90
	private final ISelectionStatusValidator validator = new ISelectionStatusValidator()
115
	private final ISelectionStatusValidator validator = new ISelectionStatusValidator()
91
	{
116
	{
Lines 134-139 Link Here
134
			{
159
			{
135
				updateResourceText(useDefaultCheckButton.getSelection());
160
				updateResourceText(useDefaultCheckButton.getSelection());
136
			}
161
			}
162
			else if (source == fOpenFilesButton)
163
			{
164
				handleOpenFilesResourceBrowseButtonSelected();
165
			}
137
		}
166
		}
138
	}
167
	}
139
168
Lines 267-273 Link Here
267
		new Label(parent, SWT.NONE);
296
		new Label(parent, SWT.NONE);
268
297
269
		Composite buttonComp = new Composite(parent, SWT.NONE);
298
		Composite buttonComp = new Composite(parent, SWT.NONE);
270
		GridLayout layout = new GridLayout(3, false);
299
		GridLayout layout = new GridLayout(4, false);
271
		layout.marginHeight = 0;
300
		layout.marginHeight = 0;
272
		layout.marginWidth = 0;
301
		layout.marginWidth = 0;
273
		buttonComp.setLayout(layout);
302
		buttonComp.setLayout(layout);
Lines 284-289 Link Here
284
313
285
		fVariablesButton = createPushButton(buttonComp, getMessage(VARIABLES_BUTTON), null);
314
		fVariablesButton = createPushButton(buttonComp, getMessage(VARIABLES_BUTTON), null);
286
		fVariablesButton.addSelectionListener(widgetListener);
315
		fVariablesButton.addSelectionListener(widgetListener);
316
		
317
		fOpenFilesButton = createPushButton(buttonComp, getMessage(OPENFILES_BUTTON), null);
318
		fOpenFilesButton.addSelectionListener(widgetListener);
287
	}
319
	}
288
320
289
	protected void updateResourceText(boolean useDefault)
321
	protected void updateResourceText(boolean useDefault)
Lines 357-365 Link Here
357
389
358
	protected String[] getFileExtensions()
390
	protected String[] getFileExtensions()
359
	{
391
	{
360
		return null;
392
		return new XMLContentType().getFileExtensions();
361
	}
393
	}
394
	
395
	protected void handleOpenFilesResourceBrowseButtonSelected()
396
	{
397
		String path = openFileListResourceDialog();
398
		if (path != null)
399
			setText("${workspace_loc:" + path + "}");   //$NON-NLS-1$ //$NON-NLS-2$
400
	}
401
	/**
402
	 * Opens a dialog displaying a list of all XML files in the editor and allows the user to select one of them.
403
	 * @return The path to the selected XML file or null if none was chosen.
404
	 */
405
	protected String openFileListResourceDialog(){
406
		IEditorReference[] editors = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
407
				
408
		WorkbenchContentProvider w = new WorkbenchContentProvider();
409
		String[] paths = filterOpenEditorsByFileExtension(editors);
410
		
411
		ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new LabelProvider());
362
412
413
		dialog.setTitle(getMessage(OPENFILES_DIALOG_TITLE));
414
		dialog.setElements(paths);
415
		dialog.open();
416
		
417
		return (String)dialog.getFirstResult();
418
		
419
	}
420
421
	private String[] filterOpenEditorsByFileExtension(IEditorReference[] editors) {
422
		String [] paths = new String[editors.length];
423
		String [] fileExts = getFileExtensions();
424
		
425
		for(int i =0; i<editors.length; i++){
426
			IEditorReference currentEditor = editors[i];
427
			IEditorPart editorPart = currentEditor.getEditor(true);
428
            IPath path = ((IFile) editorPart.getEditorInput().getAdapter(IFile.class)).getFullPath();
429
            
430
            if (path != null) {
431
            	paths[i] = getEditorPath(path, fileExts);
432
			}
433
		}
434
		return paths;
435
	}
436
437
	private String getEditorPath(IPath filePath, String[] fileExts) {
438
		if (fileExts == null || fileExts.length == 0) {
439
			return filePath.toOSString();
440
		}
441
		
442
		String path = null;
443
		for (int cnt = 0; cnt < fileExts.length; cnt++) {
444
			if (filePath.getFileExtension().equals(fileExts[cnt])) {
445
				path = filePath.toOSString();
446
				break;
447
			}
448
		}		
449
		return path;
450
	}
451
	
452
	
363
	protected void handleWorkspaceResourceBrowseButtonSelected()
453
	protected void handleWorkspaceResourceBrowseButtonSelected()
364
	{
454
	{
365
		IPath path = openWorkspaceResourceDialog();
455
		IPath path = openWorkspaceResourceDialog();

Return to bug 264788