blob: c2cf918da87b6eb40bc76851f18ce34ce332970c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/*******************************************************************************
* Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.team.internal.ui.wizards;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
public class PsfFilenameStore extends PsfStore {
private static final String FILENAMES = "filenames"; //$NON-NLS-1$
private static final String PREVIOUS = "previous"; //$NON-NLS-1$
// If a PSF file was selected when the wizard was opened, then this is it.
// This is only a cache; it is not part of the history until the user has used it.
private String _selectedFilename = null;
private static PsfFilenameStore instance;
public static PsfFilenameStore getInstance(){
if(instance==null){
instance = new PsfFilenameStore();
}
return instance;
}
private PsfFilenameStore() {
// Singleton
}
public void setDefaultFromSelection(IWorkbench workbench) {
// Scan the workbench for a selected PSF file
IWorkbenchWindow wnd = workbench.getActiveWorkbenchWindow();
IWorkbenchPage pg = wnd.getActivePage();
ISelection sel = pg.getSelection();
if (!(sel instanceof IStructuredSelection)) {
return;
}
IStructuredSelection selection = (IStructuredSelection)sel;
Object firstElement = selection.getFirstElement();
if (!(firstElement instanceof IAdaptable)) {
return;
}
Object o = ((IAdaptable) firstElement).getAdapter(IResource.class);
if (o == null) {
return;
}
IResource resource = (IResource) o;
if (resource.getType() != IResource.FILE) {
return;
}
if (!resource.isAccessible()) {
return;
}
String extension = resource.getFileExtension();
if (extension == null || !extension.equalsIgnoreCase("psf")) { //$NON-NLS-1$
return;
}
IWorkspace workspace = resource.getWorkspace();
workspace.getRoot().getFullPath();
IPath path = resource.getLocation();
_selectedFilename = path.toOSString();
}
@Override
public String getSuggestedDefault() {
if (_selectedFilename != null) {
return _selectedFilename;
}
return getPrevious();
}
@Override
protected String getPreviousTag() {
return PREVIOUS;
}
@Override
protected String getListTag() {
return FILENAMES;
}
}
|