18
18
19
19
import java .util .Comparator ;
20
20
import java .util .HashMap ;
21
- import java .util .HashSet ;
22
21
23
22
import org .eclipse .core .runtime .CoreException ;
24
23
import org .eclipse .core .runtime .IProgressMonitor ;
25
24
import org .eclipse .core .runtime .IStatus ;
26
25
import org .eclipse .core .runtime .Status ;
27
26
import org .eclipse .jface .dialogs .IDialogConstants ;
28
27
import org .eclipse .jface .dialogs .IDialogSettings ;
28
+ import org .eclipse .jface .viewers .StructuredSelection ;
29
29
import org .eclipse .osgi .service .resolver .ExportPackageDescription ;
30
30
import org .eclipse .osgi .service .resolver .VersionRange ;
31
31
import org .eclipse .pde .core .plugin .IFragment ;
43
43
import org .eclipse .pde .internal .ui .IHelpContextIds ;
44
44
import org .eclipse .pde .internal .ui .PDEPlugin ;
45
45
import org .eclipse .pde .internal .ui .PDEUIMessages ;
46
+ import org .eclipse .swt .widgets .Button ;
46
47
import org .eclipse .swt .widgets .Composite ;
47
48
import org .eclipse .swt .widgets .Control ;
48
49
import org .eclipse .swt .widgets .Shell ;
@@ -137,6 +138,11 @@ public PluginSelectionDialog(Shell parentShell, IPluginModelBase[] models, boole
137
138
setListLabelProvider (PDEPlugin .getDefault ().getLabelProvider ());
138
139
}
139
140
141
+ public PluginSelectionDialog (Shell activeWorkbenchShell , IPluginModelBase [] availablePlugins ,
142
+ boolean multipleSelection , IPluginModelBase model ) {
143
+ this (activeWorkbenchShell , availablePlugins , multipleSelection );
144
+ PDEPlugin .getDefault ().getLabelProvider ().setCurrentModel (model );
145
+ }
140
146
@ Override
141
147
protected void configureShell (Shell newShell ) {
142
148
super .configureShell (newShell );
@@ -153,8 +159,8 @@ private static IPluginModelBase[] getElements(boolean includeFragments) {
153
159
return PluginRegistry .getActiveModels (includeFragments );
154
160
}
155
161
156
- public static HashSet <String > getExistingImports (IPluginModelBase model , boolean includeImportPkg ) {
157
- HashSet <String > existingImports = new HashSet <>();
162
+ public static HashMap <String , Boolean > getExistingImports (IPluginModelBase model , boolean includeImportPkg ) {
163
+ HashMap <String , Boolean > existingImports = new HashMap <>();
158
164
addSelfAndDirectImports (existingImports , model );
159
165
if (model instanceof IFragmentModel ) {
160
166
IFragment fragment = ((IFragmentModel ) model ).getFragment ();
@@ -169,33 +175,34 @@ public static HashSet<String> getExistingImports(IPluginModelBase model, boolean
169
175
return existingImports ;
170
176
}
171
177
172
- private static void addSelfAndDirectImports (HashSet <String > set , IPluginModelBase model ) {
178
+ private static void addSelfAndDirectImports (HashMap <String , Boolean > existingImports , IPluginModelBase model ) {
173
179
if (model == null ) {
174
180
return ;
175
181
}
176
- set . add (model .getPluginBase ().getId ());
182
+ existingImports . put (model .getPluginBase ().getId (), false );
177
183
IPluginImport [] imports = model .getPluginBase ().getImports ();
178
184
for (IPluginImport pImport : imports ) {
179
185
String id = pImport .getId ();
180
- if ( set . add (id )) {
181
- addReexportedImport (set , id );
182
- }
186
+ existingImports . put (id , false );
187
+ addReexportedImport (existingImports , id );
188
+
183
189
}
184
190
}
185
191
186
- private static void addReexportedImport (HashSet <String > set , String id ) {
192
+ private static void addReexportedImport (HashMap <String , Boolean > existingImports , String id ) {
187
193
IPluginModelBase model = PluginRegistry .findModel (id );
188
194
if (model != null ) {
189
195
IPluginImport [] imports = model .getPluginBase ().getImports ();
190
196
for (IPluginImport pImport : imports ) {
191
- if (pImport .isReexported () && set .add (pImport .getId ())) {
192
- addReexportedImport (set , pImport .getId ());
197
+ if (pImport .isReexported ()) {
198
+ existingImports .put (pImport .getId (), true );
199
+ addReexportedImport (existingImports , pImport .getId ());
193
200
}
194
201
}
195
202
}
196
203
}
197
204
198
- private static void addImportedPackages (IBundlePluginModelBase base , HashSet <String > existingImports ) {
205
+ private static void addImportedPackages (IBundlePluginModelBase base , HashMap <String , Boolean > existingImports ) {
199
206
HashMap <String , ImportPackageObject > map = getImportPackages (base );
200
207
if (map == null ) {
201
208
return ;
@@ -220,7 +227,7 @@ private static void addImportedPackages(IBundlePluginModelBase base, HashSet<Str
220
227
continue ;
221
228
}
222
229
}
223
- existingImports .add (exported [i ].getSupplier ().getSymbolicName ());
230
+ existingImports .put (exported [i ].getSupplier ().getSymbolicName (), false );
224
231
}
225
232
}
226
233
}
@@ -297,4 +304,22 @@ protected void createButtonsForButtonBar(Composite parent) {
297
304
createButton (parent , IDialogConstants .CANCEL_ID , IDialogConstants .CANCEL_LABEL , false );
298
305
}
299
306
307
+ @ Override
308
+ protected void updateButtonsEnableState (IStatus status ) {
309
+ super .updateButtonsEnableState (status );
310
+ Button okButton = getOkButton ();
311
+ StructuredSelection currentSelection = super .getSelectedItems ();
312
+ HashMap <String , Boolean > existingImports = PluginSelectionDialog
313
+ .getExistingImports (PDEPlugin .getDefault ().getLabelProvider ().getCurrentPluginModel (), false );
314
+ if (!currentSelection .isEmpty ())
315
+ okButton .setEnabled (false );
316
+ for (Object selection : currentSelection ) {
317
+ if (selection instanceof IPluginModelBase
318
+ && !(existingImports .keySet ().contains (((IPluginModelBase ) selection ).getPluginBase ().getId ()))) {
319
+ okButton .setEnabled (true );
320
+ break ;
321
+ }
322
+
323
+ }
324
+ }
300
325
}
0 commit comments