001: /*******************************************************************************
002: * Copyright (c) 2000, 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.schema;
011:
012: import org.eclipse.jface.viewers.StructuredSelection;
013: import org.eclipse.osgi.util.NLS;
014: import org.eclipse.pde.internal.core.ischema.ISchemaObject;
015: import org.eclipse.pde.internal.core.schema.SchemaElementReference;
016: import org.eclipse.pde.internal.ui.PDEUIMessages;
017: import org.eclipse.swt.SWT;
018: import org.eclipse.swt.events.SelectionAdapter;
019: import org.eclipse.swt.events.SelectionEvent;
020: import org.eclipse.swt.layout.GridData;
021: import org.eclipse.swt.widgets.Composite;
022: import org.eclipse.swt.widgets.Label;
023: import org.eclipse.ui.forms.IFormColors;
024: import org.eclipse.ui.forms.events.HyperlinkAdapter;
025: import org.eclipse.ui.forms.events.HyperlinkEvent;
026: import org.eclipse.ui.forms.widgets.FormToolkit;
027: import org.eclipse.ui.forms.widgets.Hyperlink;
028:
029: public class SchemaElementReferenceDetails extends
030: AbstractSchemaDetails {
031:
032: private SchemaElementReference fElement;
033: private Hyperlink fReferenceLink;
034: private Label fRefLabel;
035:
036: public SchemaElementReferenceDetails(ElementSection section) {
037: super (section, true, false);
038: }
039:
040: public void createDetails(Composite parent) {
041: FormToolkit toolkit = getManagedForm().getToolkit();
042:
043: createMinOccurComp(parent, toolkit);
044: createMaxOccurComp(parent, toolkit);
045:
046: fRefLabel = toolkit.createLabel(parent,
047: PDEUIMessages.SchemaElementReferenceDetails_reference);
048: fRefLabel.setForeground(toolkit.getColors().getColor(
049: IFormColors.TITLE));
050: fReferenceLink = toolkit.createHyperlink(parent, new String(),
051: SWT.NONE);
052: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
053: gd.horizontalSpan = 2;
054: fReferenceLink.setLayoutData(gd);
055:
056: setText(PDEUIMessages.SchemaElementReferenceDetails_title);
057: }
058:
059: public void updateFields(ISchemaObject object) {
060: if (!(object instanceof SchemaElementReference))
061: return;
062: fElement = (SchemaElementReference) object;
063:
064: setDecription(NLS
065: .bind(
066: PDEUIMessages.SchemaElementReferenceDetails_description,
067: fElement.getName()));
068: fReferenceLink.setText(fElement.getName());
069: updateMinOccur(fElement.getMinOccurs());
070: updateMaxOccur(fElement.getMaxOccurs());
071: boolean editable = isEditableElement();
072: fRefLabel.setEnabled(editable);
073: fReferenceLink.setEnabled(editable);
074: enableMinMax(editable);
075: }
076:
077: public void hookListeners() {
078: hookMinOccur(new SelectionAdapter() {
079: public void widgetSelected(SelectionEvent e) {
080: if (blockListeners())
081: return;
082: fElement.setMinOccurs(getMinOccur());
083: }
084: });
085: hookMaxOccur(new SelectionAdapter() {
086: public void widgetSelected(SelectionEvent e) {
087: if (blockListeners())
088: return;
089: fElement.setMaxOccurs(getMaxOccur());
090: }
091: });
092: fReferenceLink.addHyperlinkListener(new HyperlinkAdapter() {
093: public void linkActivated(HyperlinkEvent e) {
094: if (blockListeners())
095: return;
096: fireMasterSelection(new StructuredSelection(fElement
097: .getReferencedObject()));
098: }
099: });
100: }
101:
102: /* (non-Javadoc)
103: * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
104: */
105: public void commit(boolean onSave) {
106: super .commit(onSave);
107: // Only required for form entries
108: // NO-OP
109: }
110: }
|