KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > plugin > rows > ClassAttributeRow


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.plugin.rows;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.jdt.core.search.IJavaSearchConstants;
16 import org.eclipse.jdt.ui.IJavaElementSearchConstants;
17 import org.eclipse.pde.core.IBaseModel;
18 import org.eclipse.pde.core.plugin.IPluginBase;
19 import org.eclipse.pde.core.plugin.IPluginModelBase;
20 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
21 import org.eclipse.pde.internal.ui.editor.IContextPart;
22 import org.eclipse.pde.internal.ui.editor.contentassist.TypeFieldAssistDisposer;
23 import org.eclipse.pde.internal.ui.editor.plugin.JavaAttributeValue;
24 import org.eclipse.pde.internal.ui.util.PDEJavaHelperUI;
25 import org.eclipse.pde.internal.ui.util.TextUtil;
26 import org.eclipse.swt.custom.BusyIndicator;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.ui.forms.widgets.FormToolkit;
29
30 public class ClassAttributeRow extends ButtonAttributeRow {
31     
32     private TypeFieldAssistDisposer fTypeFieldAssistDisposer;
33     
34     public ClassAttributeRow(IContextPart part, ISchemaAttribute att) {
35         super(part, att);
36     }
37     protected boolean isReferenceModel() {
38         return !part.getPage().getModel().isEditable();
39     }
40     /*
41      * (non-Javadoc)
42      *
43      * @see org.eclipse.pde.internal.ui.neweditor.plugin.ReferenceAttributeRow#openReference()
44      */

45     protected void openReference() {
46         String JavaDoc name = TextUtil.trimNonAlphaChars(text.getText()).replace('$', '.');
47         name = PDEJavaHelperUI.createClass(
48                 name, getProject(),
49                 createJavaAttributeValue(name), true);
50         if (name != null)
51             text.setText(name);
52     }
53     
54     /*
55      * (non-Javadoc)
56      *
57      * @see org.eclipse.pde.internal.ui.editor.plugin.rows.ReferenceAttributeRow#createContents(org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit, int)
58      */

59     public void createContents(Composite parent, FormToolkit toolkit, int span) {
60         super.createContents(parent, toolkit, span);
61
62         if (part.isEditable()) {
63             fTypeFieldAssistDisposer =
64                 PDEJavaHelperUI.addTypeFieldAssistToText(text,
65                         getProject(),
66                         IJavaSearchConstants.CLASS_AND_INTERFACE);
67         }
68     }
69     
70     /*
71      * (non-Javadoc)
72      *
73      * @see org.eclipse.pde.internal.ui.neweditor.plugin.ReferenceAttributeRow#browse()
74      */

75     protected void browse() {
76         BusyIndicator.showWhile(text.getDisplay(), new Runnable JavaDoc() {
77             public void run() {
78                 doOpenSelectionDialog();
79             }
80         });
81     }
82     private JavaAttributeValue createJavaAttributeValue(String JavaDoc name) {
83         IProject project = part.getPage().getPDEEditor().getCommonProject();
84         IPluginModelBase model = (IPluginModelBase) part.getPage().getModel();
85         return new JavaAttributeValue(project, model, getAttribute(), name);
86     }
87     private void doOpenSelectionDialog() {
88         IResource resource = getPluginBase().getModel().getUnderlyingResource();
89         String JavaDoc type = PDEJavaHelperUI.selectType(
90                 resource,
91                 IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES,
92                 text.getText());
93         if (type != null)
94             text.setText(type);
95
96     }
97     private IPluginBase getPluginBase() {
98         IBaseModel model = part.getPage().getPDEEditor().getAggregateModel();
99         return ((IPluginModelBase) model).getPluginBase();
100     }
101     
102     /* (non-Javadoc)
103      * @see org.eclipse.pde.internal.ui.editor.plugin.rows.ExtensionAttributeRow#dispose()
104      */

105     public void dispose() {
106         super.dispose();
107         if (fTypeFieldAssistDisposer != null) {
108             fTypeFieldAssistDisposer.dispose();
109         }
110     }
111 }
112
Popular Tags