1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ide.eclipse.adt.internal.editors.uimodel; 18 19 import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor; 20 import com.android.ide.eclipse.adt.internal.editors.descriptors.SeparatorAttributeDescriptor; 21 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.layout.GridData; 24 import org.eclipse.swt.layout.GridLayout; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Label; 27 import org.eclipse.ui.forms.IManagedForm; 28 import org.eclipse.ui.forms.widgets.FormToolkit; 29 import org.eclipse.ui.forms.widgets.TableWrapData; 30 import org.eclipse.ui.forms.widgets.TableWrapLayout; 31 import org.w3c.dom.Node; 32 33 /** 34 * {@link UiSeparatorAttributeNode} does not represent any real attribute. 35 * <p/> 36 * It is used to separate groups of attributes visually. 37 */ 38 public class UiSeparatorAttributeNode extends UiAttributeNode { 39 40 /** Creates a new {@link UiAttributeNode} linked to a specific {@link AttributeDescriptor} */ 41 public UiSeparatorAttributeNode(SeparatorAttributeDescriptor attrDesc, 42 UiElementNode uiParent) { 43 super(attrDesc, uiParent); 44 } 45 46 /** Returns the current value of the node. */ 47 @Override 48 public String getCurrentValue() { 49 // There is no value here. 50 return null; 51 } 52 53 /** 54 * Sets whether the attribute is dirty and also notifies the editor some part's dirty 55 * flag as changed. 56 * <p/> 57 * Subclasses should set the to true as a result of user interaction with the widgets in 58 * the section and then should set to false when the commit() method completed. 59 */ 60 @Override 61 public void setDirty(boolean isDirty) { 62 // This is never dirty. 63 } 64 65 /** 66 * Called once by the parent user interface to creates the necessary 67 * user interface to edit this attribute. 68 * <p/> 69 * This method can be called more than once in the life cycle of an UI node, 70 * typically when the UI is part of a master-detail tree, as pages are swapped. 71 * 72 * @param parent The composite where to create the user interface. 73 * @param managedForm The managed form owning this part. 74 */ 75 @Override 76 public void createUiControl(Composite parent, IManagedForm managedForm) { 77 FormToolkit toolkit = managedForm.getToolkit(); 78 Composite row = toolkit.createComposite(parent); 79 80 TableWrapData twd = new TableWrapData(TableWrapData.FILL_GRAB); 81 if (parent.getLayout() instanceof TableWrapLayout) { 82 twd.colspan = ((TableWrapLayout) parent.getLayout()).numColumns; 83 } 84 row.setLayoutData(twd); 85 row.setLayout(new GridLayout(3, false /* equal width */)); 86 87 Label sep = toolkit.createSeparator(row, SWT.HORIZONTAL); 88 GridData gd = new GridData(SWT.LEFT, SWT.CENTER, false, false); 89 gd.widthHint = 16; 90 sep.setLayoutData(gd); 91 92 Label label = toolkit.createLabel(row, getDescriptor().getXmlLocalName()); 93 label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); 94 95 sep = toolkit.createSeparator(row, SWT.HORIZONTAL); 96 sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 97 } 98 99 /** 100 * No completion values for this UI attribute. 101 * 102 * {@inheritDoc} 103 */ 104 @Override 105 public String[] getPossibleValues(String prefix) { 106 return null; 107 } 108 109 /** 110 * Called when the XML is being loaded or has changed to 111 * update the value held by this user interface attribute node. 112 * <p/> 113 * The XML Node <em>may</em> be null, which denotes that the attribute is not 114 * specified in the XML model. In general, this means the "default" value of the 115 * attribute should be used. 116 * <p/> 117 * The caller doesn't really know if attributes have changed, 118 * so it will call this to refresh the attribute anyway. It's up to the 119 * UI implementation to minimize refreshes. 120 * 121 * @param xml_attribute_node 122 */ 123 @Override 124 public void updateValue(Node xml_attribute_node) { 125 // No value to update. 126 } 127 128 /** 129 * Called by the user interface when the editor is saved or its state changed 130 * and the modified attributes must be committed (i.e. written) to the XML model. 131 * <p/> 132 * Important behaviors: 133 * <ul> 134 * <li>The caller *must* have called IStructuredModel.aboutToChangeModel before. 135 * The implemented methods must assume it is safe to modify the XML model. 136 * <li>On success, the implementation *must* call setDirty(false). 137 * <li>On failure, the implementation can fail with an exception, which 138 * is trapped and logged by the caller, or do nothing, whichever is more 139 * appropriate. 140 * </ul> 141 */ 142 @Override 143 public void commit() { 144 // No value to commit. 145 } 146 } 147