1 11 package org.eclipse.pde.internal.ui.editor.product; 12 13 import org.eclipse.jface.window.Window; 14 import org.eclipse.pde.core.IModelChangedEvent; 15 import org.eclipse.pde.core.plugin.IPluginModelBase; 16 import org.eclipse.pde.core.plugin.PluginRegistry; 17 import org.eclipse.pde.internal.core.iproduct.IProduct; 18 import org.eclipse.pde.internal.core.iproduct.IProductModel; 19 import org.eclipse.pde.internal.core.iproduct.ISplashInfo; 20 import org.eclipse.pde.internal.ui.PDEPlugin; 21 import org.eclipse.pde.internal.ui.PDEUIMessages; 22 import org.eclipse.pde.internal.ui.editor.FormEntryAdapter; 23 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; 24 import org.eclipse.pde.internal.ui.editor.PDEFormPage; 25 import org.eclipse.pde.internal.ui.editor.PDESection; 26 import org.eclipse.pde.internal.ui.parts.FormEntry; 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.dnd.Clipboard; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.swt.widgets.Control; 32 import org.eclipse.swt.widgets.Display; 33 import org.eclipse.swt.widgets.Label; 34 import org.eclipse.swt.widgets.Text; 35 import org.eclipse.ui.IActionBars; 36 import org.eclipse.ui.dialogs.ElementListSelectionDialog; 37 import org.eclipse.ui.forms.widgets.FormToolkit; 38 import org.eclipse.ui.forms.widgets.Section; 39 40 41 public class SplashLocationSection extends PDESection { 42 43 private FormEntry fPluginEntry; 44 45 public SplashLocationSection(PDEFormPage page, Composite parent) { 46 super(page, parent, Section.DESCRIPTION); 47 createClient(getSection(), page.getEditor().getToolkit()); 48 } 49 50 53 protected void createClient(Section section, FormToolkit toolkit) { 54 55 section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1)); 57 GridData data = new GridData(GridData.FILL_HORIZONTAL); 58 section.setLayoutData(data); 59 section.setText(PDEUIMessages.SplashSection_title); 60 section.setDescription(PDEUIMessages.SplashSection_desc); 61 Composite client = toolkit.createComposite(section); 63 client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 3)); 64 client.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 65 Label label = toolkit.createLabel(client, PDEUIMessages.SplashSection_label, SWT.WRAP); 67 GridData gd = new GridData(); 68 gd.horizontalSpan = 3; 69 label.setLayoutData(gd); 70 IActionBars actionBars = getPage().getPDEEditor().getEditorSite().getActionBars(); 72 fPluginEntry = new FormEntry(client, toolkit, PDEUIMessages.SplashSection_plugin, PDEUIMessages.SplashSection_browse, false); 73 fPluginEntry.setFormEntryListener(new FormEntryAdapter(this, actionBars) { 74 public void textValueChanged(FormEntry entry) { 75 getSplashInfo().setLocation(entry.getValue(), false); 76 } 77 public void browseButtonSelected(FormEntry entry) { 78 handleBrowse(); 79 } 80 }); 81 fPluginEntry.setEditable(isEditable()); 82 83 toolkit.paintBordersFor(client); 84 section.setClient(client); 85 getModel().addModelChangedListener(this); 87 } 88 89 92 public void refresh() { 93 ISplashInfo info = getSplashInfo(); 94 fPluginEntry.setValue(info.getLocation(), true); 95 super.refresh(); 96 } 97 98 public void commit(boolean onSave) { 99 fPluginEntry.commit(); 100 super.commit(onSave); 101 } 102 103 public void cancelEdit() { 104 fPluginEntry.cancelEdit(); 105 super.cancelEdit(); 106 } 107 108 private ISplashInfo getSplashInfo() { 109 ISplashInfo info = getProduct().getSplashInfo(); 110 if (info == null) { 111 info = getModel().getFactory().createSplashInfo(); 112 getProduct().setSplashInfo(info); 113 } 114 return info; 115 } 116 117 private IProduct getProduct() { 118 return getModel().getProduct(); 119 } 120 121 private IProductModel getModel() { 122 return (IProductModel)getPage().getPDEEditor().getAggregateModel(); 123 } 124 125 private void handleBrowse() { 126 ElementListSelectionDialog dialog = new ElementListSelectionDialog(PDEPlugin.getActiveWorkbenchShell(), PDEPlugin.getDefault().getLabelProvider()); 127 dialog.setElements(PluginRegistry.getActiveModels()); 128 dialog.setMultipleSelection(false); 129 dialog.setTitle(PDEUIMessages.SplashSection_selection); 130 dialog.setMessage(PDEUIMessages.SplashSection_message); 131 if (dialog.open() == Window.OK) { 132 IPluginModelBase model = (IPluginModelBase)dialog.getFirstResult(); 133 fPluginEntry.setValue(model.getPluginBase().getId()); 134 } 135 } 136 137 public boolean canPaste(Clipboard clipboard) { 138 Display d = getSection().getDisplay(); 139 Control c = d.getFocusControl(); 140 if (c instanceof Text) 141 return true; 142 return false; 143 } 144 145 148 public void modelChanged(IModelChangedEvent e) { 149 if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) { 151 handleModelEventWorldChanged(e); 152 } 153 } 154 155 158 private void handleModelEventWorldChanged(IModelChangedEvent event) { 159 refresh(); 160 } 161 162 165 public void dispose() { 166 IProductModel model = getModel(); 167 if (model != null) { 168 model.removeModelChangedListener(this); 169 } 170 super.dispose(); 171 } 172 173 } 174 | Popular Tags |