KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2003, 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 import org.eclipse.core.runtime.CoreException;
13 import org.eclipse.jface.text.ITextSelection;
14 import org.eclipse.jface.text.TextSelection;
15 import org.eclipse.pde.core.plugin.IPluginAttribute;
16 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
17 import org.eclipse.pde.internal.ui.PDEPlugin;
18 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
19 import org.eclipse.pde.internal.ui.editor.IContextPart;
20 import org.eclipse.pde.internal.ui.editor.text.PDETextHover;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.events.FocusAdapter;
23 import org.eclipse.swt.events.FocusEvent;
24 import org.eclipse.swt.events.ModifyEvent;
25 import org.eclipse.swt.events.ModifyListener;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Text;
29 import org.eclipse.ui.forms.widgets.FormToolkit;
30
31 public class TextAttributeRow extends ExtensionAttributeRow {
32     protected Text text;
33     /**
34      * @param att
35      */

36     public TextAttributeRow(IContextPart part, ISchemaAttribute att) {
37         super(part, att);
38     }
39     
40     public TextAttributeRow(IContextPart part, IPluginAttribute att) {
41         super(part, att);
42     }
43     public void createContents(Composite parent, FormToolkit toolkit, int span) {
44         super.createContents(parent, toolkit, span);
45         createLabel(parent, toolkit);
46         text = toolkit.createText(parent, "", SWT.SINGLE); //$NON-NLS-1$
47
text.setLayoutData(createGridData(span));
48         text.addModifyListener(new ModifyListener() {
49             public void modifyText(ModifyEvent e) {
50                 if (!blockNotification) markDirty();
51                 PDETextHover.updateHover(fIC, getHoverContent(text));
52             }
53         });
54         text.setEditable(part.isEditable());
55         PDETextHover.addHoverListenerToControl(fIC, text, this);
56         // Create a focus listener to update selectable actions
57
createUITextFocusListener();
58     }
59     
60     /**
61      *
62      */

63     private void createUITextFocusListener() {
64         // Required to enable Ctrl-V paste operations
65
text.addFocusListener(new FocusAdapter() {
66             public void focusGained(FocusEvent e) {
67                 ITextSelection selection = new TextSelection(1,1);
68                 part.getPage().getPDEEditor().getContributor().updateSelectableActions(selection);
69             }
70         });
71     }
72
73     protected GridData createGridData(int span) {
74         GridData gd = new GridData(span == 2
75                 ? GridData.FILL_HORIZONTAL
76                 : GridData.HORIZONTAL_ALIGN_FILL);
77         gd.widthHint = 20;
78         gd.horizontalSpan = span - 1;
79         gd.horizontalIndent = FormLayoutFactory.CONTROL_HORIZONTAL_INDENT;
80         return gd;
81     }
82     /*
83      * (non-Javadoc)
84      *
85      * @see org.eclipse.pde.internal.ui.neweditor.plugin.ExtensionElementEditor#update(org.eclipse.pde.internal.ui.neweditor.plugin.DummyExtensionElement)
86      */

87     protected void update() {
88         blockNotification = true;
89         text.setText(getValue());
90         blockNotification = false;
91     }
92     public void commit() {
93         if (dirty && input!=null) {
94             String JavaDoc value = text.getText();
95             try {
96                 input.setAttribute(getName(), value);
97                 dirty = false;
98             } catch (CoreException e) {
99                 PDEPlugin.logException(e);
100             }
101         }
102     }
103     public void setFocus() {
104         text.setFocus();
105     }
106 }
107
Popular Tags