001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.toc.details;
011:
012: import org.eclipse.jface.viewers.ISelection;
013: import org.eclipse.pde.internal.core.text.toc.TocAnchor;
014: import org.eclipse.pde.internal.core.text.toc.TocObject;
015: import org.eclipse.pde.internal.ui.PDEUIMessages;
016: import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
017: import org.eclipse.pde.internal.ui.editor.toc.TocInputContext;
018: import org.eclipse.pde.internal.ui.editor.toc.TocTreeSection;
019: import org.eclipse.pde.internal.ui.parts.FormEntry;
020: import org.eclipse.swt.SWT;
021: import org.eclipse.swt.layout.GridData;
022: import org.eclipse.swt.widgets.Composite;
023: import org.eclipse.ui.forms.IFormPart;
024:
025: public class TocAnchorDetails extends TocAbstractDetails {
026:
027: private TocAnchor fDataTOCAnchor;
028:
029: private FormEntry fAnchorIdEntry;
030:
031: /**
032: * @param masterSection
033: */
034: public TocAnchorDetails(TocTreeSection masterSection) {
035: super (masterSection, TocInputContext.CONTEXT_ID);
036: fDataTOCAnchor = null;
037:
038: fAnchorIdEntry = null;
039: }
040:
041: /**
042: * @param object
043: */
044: public void setData(TocAnchor object) {
045: // Set data
046: fDataTOCAnchor = object;
047: }
048:
049: protected TocObject getDataObject() {
050: return fDataTOCAnchor;
051: }
052:
053: protected FormEntry getPathEntryField() {
054: return null;
055: }
056:
057: /* (non-Javadoc)
058: * @see org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails#createDetails(org.eclipse.swt.widgets.Composite)
059: */
060: public void createFields(Composite parent) {
061: createAnchorIdWidget(parent);
062: }
063:
064: /**
065: * @param parent
066: */
067: private void createAnchorIdWidget(Composite parent) {
068: fAnchorIdEntry = new FormEntry(parent, getManagedForm()
069: .getToolkit(), PDEUIMessages.TocAnchorDetails_id,
070: SWT.NONE);
071: // Ensure that the text field has proper width
072: fAnchorIdEntry.getText().setLayoutData(
073: new GridData(SWT.FILL, SWT.CENTER, true, false));
074: }
075:
076: protected String getDetailsTitle() {
077: return PDEUIMessages.TocAnchorDetails_title;
078: }
079:
080: protected String getDetailsDescription() {
081: return PDEUIMessages.TocAnchorDetails_sectionDescription;
082: }
083:
084: /* (non-Javadoc)
085: * @see org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails#hookListeners()
086: */
087: public void hookListeners() {
088: createAnchorIdEntryListeners();
089: }
090:
091: /**
092: *
093: */
094: private void createAnchorIdEntryListeners() {
095: fAnchorIdEntry.setFormEntryListener(new FormEntryAdapter(this ) {
096: public void textValueChanged(FormEntry entry) {
097: // Ensure data object is defined
098: if (fDataTOCAnchor != null) {
099: {
100: fDataTOCAnchor.setFieldAnchorId(fAnchorIdEntry
101: .getValue());
102: }
103: }
104: }
105: });
106: }
107:
108: /* (non-Javadoc)
109: * @see org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails#updateFields()
110: */
111: public void updateFields() {
112: // Ensure data object is defined
113: if (fDataTOCAnchor != null) { // Update name entry
114: updateAnchorIdEntry(isEditableElement());
115: }
116: }
117:
118: /**
119: * @param editable
120: */
121: private void updateAnchorIdEntry(boolean editable) {
122: fAnchorIdEntry
123: .setValue(fDataTOCAnchor.getFieldAnchorId(), true);
124: fAnchorIdEntry.setEditable(editable);
125: }
126:
127: /* (non-Javadoc)
128: * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
129: */
130: public void commit(boolean onSave) {
131: super .commit(onSave);
132: // Only required for form entries
133: fAnchorIdEntry.commit();
134: }
135:
136: /* (non-Javadoc)
137: * @see org.eclipse.ui.forms.IPartSelectionListener#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
138: */
139: public void selectionChanged(IFormPart part, ISelection selection) {
140: // Get the first selected object
141: Object object = getFirstSelectedObject(selection);
142: // Ensure we have the right type
143: if (object != null && object instanceof TocAnchor) {
144: // Set data
145: setData((TocAnchor) object);
146: // Update the UI given the new data
147: updateFields();
148: }
149: }
150: }
|