|
Lines 11-36
Link Here
|
| 11 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 12 |
package org.eclipse.ui.internal.ide.misc; |
12 |
package org.eclipse.ui.internal.ide.misc; |
| 13 |
|
13 |
|
| 14 |
import java.io.IOException; |
|
|
| 15 |
import java.io.StringReader; |
| 16 |
import java.io.StringWriter; |
| 17 |
import java.util.LinkedList; |
| 18 |
|
| 19 |
import org.eclipse.core.filesystem.IFileInfoFilter; |
14 |
import org.eclipse.core.filesystem.IFileInfoFilter; |
| 20 |
import org.eclipse.core.resources.IFilterDescriptor; |
15 |
import org.eclipse.core.resources.IFilterDescriptor; |
| 21 |
import org.eclipse.core.resources.IProject; |
16 |
import org.eclipse.core.resources.IProject; |
| 22 |
import org.eclipse.core.resources.IResourceFilter; |
17 |
import org.eclipse.core.resources.IResourceFilter; |
| 23 |
import org.eclipse.core.runtime.IPath; |
|
|
| 24 |
import org.eclipse.ui.IMemento; |
| 25 |
import org.eclipse.ui.WorkbenchException; |
| 26 |
import org.eclipse.ui.XMLMemento; |
| 27 |
|
18 |
|
| 28 |
/** |
19 |
/** |
| 29 |
* Resource Filter Type allowing serializing sub filters as the arguments |
20 |
* Resource Filter Type allowing serializing sub filters as the arguments |
| 30 |
*/ |
21 |
*/ |
| 31 |
public class CompoundResourceFilter { |
22 |
public class CompoundResourceFilter { |
| 32 |
|
23 |
|
| 33 |
private static final String T_FILTERS = "filters"; //$NON-NLS-1$ |
24 |
// private static final String T_FILTERS = "filters"; //$NON-NLS-1$ |
| 34 |
|
25 |
|
| 35 |
protected IFileInfoFilter instantiate(IProject project, |
26 |
protected IFileInfoFilter instantiate(IProject project, |
| 36 |
IResourceFilter filter) { |
27 |
IResourceFilter filter) { |
|
Lines 42-51
Link Here
|
| 42 |
return null; |
33 |
return null; |
| 43 |
} |
34 |
} |
| 44 |
|
35 |
|
| 45 |
private static final String T_FILTER = "filter"; //$NON-NLS-1$ |
36 |
// private static final String T_FILTER = "filter"; //$NON-NLS-1$ |
| 46 |
private static final String T_TYPE = "type"; //$NON-NLS-1$ |
37 |
// private static final String T_TYPE = "type"; //$NON-NLS-1$ |
| 47 |
private static final String T_ID = "id"; //$NON-NLS-1$ |
38 |
// private static final String T_ID = "id"; //$NON-NLS-1$ |
| 48 |
private static final String T_ARGUMENTS = "arguments"; //$NON-NLS-1$ |
39 |
// private static final String T_ARGUMENTS = "arguments"; //$NON-NLS-1$ |
| 49 |
|
40 |
|
| 50 |
/** |
41 |
/** |
| 51 |
* Unserialize the filters stored in a memento |
42 |
* Unserialize the filters stored in a memento |
|
Lines 54-103
Link Here
|
| 54 |
* @param memento |
45 |
* @param memento |
| 55 |
* @return the filter array |
46 |
* @return the filter array |
| 56 |
*/ |
47 |
*/ |
| 57 |
public static IResourceFilter[] unserialize(final IProject project, |
48 |
// public static IResourceFilter[] unserialize(final IProject project, |
| 58 |
String memento) { |
49 |
// String memento) { |
| 59 |
LinkedList filters = new LinkedList(); |
50 |
// LinkedList filters = new LinkedList(); |
| 60 |
XMLMemento mementoObject = null; |
51 |
// XMLMemento mementoObject = null; |
| 61 |
try { |
52 |
// try { |
| 62 |
mementoObject = XMLMemento |
53 |
// mementoObject = XMLMemento |
| 63 |
.createReadRoot(new StringReader(memento)); |
54 |
// .createReadRoot(new StringReader(memento)); |
| 64 |
} catch (WorkbenchException e) { |
55 |
// } catch (WorkbenchException e) { |
| 65 |
return new IResourceFilter[0]; |
56 |
// return new IResourceFilter[0]; |
| 66 |
} |
57 |
// } |
| 67 |
IMemento childMem = mementoObject.getChild(T_FILTERS); |
58 |
// IMemento childMem = mementoObject.getChild(T_FILTERS); |
| 68 |
if (childMem != null) { |
59 |
// if (childMem != null) { |
| 69 |
IMemento[] elementMem = childMem.getChildren(T_FILTER); |
60 |
// IMemento[] elementMem = childMem.getChildren(T_FILTER); |
| 70 |
for (int i = 0; i < elementMem.length; i++) { |
61 |
// for (int i = 0; i < elementMem.length; i++) { |
| 71 |
final String id = elementMem[i].getString(T_ID); |
62 |
// final String id = elementMem[i].getString(T_ID); |
| 72 |
final int type = elementMem[i].getInteger(T_TYPE).intValue(); |
63 |
// final int type = elementMem[i].getInteger(T_TYPE).intValue(); |
| 73 |
IMemento argumentMem = elementMem[i].getChild(T_ARGUMENTS); |
64 |
// IMemento argumentMem = elementMem[i].getChild(T_ARGUMENTS); |
| 74 |
final String arguments = argumentMem != null ? argumentMem |
65 |
// final String arguments = argumentMem != null ? argumentMem |
| 75 |
.getTextData() : ""; //$NON-NLS-1$ |
66 |
// .getTextData() : ""; //$NON-NLS-1$ |
| 76 |
filters.add(new IResourceFilter() { |
67 |
// filters.add(new IResourceFilter() { |
| 77 |
public String getArguments() { |
68 |
// public String getArguments() { |
| 78 |
return arguments; |
69 |
// return arguments; |
| 79 |
} |
70 |
// } |
| 80 |
|
71 |
// |
| 81 |
public String getId() { |
72 |
// public String getId() { |
| 82 |
return id; |
73 |
// return id; |
| 83 |
} |
74 |
// } |
| 84 |
|
75 |
// |
| 85 |
public IPath getPath() { |
76 |
// public IPath getPath() { |
| 86 |
return null; |
77 |
// return null; |
| 87 |
} |
78 |
// } |
| 88 |
|
79 |
// |
| 89 |
public IProject getProject() { |
80 |
// public IProject getProject() { |
| 90 |
return project; |
81 |
// return project; |
| 91 |
} |
82 |
// } |
| 92 |
|
83 |
// |
| 93 |
public int getType() { |
84 |
// public int getType() { |
| 94 |
return type; |
85 |
// return type; |
| 95 |
} |
86 |
// } |
| 96 |
}); |
87 |
// }); |
| 97 |
} |
88 |
// } |
| 98 |
} |
89 |
// } |
| 99 |
return (IResourceFilter[]) filters.toArray(new IResourceFilter[0]); |
90 |
// return (IResourceFilter[]) filters.toArray(new IResourceFilter[0]); |
| 100 |
} |
91 |
// } |
| 101 |
|
92 |
|
| 102 |
/** |
93 |
/** |
| 103 |
* Serialize filters into in a memento |
94 |
* Serialize filters into in a memento |
|
Lines 105-130
Link Here
|
| 105 |
* @param filters |
96 |
* @param filters |
| 106 |
* @return the memento |
97 |
* @return the memento |
| 107 |
*/ |
98 |
*/ |
| 108 |
public static String serialize(IResourceFilter[] filters) { |
99 |
// public static String serialize(IResourceFilter[] filters) { |
| 109 |
XMLMemento memento = XMLMemento.createWriteRoot("memento"); //$NON-NLS-1$ |
100 |
// XMLMemento memento = XMLMemento.createWriteRoot("memento"); //$NON-NLS-1$ |
| 110 |
|
101 |
// |
| 111 |
IMemento expandedMem = memento.createChild(T_FILTERS); |
102 |
// IMemento expandedMem = memento.createChild(T_FILTERS); |
| 112 |
for (int i = 0; i < filters.length; i++) { |
103 |
// for (int i = 0; i < filters.length; i++) { |
| 113 |
IMemento elementMem = expandedMem.createChild(T_FILTER); |
104 |
// IMemento elementMem = expandedMem.createChild(T_FILTER); |
| 114 |
elementMem.putString(T_ID, filters[i].getId()); |
105 |
// elementMem.putString(T_ID, filters[i].getId()); |
| 115 |
elementMem.putInteger(T_TYPE, filters[i].getType()); |
106 |
// elementMem.putInteger(T_TYPE, filters[i].getType()); |
| 116 |
IMemento argumentMem = elementMem.createChild(T_ARGUMENTS); |
107 |
// IMemento argumentMem = elementMem.createChild(T_ARGUMENTS); |
| 117 |
argumentMem.putTextData(filters[i].getArguments()); |
108 |
// argumentMem.putTextData(filters[i].getArguments()); |
| 118 |
} |
109 |
// } |
| 119 |
|
110 |
// |
| 120 |
StringWriter writer = new StringWriter(); |
111 |
// StringWriter writer = new StringWriter(); |
| 121 |
try { |
112 |
// try { |
| 122 |
memento.save(writer); |
113 |
// memento.save(writer); |
| 123 |
} catch (IOException e) { |
114 |
// } catch (IOException e) { |
| 124 |
return ""; //$NON-NLS-1$ |
115 |
// return ""; //$NON-NLS-1$ |
| 125 |
} |
116 |
// } |
| 126 |
return writer.toString(); |
117 |
// return writer.toString(); |
| 127 |
} |
118 |
// } |
| 128 |
|
119 |
|
| 129 |
protected abstract class FileInfoFilter implements IFileInfoFilter { |
120 |
protected abstract class FileInfoFilter implements IFileInfoFilter { |
| 130 |
protected IFileInfoFilter[] filterTypes; |
121 |
protected IFileInfoFilter[] filterTypes; |