20
20
import java .io .ByteArrayInputStream ;
21
21
import java .io .InputStream ;
22
22
import java .util .ArrayList ;
23
+ import java .util .HashMap ;
23
24
import java .util .Iterator ;
24
- import java .util .Set ;
25
+ import java .util .List ;
26
+ import java .util .Map ;
25
27
import java .util .Vector ;
26
28
27
29
import org .eclipse .core .runtime .CoreException ;
@@ -288,7 +290,7 @@ public boolean doGlobalAction(String actionId) {
288
290
289
291
@ Override
290
292
protected boolean canPaste (Object targetObject , Object [] sourceObjects ) {
291
- Set <String > existingImportsSet = null ;
293
+ Map <String , Boolean > existingImportsMap = null ;
292
294
// Only import objects that are not already existing imports can be
293
295
// pasted
294
296
for (Object sourceObject : sourceObjects ) {
@@ -298,12 +300,12 @@ protected boolean canPaste(Object targetObject, Object[] sourceObjects) {
298
300
}
299
301
// Get the current import objects and store them for searching
300
302
// purposes
301
- if (existingImportsSet == null ) {
302
- existingImportsSet = PluginSelectionDialog .getExistingImports (getModel (), false );
303
+ if (existingImportsMap == null ) {
304
+ existingImportsMap = PluginSelectionDialog .getExistingImports (getModel (), false );
303
305
}
304
306
// Only import object that do not exist are allowed
305
307
ImportObject importObject = (ImportObject ) sourceObject ;
306
- if (existingImportsSet .contains (importObject .getImport ().getId ())) {
308
+ if (existingImportsMap . keySet () .contains (importObject .getImport ().getId ())) {
307
309
return false ;
308
310
}
309
311
}
@@ -427,21 +429,28 @@ else if (base instanceof PluginBaseNode)
427
429
428
430
private void handleAdd () {
429
431
IPluginModelBase model = (IPluginModelBase ) getPage ().getModel ();
430
- PluginSelectionDialog dialog = new PluginSelectionDialog (PDEPlugin .getActiveWorkbenchShell (), getAvailablePlugins (model ), true );
432
+ PluginSelectionDialog dialog = new PluginSelectionDialog (PDEPlugin .getActiveWorkbenchShell (), getAvailablePlugins (model ), true , model );
431
433
dialog .create ();
432
434
if (dialog .open () == Window .OK ) {
433
435
Object [] models = dialog .getResult ();
434
- IPluginImport [] imports = new IPluginImport [models .length ];
436
+ List <IPluginImport > imports = new ArrayList <>();
437
+ HashMap <String , Boolean > existingImports = PluginSelectionDialog .getExistingImports (model , false );
435
438
try {
436
439
for (int i = 0 ; i < models .length ; i ++) {
440
+ if (!existingImports .keySet ().contains (((IPluginModel ) models [i ]).getPluginBase ().getId ())) {
437
441
IPluginModel candidate = (IPluginModel ) models [i ];
438
442
String pluginId = candidate .getPlugin ().getId ();
439
443
IPluginImport importNode = createImport (model .getPluginFactory (), pluginId );
440
444
String version = VersionUtil .computeInitialPluginVersion (candidate .getPlugin ().getVersion ());
441
445
importNode .setVersion (version );
442
- imports [i ] = importNode ;
446
+ imports .add (importNode );
447
+ }
448
+ }
449
+ if (imports .size () > 0 ) {
450
+ IPluginImport [] pluginImports = new IPluginImport [imports .size ()];
451
+ pluginImports = imports .toArray (pluginImports );
452
+ addImports (model .getPluginBase (), pluginImports );
443
453
}
444
- addImports (model .getPluginBase (), imports );
445
454
} catch (CoreException e ) {
446
455
}
447
456
}
@@ -497,15 +506,14 @@ public void swap(int index1, int index2) {
497
506
498
507
private IPluginModelBase [] getAvailablePlugins (IPluginModelBase model ) {
499
508
IPluginModelBase [] plugins = PluginRegistry .getActiveModels (false );
500
- Set <String > existingImports = PluginSelectionDialog .getExistingImports (model , false );
509
+ HashMap <String , Boolean > existingImports = PluginSelectionDialog .getExistingImports (model , false );
501
510
ArrayList <IPluginModelBase > result = new ArrayList <>();
502
511
for (int i = 0 ; i < plugins .length ; i ++) {
503
- if (!existingImports . contains ( plugins [i ].getPluginBase ().getId ())) {
512
+ if (!getModel (). getPluginBase (). getId (). equals ( plugins [i ].getPluginBase ().getId ()))
504
513
result .add (plugins [i ]);
505
- }
506
514
}
507
515
508
- if (!existingImports .contains ("system.bundle" )) //$NON-NLS-1$
516
+ if (!existingImports .keySet (). contains ("system.bundle" )) //$NON-NLS-1$
509
517
addSystemBundle (result );
510
518
return result .toArray (new IPluginModelBase [result .size ()]);
511
519
}
0 commit comments