Lines 17-28
import org.eclipse.jface.viewers.*;
Link Here
|
17 |
import org.eclipse.jface.window.Window; |
17 |
import org.eclipse.jface.window.Window; |
18 |
import org.eclipse.osgi.util.NLS; |
18 |
import org.eclipse.osgi.util.NLS; |
19 |
import org.eclipse.pde.core.IModelChangedEvent; |
19 |
import org.eclipse.pde.core.IModelChangedEvent; |
|
|
20 |
import org.eclipse.pde.core.plugin.*; |
20 |
import org.eclipse.pde.internal.core.*; |
21 |
import org.eclipse.pde.internal.core.*; |
21 |
import org.eclipse.pde.internal.core.ifeature.*; |
22 |
import org.eclipse.pde.internal.core.ifeature.*; |
22 |
import org.eclipse.pde.internal.core.isite.*; |
23 |
import org.eclipse.pde.internal.core.isite.*; |
23 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
24 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
24 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
25 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
25 |
import org.eclipse.pde.internal.ui.dialogs.FeatureSelectionDialog; |
26 |
import org.eclipse.pde.internal.ui.dialogs.FeatureSelectionDialog; |
|
|
27 |
import org.eclipse.pde.internal.ui.dialogs.PluginSelectionDialog; |
26 |
import org.eclipse.pde.internal.ui.editor.*; |
28 |
import org.eclipse.pde.internal.ui.editor.*; |
27 |
import org.eclipse.pde.internal.ui.editor.feature.FeatureEditor; |
29 |
import org.eclipse.pde.internal.ui.editor.feature.FeatureEditor; |
28 |
import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; |
30 |
import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; |
Lines 42-47
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
42 |
|
44 |
|
43 |
private static final int BUTTON_ADD_CATEGORY = 0; |
45 |
private static final int BUTTON_ADD_CATEGORY = 0; |
44 |
private static final int BUTTON_ADD_FEATURE = 1; |
46 |
private static final int BUTTON_ADD_FEATURE = 1; |
|
|
47 |
private static final int BUTTON_ADD_BUNDLE = 2; |
45 |
private static int fCounter; |
48 |
private static int fCounter; |
46 |
private ISiteModel fModel; |
49 |
private ISiteModel fModel; |
47 |
private TreePart fCategoryTreePart; |
50 |
private TreePart fCategoryTreePart; |
Lines 61-74
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
61 |
if (features[i].getCategories().length == 0) |
64 |
if (features[i].getCategories().length == 0) |
62 |
result.add(new SiteFeatureAdapter(null, features[i])); |
65 |
result.add(new SiteFeatureAdapter(null, features[i])); |
63 |
} |
66 |
} |
|
|
67 |
ISiteBundle[] bundles = fModel.getSite().getBundles(); |
68 |
for (int i = 0; i < bundles.length; i++) { |
69 |
if (bundles[i].getCategories().length == 0) { |
70 |
result.add(new SiteBundleAdapter(null, bundles[i])); |
71 |
} |
72 |
} |
64 |
return result.toArray(); |
73 |
return result.toArray(); |
65 |
} |
74 |
} |
66 |
|
75 |
|
67 |
public Object[] getChildren(Object parent) { |
76 |
public Object[] getChildren(Object parent) { |
68 |
if (parent instanceof ISiteCategoryDefinition) { |
77 |
if (parent instanceof ISiteCategoryDefinition) { |
69 |
ISiteCategoryDefinition catDef = (ISiteCategoryDefinition) parent; |
78 |
ISiteCategoryDefinition catDef = (ISiteCategoryDefinition) parent; |
70 |
ISiteFeature[] features = fModel.getSite().getFeatures(); |
|
|
71 |
HashSet result = new HashSet(); |
79 |
HashSet result = new HashSet(); |
|
|
80 |
ISiteFeature[] features = fModel.getSite().getFeatures(); |
72 |
for (int i = 0; i < features.length; i++) { |
81 |
for (int i = 0; i < features.length; i++) { |
73 |
ISiteCategory[] cats = features[i].getCategories(); |
82 |
ISiteCategory[] cats = features[i].getCategories(); |
74 |
for (int j = 0; j < cats.length; j++) { |
83 |
for (int j = 0; j < cats.length; j++) { |
Lines 77-82
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
77 |
} |
86 |
} |
78 |
} |
87 |
} |
79 |
} |
88 |
} |
|
|
89 |
ISiteBundle[] bundles = fModel.getSite().getBundles(); |
90 |
for (int i = 0; i < bundles.length; i++) { |
91 |
ISiteCategory[] cats = bundles[i].getCategories(); |
92 |
for (int j = 0; j < cats.length; j++) { |
93 |
if (cats[j].getDefinition() != null && cats[j].getDefinition().equals(catDef)) { |
94 |
result.add(new SiteBundleAdapter(cats[j].getName(), bundles[i])); |
95 |
} |
96 |
} |
97 |
} |
80 |
return result.toArray(); |
98 |
return result.toArray(); |
81 |
} |
99 |
} |
82 |
return new Object[0]; |
100 |
return new Object[0]; |
Lines 98-110
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
98 |
} |
116 |
} |
99 |
} |
117 |
} |
100 |
} |
118 |
} |
|
|
119 |
ISiteBundle[] bundles = fModel.getSite().getBundles(); |
120 |
for (int i = 0; i < bundles.length; i++) { |
121 |
ISiteCategory[] cats = bundles[i].getCategories(); |
122 |
for (int j = 0; j < cats.length; j++) { |
123 |
if (cats[j].getDefinition() != null && cats[j].getDefinition().equals(catDef)) { |
124 |
return true; |
125 |
} |
126 |
} |
127 |
} |
101 |
} |
128 |
} |
102 |
return false; |
129 |
return false; |
103 |
} |
130 |
} |
104 |
} |
131 |
} |
105 |
|
132 |
|
106 |
public CategorySection(PDEFormPage formPage, Composite parent) { |
133 |
public CategorySection(PDEFormPage formPage, Composite parent) { |
107 |
super(formPage, parent, Section.DESCRIPTION, new String[] {PDEUIMessages.CategoryDefinitionCategorySection_new, PDEUIMessages.CategorySection_add}); |
134 |
super(formPage, parent, Section.DESCRIPTION, new String[] {PDEUIMessages.CategoryDefinitionCategorySection_new, PDEUIMessages.CategorySection_add, PDEUIMessages.CategorySection_addBundle}); |
108 |
getSection().setText(PDEUIMessages.CategoryDefinitionCategorySection_title); |
135 |
getSection().setText(PDEUIMessages.CategoryDefinitionCategorySection_title); |
109 |
getSection().setDescription(PDEUIMessages.CategoryDefinitionCategorySection_desc); |
136 |
getSection().setDescription(PDEUIMessages.CategoryDefinitionCategorySection_desc); |
110 |
} |
137 |
} |
Lines 208-213
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
208 |
} |
235 |
} |
209 |
return true; |
236 |
return true; |
210 |
} |
237 |
} |
|
|
238 |
if (objects.length > 0 && objects[0] instanceof SiteBundleAdapter) { |
239 |
if (op == DND.DROP_COPY && target != null) { |
240 |
copyBundle((SiteBundleAdapter) objects[0], target); |
241 |
} else { |
242 |
moveBundle((SiteBundleAdapter) objects[0], target); |
243 |
} |
244 |
return true; |
245 |
} |
211 |
return false; |
246 |
return false; |
212 |
} |
247 |
} |
213 |
|
248 |
|
Lines 221-227
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
221 |
fCategoryViewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, transfers, new DragSourceListener() { |
256 |
fCategoryViewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, transfers, new DragSourceListener() { |
222 |
public void dragStart(DragSourceEvent event) { |
257 |
public void dragStart(DragSourceEvent event) { |
223 |
IStructuredSelection ssel = (IStructuredSelection) fCategoryViewer.getSelection(); |
258 |
IStructuredSelection ssel = (IStructuredSelection) fCategoryViewer.getSelection(); |
224 |
if (ssel == null || ssel.isEmpty() || !(ssel.getFirstElement() instanceof SiteFeatureAdapter)) { |
259 |
if (ssel == null || ssel.isEmpty() || !(ssel.getFirstElement() instanceof SiteFeatureAdapter || ssel.getFirstElement() instanceof SiteBundleAdapter)) { |
225 |
event.doit = false; |
260 |
event.doit = false; |
226 |
} |
261 |
} |
227 |
} |
262 |
} |
Lines 237-242
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
237 |
|
272 |
|
238 |
fCategoryTreePart.setButtonEnabled(BUTTON_ADD_CATEGORY, isEditable()); |
273 |
fCategoryTreePart.setButtonEnabled(BUTTON_ADD_CATEGORY, isEditable()); |
239 |
fCategoryTreePart.setButtonEnabled(BUTTON_ADD_FEATURE, isEditable()); |
274 |
fCategoryTreePart.setButtonEnabled(BUTTON_ADD_FEATURE, isEditable()); |
|
|
275 |
fCategoryTreePart.setButtonEnabled(BUTTON_ADD_BUNDLE, isEditable()); |
240 |
|
276 |
|
241 |
// fCategoryViewer.expandAll(); |
277 |
// fCategoryViewer.expandAll(); |
242 |
toolkit.paintBordersFor(container); |
278 |
toolkit.paintBordersFor(container); |
Lines 267-272
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
267 |
} |
303 |
} |
268 |
} |
304 |
} |
269 |
|
305 |
|
|
|
306 |
private void copyBundle(SiteBundleAdapter adapter, Object target) { |
307 |
ISiteBundle bundle = findRealBundle(adapter); |
308 |
if (bundle == null) { |
309 |
return; |
310 |
} |
311 |
if (target != null && target instanceof ISiteCategoryDefinition) { |
312 |
addCategory(bundle, ((ISiteCategoryDefinition) target).getName()); |
313 |
} |
314 |
} |
315 |
|
270 |
private void addCategory(ISiteFeature aFeature, String catName) { |
316 |
private void addCategory(ISiteFeature aFeature, String catName) { |
271 |
try { |
317 |
try { |
272 |
if (aFeature == null) |
318 |
if (aFeature == null) |
Lines 284-289
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
284 |
} |
330 |
} |
285 |
} |
331 |
} |
286 |
|
332 |
|
|
|
333 |
private void addCategory(ISiteBundle aBundle, String catName) { |
334 |
try { |
335 |
if (aBundle == null) |
336 |
return; |
337 |
ISiteCategory[] cats = aBundle.getCategories(); |
338 |
for (int j = 0; j < cats.length; j++) { |
339 |
if (cats[j].getName().equals(catName)) |
340 |
return; |
341 |
} |
342 |
ISiteCategory cat = fModel.getFactory().createCategory(aBundle); |
343 |
cat.setName(catName); |
344 |
expandCategory(catName); |
345 |
aBundle.addCategories(new ISiteCategory[] {cat}); |
346 |
} catch (CoreException e) { |
347 |
} |
348 |
} |
349 |
|
287 |
private void moveFeature(SiteFeatureAdapter adapter, Object target) { |
350 |
private void moveFeature(SiteFeatureAdapter adapter, Object target) { |
288 |
ISiteFeature feature = findRealFeature(adapter); |
351 |
ISiteFeature feature = findRealFeature(adapter); |
289 |
if (feature == null) { |
352 |
if (feature == null) { |
Lines 297-302
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
297 |
} |
360 |
} |
298 |
} |
361 |
} |
299 |
|
362 |
|
|
|
363 |
private void moveBundle(SiteBundleAdapter adapter, Object target) { |
364 |
ISiteBundle bundle = findRealBundle(adapter); |
365 |
if (bundle == null) { |
366 |
return; |
367 |
} |
368 |
if (adapter.category != null) { |
369 |
removeCategory(bundle, adapter.category); |
370 |
} |
371 |
if (target != null && target instanceof ISiteCategoryDefinition) { |
372 |
addCategory(bundle, ((ISiteCategoryDefinition) target).getName()); |
373 |
} |
374 |
} |
375 |
|
300 |
protected void buttonSelected(int index) { |
376 |
protected void buttonSelected(int index) { |
301 |
switch (index) { |
377 |
switch (index) { |
302 |
case BUTTON_ADD_CATEGORY : |
378 |
case BUTTON_ADD_CATEGORY : |
Lines 305-310
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
305 |
case BUTTON_ADD_FEATURE : |
381 |
case BUTTON_ADD_FEATURE : |
306 |
handleNewFeature(); |
382 |
handleNewFeature(); |
307 |
break; |
383 |
break; |
|
|
384 |
case BUTTON_ADD_BUNDLE : |
385 |
handleNewBundle(); |
386 |
break; |
308 |
} |
387 |
} |
309 |
} |
388 |
} |
310 |
|
389 |
|
Lines 415-420
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
415 |
} |
494 |
} |
416 |
} |
495 |
} |
417 |
|
496 |
|
|
|
497 |
private void removeCategory(ISiteBundle aBundle, String catName) { |
498 |
try { |
499 |
if (aBundle == null) |
500 |
return; |
501 |
ISiteCategory[] cats = aBundle.getCategories(); |
502 |
for (int i = 0; i < cats.length; i++) { |
503 |
if (catName.equals(cats[i].getName())) |
504 |
aBundle.removeCategories(new ISiteCategory[] {cats[i]}); |
505 |
} |
506 |
} catch (CoreException e) { |
507 |
} |
508 |
} |
509 |
|
418 |
private ISiteFeature findRealFeature(SiteFeatureAdapter adapter) { |
510 |
private ISiteFeature findRealFeature(SiteFeatureAdapter adapter) { |
419 |
ISiteFeature featureCopy = adapter.feature; |
511 |
ISiteFeature featureCopy = adapter.feature; |
420 |
ISiteFeature[] features = fModel.getSite().getFeatures(); |
512 |
ISiteFeature[] features = fModel.getSite().getFeatures(); |
Lines 426-431
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
426 |
return null; |
518 |
return null; |
427 |
} |
519 |
} |
428 |
|
520 |
|
|
|
521 |
private ISiteBundle findRealBundle(SiteBundleAdapter adapter) { |
522 |
ISiteBundle featureCopy = adapter.bundle; |
523 |
ISiteBundle[] bundles = fModel.getSite().getBundles(); |
524 |
for (int i = 0; i < bundles.length; i++) { |
525 |
if (bundles[i].getId().equals(featureCopy.getId()) && bundles[i].getVersion().equals(featureCopy.getVersion())) { |
526 |
return bundles[i]; |
527 |
} |
528 |
} |
529 |
return null; |
530 |
} |
531 |
|
429 |
public void dispose() { |
532 |
public void dispose() { |
430 |
super.dispose(); |
533 |
super.dispose(); |
431 |
FeatureModelManager mng = PDECore.getDefault().getFeatureModelManager(); |
534 |
FeatureModelManager mng = PDECore.getDefault().getFeatureModelManager(); |
Lines 565-570
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
565 |
}); |
668 |
}); |
566 |
} |
669 |
} |
567 |
|
670 |
|
|
|
671 |
private void handleNewBundle() { |
672 |
final Control control = fCategoryViewer.getControl(); |
673 |
BusyIndicator.showWhile(control.getDisplay(), new Runnable() { |
674 |
public void run() { |
675 |
IPluginModelBase[] allModels = PluginRegistry.getAllModels(); |
676 |
ArrayList newModels = new ArrayList(); |
677 |
for (int i = 0; i < allModels.length; i++) { |
678 |
if (canAdd(allModels[i])) |
679 |
newModels.add(allModels[i]); |
680 |
} |
681 |
IPluginModelBase[] candidateModels = (IPluginModelBase[]) newModels.toArray(new IPluginModelBase[newModels.size()]); |
682 |
PluginSelectionDialog dialog = new PluginSelectionDialog(fCategoryViewer.getTree().getShell(), candidateModels, true); |
683 |
if (dialog.open() == Window.OK) { |
684 |
Object[] models = dialog.getResult(); |
685 |
try { |
686 |
doAddBundles(models); |
687 |
} catch (CoreException e) { |
688 |
PDEPlugin.log(e); |
689 |
} |
690 |
} |
691 |
} |
692 |
}); |
693 |
} |
694 |
|
568 |
private boolean canAdd(IFeatureModel candidate) { |
695 |
private boolean canAdd(IFeatureModel candidate) { |
569 |
ISiteFeature[] features = fModel.getSite().getFeatures(); |
696 |
ISiteFeature[] features = fModel.getSite().getFeatures(); |
570 |
IFeature cfeature = candidate.getFeature(); |
697 |
IFeature cfeature = candidate.getFeature(); |
Lines 577-582
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
577 |
return true; |
704 |
return true; |
578 |
} |
705 |
} |
579 |
|
706 |
|
|
|
707 |
private boolean canAdd(IPluginModelBase candidate) { |
708 |
ISiteBundle[] currentBundles = fModel.getSite().getBundles(); |
709 |
IPluginBase candidateBundle = candidate.getPluginBase(); |
710 |
|
711 |
for (int i = 0; i < currentBundles.length; i++) { |
712 |
ISiteBundle currentBundle = currentBundles[i]; |
713 |
if (currentBundle.getId().equals(candidateBundle.getId()) && currentBundle.getVersion().equals(candidateBundle.getVersion())) |
714 |
return false; |
715 |
} |
716 |
return true; |
717 |
} |
718 |
|
580 |
public static ISiteFeature createSiteFeature(ISiteModel model, IFeatureModel featureModel) throws CoreException { |
719 |
public static ISiteFeature createSiteFeature(ISiteModel model, IFeatureModel featureModel) throws CoreException { |
581 |
IFeature feature = featureModel.getFeature(); |
720 |
IFeature feature = featureModel.getFeature(); |
582 |
ISiteFeature sfeature = model.getFactory().createFeature(); |
721 |
ISiteFeature sfeature = model.getFactory().createFeature(); |
Lines 594-599
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
594 |
return sfeature; |
733 |
return sfeature; |
595 |
} |
734 |
} |
596 |
|
735 |
|
|
|
736 |
private ISiteBundle createSiteBundle(ISiteModel model, IPluginModelBase candidate) throws CoreException { |
737 |
ISiteBundle newBundle = model.getFactory().createBundle(); |
738 |
newBundle.setId(candidate.getPluginBase().getId()); |
739 |
newBundle.setVersion(candidate.getPluginBase().getVersion()); |
740 |
return newBundle; |
741 |
} |
742 |
|
597 |
private static String formatVersion(String version) { |
743 |
private static String formatVersion(String version) { |
598 |
try { |
744 |
try { |
599 |
Version v = new Version(version); |
745 |
Version v = new Version(version); |
Lines 657-662
public class CategorySection extends TreeSection implements IFeatureModelListene
Link Here
|
657 |
} |
803 |
} |
658 |
} |
804 |
} |
659 |
|
805 |
|
|
|
806 |
/** |
807 |
* |
808 |
* @param candidates |
809 |
* Array of IPluginModelBase |
810 |
* @param monitor |
811 |
* @throws CoreException |
812 |
*/ |
813 |
public void doAddBundles(Object[] candidates) throws CoreException { |
814 |
// Category to add features to |
815 |
String categoryName = null; |
816 |
ISelection selection = fCategoryViewer.getSelection(); |
817 |
if (!selection.isEmpty() && selection instanceof IStructuredSelection) { |
818 |
Object element = ((IStructuredSelection) selection).getFirstElement(); |
819 |
if (element instanceof ISiteCategoryDefinition) { |
820 |
categoryName = ((ISiteCategoryDefinition) element).getName(); |
821 |
} else if (element instanceof SiteFeatureAdapter) { |
822 |
categoryName = ((SiteFeatureAdapter) element).category; |
823 |
} |
824 |
} |
825 |
// |
826 |
ISiteBundle[] added = new ISiteBundle[candidates.length]; |
827 |
for (int i = 0; i < candidates.length; i++) { |
828 |
IPluginModelBase candidate = (IPluginModelBase) candidates[i]; |
829 |
ISiteBundle child = createSiteBundle(fModel, candidate); |
830 |
if (categoryName != null) { |
831 |
addCategory(child, categoryName); |
832 |
} |
833 |
added[i] = child; |
834 |
} |
835 |
|
836 |
// Update model |
837 |
fModel.getSite().addBundles(added); |
838 |
// Select last added feature |
839 |
if (added.length > 0) { |
840 |
if (categoryName != null) { |
841 |
expandCategory(categoryName); |
842 |
} |
843 |
fCategoryViewer.setSelection(new StructuredSelection(new SiteBundleAdapter(categoryName, added[added.length - 1])), true); |
844 |
} |
845 |
} |
846 |
|
660 |
void fireSelection() { |
847 |
void fireSelection() { |
661 |
fCategoryViewer.setSelection(fCategoryViewer.getSelection()); |
848 |
fCategoryViewer.setSelection(fCategoryViewer.getSelection()); |
662 |
} |
849 |
} |