1 11 package org.eclipse.pde.internal.ui.editor.feature; 12 13 import java.lang.reflect.*; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jface.dialogs.Dialog; 17 import org.eclipse.jface.operation.*; 18 import org.eclipse.jface.viewers.*; 19 import org.eclipse.jface.wizard.*; 20 import org.eclipse.pde.core.plugin.*; 21 import org.eclipse.pde.internal.core.*; 22 import org.eclipse.pde.internal.core.ifeature.*; 23 import org.eclipse.pde.internal.ui.*; 24 import org.eclipse.pde.internal.ui.elements.*; 25 import org.eclipse.pde.internal.ui.parts.*; 26 import org.eclipse.pde.internal.ui.wizards.*; 27 import org.eclipse.swt.*; 28 import org.eclipse.swt.layout.*; 29 import org.eclipse.swt.widgets.*; 30 import org.eclipse.ui.*; 31 import org.eclipse.ui.forms.widgets.*; 32 33 public abstract class ReferenceWizardPage extends WizardPage { 34 public static final String KEY_PLUGINS = 35 "FeatureEditor.PluginSection.new.label"; protected IFeatureModel model; 37 private TablePart checkboxTablePart; 38 private CheckboxTableViewer pluginViewer; 39 private boolean includeExternal; 40 41 class PluginContentProvider 42 extends DefaultContentProvider 43 implements IStructuredContentProvider { 44 public Object [] getElements(Object parent) { 45 return getChoices(); 46 } 47 } 48 49 class TablePart extends WizardCheckboxTablePart { 50 public TablePart() { 51 super(PDEPlugin.getResourceString(KEY_PLUGINS)); 52 } 53 public void updateCounter(int count) { 54 super.updateCounter(count); 55 setPageComplete(count>0); 56 } 57 protected StructuredViewer createStructuredViewer( 58 Composite parent, 59 int style, 60 FormToolkit toolkit) { 61 StructuredViewer viewer = 62 super.createStructuredViewer(parent, style, toolkit); 63 viewer.setSorter(ListUtil.PLUGIN_SORTER); 64 return viewer; 65 } 66 } 67 68 public ReferenceWizardPage(IFeatureModel model, boolean includeExternal) { 69 super("newFeaturePluginPage"); this.model = model; 71 setPageComplete(false); 72 checkboxTablePart = new TablePart(); 73 PDEPlugin.getDefault().getLabelProvider().connect(this); 74 this.includeExternal = includeExternal; 75 } 76 77 public void dispose() { 78 PDEPlugin.getDefault().getLabelProvider().disconnect(this); 79 super.dispose(); 80 } 81 82 public void createControl(Composite parent) { 83 Composite container = new Composite(parent, SWT.NULL); 84 GridLayout layout = new GridLayout(); 85 layout.numColumns = 2; 86 container.setLayout(layout); 87 88 createPluginList(container); 89 initialize(); 90 setControl(container); 91 Dialog.applyDialogFont(container); 92 } 93 94 protected void createPluginList(Composite parent) { 95 checkboxTablePart.createControl(parent); 96 pluginViewer = checkboxTablePart.getTableViewer(); 97 pluginViewer.setContentProvider(new PluginContentProvider()); 98 pluginViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider()); 99 pluginViewer.addFilter(new ViewerFilter() { 100 public boolean select(Viewer v, Object parent, Object object) { 101 if (object instanceof IPluginModelBase) { 102 IPluginModelBase model = (IPluginModelBase) object; 103 return !isOnTheList(model); 104 } 105 return true; 106 } 107 }); 108 pluginViewer.setSorter(ListUtil.PLUGIN_SORTER); 109 GridData gd = (GridData)checkboxTablePart.getControl().getLayoutData(); 110 gd.heightHint = 300; 111 } 112 113 protected abstract boolean isOnTheList(IPluginModelBase candidate); 114 115 public void init(IWorkbench workbench) { 116 } 117 118 private void initialize() { 119 pluginViewer.setInput(model.getFeature()); 120 checkboxTablePart.setSelection(new Object [0]); 121 } 122 123 private Object [] getAllChoices() { 124 PluginModelManager pmng = PDECore.getDefault().getModelManager(); 125 return pmng.getPlugins(); 126 } 127 128 private Object [] getChoices() { 129 if (includeExternal) return getAllChoices(); 130 WorkspaceModelManager mng = PDECore.getDefault().getWorkspaceModelManager(); 131 IPluginModel[] plugins = mng.getPluginModels(); 132 IFragmentModel[] fragments = mng.getFragmentModels(); 133 134 Object [] choices = new Object [plugins.length + fragments.length]; 135 System.arraycopy(plugins, 0, choices, 0, plugins.length); 136 System.arraycopy(fragments, 0, choices, plugins.length, fragments.length); 137 return choices; 138 } 139 140 public boolean finish() { 141 final Object [] candidates = checkboxTablePart.getSelection(); 142 IRunnableWithProgress op = new IRunnableWithProgress() { 143 public void run(IProgressMonitor monitor) throws InvocationTargetException { 144 try { 145 doAdd(candidates, monitor); 146 } catch (CoreException e) { 147 throw new InvocationTargetException(e); 148 } 149 } 150 }; 151 try { 152 getContainer().run(false, false, op); 153 } catch (InterruptedException e) { 154 return false; 155 } catch (InvocationTargetException e) { 156 PDEPlugin.logException(e); 157 return false; 158 } 159 return true; 160 } 161 162 protected abstract void doAdd(Object [] candidates, IProgressMonitor monitor) throws CoreException; 163 } 164 | Popular Tags |