KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > feature > FeatureMatchSection


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

11 package org.eclipse.pde.internal.ui.editor.feature;
12
13 import java.util.Iterator JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.pde.core.plugin.IPluginReference;
18 import org.eclipse.pde.internal.core.ifeature.IFeatureImport;
19 import org.eclipse.pde.internal.ui.PDEPlugin;
20 import org.eclipse.pde.internal.ui.editor.*;
21 import org.eclipse.pde.internal.ui.editor.plugin.*;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.events.*;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.widgets.*;
26 import org.eclipse.ui.forms.widgets.*;
27
28 /**
29  * @author dejan
30  *
31  * To change this generated comment edit the template variable "typecomment":
32  * Window>Preferences>Java>Templates.
33  * To enable and disable the creation of type comments go to
34  * Window>Preferences>Java>Code Generation.
35  */

36 public class FeatureMatchSection extends MatchSection {
37     private Button patchButton;
38
39     /**
40      * Constructor for FeatureMatchSection.
41      * @param formPage
42      */

43     public FeatureMatchSection(PDEFormPage formPage, Composite parent) {
44         super(formPage, parent, false);
45     }
46
47     public void createClient(
48         Section section,
49         FormToolkit toolkit) {
50         super.createClient(section, toolkit);
51         Composite client = (Composite)section.getClient();
52         patchButton = toolkit.createButton(client, PDEPlugin.getResourceString("FeatureMatchSection.patch"), SWT.CHECK); //$NON-NLS-1$
53
GridData gd = new GridData();
54         gd.horizontalSpan = 2;
55         patchButton.setLayoutData(gd);
56         patchButton.setEnabled(false);
57         patchButton.setSelection(false);
58         patchButton.addSelectionListener(new SelectionAdapter() {
59             public void widgetSelected(SelectionEvent e) {
60                 handlePatchChange(patchButton.getSelection());
61             }
62         });
63     }
64
65     private void handlePatchChange(boolean patch) {
66         if (currentImport != null) {
67             IFeatureImport iimport = (IFeatureImport) currentImport;
68             if (iimport.getType() == IFeatureImport.FEATURE) {
69                 try {
70                     iimport.setPatch(patch);
71                 } catch (CoreException e) {
72                     PDEPlugin.logException(e);
73                 }
74             }
75         }
76         if (multiSelection != null) {
77             for (Iterator JavaDoc iter = multiSelection.iterator(); iter.hasNext();) {
78                 IFeatureImport iimport = (IFeatureImport) iter.next();
79                 try {
80                     iimport.setPatch(patch);
81                 } catch (CoreException e) {
82                     PDEPlugin.logException(e);
83                     break;
84                 }
85             }
86         }
87     }
88
89     protected void update(IStructuredSelection selection) {
90         super.update(selection);
91         if (patchButton == null)
92             return;
93         if (selection.isEmpty()) {
94             update((IFeatureImport) null);
95             return;
96         }
97         if (!(selection.getFirstElement() instanceof IFeatureImport))
98             return;
99         
100         if (selection.size() == 1) {
101             update((IFeatureImport) selection.getFirstElement());
102             return;
103         }
104         int ntrue = 0, nfalse = 0;
105
106         for (Iterator JavaDoc iter = selection.iterator(); iter.hasNext();) {
107             IFeatureImport iimport = (IFeatureImport) iter.next();
108             if (iimport.getType() == IFeatureImport.FEATURE) {
109                 if (iimport.isPatch())
110                     ntrue++;
111                 else
112                     nfalse++;
113             }
114         }
115         patchButton.setEnabled(isEditable() && (ntrue > 0 || nfalse > 0));
116         patchButton.setSelection(ntrue > 0);
117     }
118
119     protected void update(IPluginReference reference) {
120         super.update(reference);
121         if (patchButton == null)
122             return;
123         IFeatureImport fimport = (IFeatureImport)reference;
124         if (fimport == null || fimport.getType() == IFeatureImport.PLUGIN) {
125             patchButton.setSelection(false);
126             patchButton.setEnabled(false);
127             return;
128         }
129         patchButton.setEnabled(getPage().getModel().isEditable());
130         patchButton.setSelection(fimport.isPatch());
131     }
132 }
133
Popular Tags