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(); |