KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > product > SplashLocationSection


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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     /* (non-Javadoc)
51      * @see org.eclipse.pde.internal.ui.editor.PDESection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
52      */

53     protected void createClient(Section section, FormToolkit toolkit) {
54         
55         // Configure section
56
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         // Create and configure client
62
Composite client = toolkit.createComposite(section);
63         client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 3));
64         client.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
65         // Create label
66
Label label = toolkit.createLabel(client, PDEUIMessages.SplashSection_label, SWT.WRAP);
67         GridData gd = new GridData();
68         gd.horizontalSpan = 3;
69         label.setLayoutData(gd);
70         // Create form entry
71
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         // Register to be notified when the model changes
86
getModel().addModelChangedListener(this);
87     }
88     
89     /* (non-Javadoc)
90      * @see org.eclipse.ui.forms.AbstractFormPart#refresh()
91      */

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     /* (non-Javadoc)
146      * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
147      */

148     public void modelChanged(IModelChangedEvent e) {
149         // No need to call super, handling world changed event here
150
if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
151             handleModelEventWorldChanged(e);
152         }
153     }
154
155     /**
156      * @param event
157      */

158     private void handleModelEventWorldChanged(IModelChangedEvent event) {
159         refresh();
160     }
161     
162     /* (non-Javadoc)
163      * @see org.eclipse.ui.forms.AbstractFormPart#dispose()
164      */

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