1 11 12 package org.eclipse.pde.internal.ui.editor.cheatsheet.comp; 13 14 import org.eclipse.jface.viewers.ISelection; 15 import org.eclipse.pde.core.IModelChangedEvent; 16 import org.eclipse.pde.core.IModelChangedListener; 17 import org.eclipse.pde.internal.core.AbstractModel; 18 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCS; 19 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSConstants; 20 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModel; 21 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject; 22 import org.eclipse.pde.internal.core.util.PDETextHelper; 23 import org.eclipse.pde.internal.ui.IHelpContextIds; 24 import org.eclipse.pde.internal.ui.IPDEUIConstants; 25 import org.eclipse.pde.internal.ui.PDEPlugin; 26 import org.eclipse.pde.internal.ui.PDEPluginImages; 27 import org.eclipse.pde.internal.ui.PDEUIMessages; 28 import org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock; 29 import org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractPage; 30 import org.eclipse.ui.PlatformUI; 31 import org.eclipse.ui.forms.IManagedForm; 32 import org.eclipse.ui.forms.editor.FormEditor; 33 import org.eclipse.ui.forms.widgets.ScrolledForm; 34 35 39 public class CompCSPage extends CSAbstractPage implements IModelChangedListener { 40 41 public static final String PAGE_ID = "compCSPage"; 43 private CompCSBlock fBlock; 44 45 48 public CompCSPage(FormEditor editor) { 49 super(editor, PAGE_ID, PDEUIMessages.SimpleCSPage_0); 50 51 fBlock = new CompCSBlock(this); 52 } 53 54 57 protected String getHelpResource() { 58 return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/composite_cs_editor/editor.htm"; } 60 61 63 66 protected void createFormContent(IManagedForm managedForm) { 67 ScrolledForm form = managedForm.getForm(); 71 ICompCSModel model = (ICompCSModel)getModel(); 73 if ((model == null) || 75 (model.isLoaded() == false)) { 76 Exception e = null; 77 if (model instanceof AbstractModel) { 78 e = ((AbstractModel)model).getException(); 79 } 80 createFormErrorContent(managedForm, 82 PDEUIMessages.SimpleCSPage_msgCheatSheetLoadFailure, 83 PDEUIMessages.SimpleCSPage_msgCheatSheetParsingFailure, 84 e); 85 return; 86 } 87 createUIFormTitleRegisterCSLink(managedForm, model); 89 super.createFormContent(managedForm); 91 form.setImage(PDEPlugin.getDefault().getLabelProvider().get( 93 PDEPluginImages.DESC_CHEATSHEET_OBJ)); 94 String title = PDETextHelper.translateReadText(model.getCompCS() 96 .getFieldName()); 97 if (title.length() > 0) { 98 form.setText(title); 99 } else { 100 form.setText(PDEUIMessages.SimpleCSPage_0); 101 } 102 fBlock.createContent(managedForm); 105 fBlock.getMastersSection().fireSelection(); 108 model.addModelChangedListener(this); 110 PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), 112 IHelpContextIds.COMPOSITE_CS_EDITOR); 113 } 114 115 118 public void dispose() { 119 120 ICompCSModel compCSModel = (ICompCSModel)getModel(); 121 if (compCSModel != null) { 122 compCSModel.removeModelChangedListener(this); 123 } 124 super.dispose(); 125 } 126 127 130 public void modelChanged(IModelChangedEvent event) { 131 132 if (event.getChangeType() == IModelChangedEvent.CHANGE) { 133 Object [] objects = event.getChangedObjects(); 134 ICompCSObject object = (ICompCSObject) objects[0]; 135 if (object == null) { 136 } else if (object.getType() == ICompCSConstants.TYPE_COMPOSITE_CHEATSHEET) { 138 String changeProperty = event.getChangedProperty(); 139 if ((changeProperty != null) 140 && changeProperty 141 .equals(ICompCSConstants.ATTRIBUTE_NAME)) { 142 getManagedForm().getForm().setText( 145 PDETextHelper.translateReadText((String ) event 146 .getNewValue())); 147 } 148 } 149 } else if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) { 150 handleModelEventWorldChanged(event); 151 } 152 fBlock.modelChanged(event); 154 } 155 156 159 public ISelection getSelection() { 160 return fBlock.getSelection(); 161 } 162 163 166 private void handleModelEventWorldChanged(IModelChangedEvent event) { 167 168 Object [] objects = event.getChangedObjects(); 169 ICompCSObject object = (ICompCSObject) objects[0]; 170 if (object == null) { 171 return; 173 } else if (object.getType() == ICompCSConstants.TYPE_COMPOSITE_CHEATSHEET) { 174 String newValue = ((ICompCS)object).getFieldName(); 175 getManagedForm().getForm().setText( 177 PDETextHelper.translateReadText(newValue)); 178 } 179 } 180 181 184 public PDEMasterDetailsBlock getBlock() { 185 return fBlock; 186 } 187 188 } 189 | Popular Tags |