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 .pde .core .plugin .IFragment ;
31
31
import org .eclipse .pde .core .plugin .IFragmentModel ;
42
42
import org .eclipse .pde .internal .ui .IHelpContextIds ;
43
43
import org .eclipse .pde .internal .ui .PDEPlugin ;
44
44
import org .eclipse .pde .internal .ui .PDEUIMessages ;
45
+ import org .eclipse .swt .widgets .Button ;
45
46
import org .eclipse .swt .widgets .Composite ;
46
47
import org .eclipse .swt .widgets .Control ;
47
48
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 ;
@@ -221,7 +228,7 @@ private static void addImportedPackages(IBundlePluginModelBase base, HashSet<Str
221
228
continue ;
222
229
}
223
230
}
224
- existingImports .add (exported [i ].getSupplier ().getSymbolicName ());
231
+ existingImports .put (exported [i ].getSupplier ().getSymbolicName (), false );
225
232
}
226
233
}
227
234
}
@@ -298,4 +305,22 @@ protected void createButtonsForButtonBar(Composite parent) {
298
305
createButton (parent , IDialogConstants .CANCEL_ID , IDialogConstants .CANCEL_LABEL , false );
299
306
}
300
307
301
- }
308
+ @ Override
309
+ protected void updateButtonsEnableState (IStatus status ) {
310
+ super .updateButtonsEnableState (status );
311
+ Button okButton = getOkButton ();
312
+ StructuredSelection currentSelection = super .getSelectedItems ();
313
+ HashMap <String , Boolean > existingImports = PluginSelectionDialog
314
+ .getExistingImports (PDEPlugin .getDefault ().getLabelProvider ().getCurrentPluginModel (), false );
315
+ if (!currentSelection .isEmpty ())
316
+ okButton .setEnabled (false );
317
+ for (Object selection : currentSelection ) {
318
+ if (selection instanceof IPluginModelBase
319
+ && !(existingImports .keySet ().contains (((IPluginModelBase ) selection ).getPluginBase ().getId ()))) {
320
+ okButton .setEnabled (true );
321
+ break ;
322
+ }
323
+
324
+ }
325
+ }
326
+ }
0 commit comments