1 11 12 package org.eclipse.pde.internal.ui.editor.cheatsheet.simple; 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.simple.ISimpleCS; 19 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSConstants; 20 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModel; 21 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject; 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 SimpleCSPage extends CSAbstractPage implements IModelChangedListener { 40 41 public static final String PAGE_ID = "simpleCSPage"; 43 private SimpleCSBlock fBlock; 44 45 48 public SimpleCSPage(FormEditor editor) { 49 super(editor, PAGE_ID, PDEUIMessages.SimpleCSPage_0); 50 fBlock = new SimpleCSBlock(this); 51 } 52 53 56 protected String getHelpResource() { 57 return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/simple_cs_editor/editor.htm"; } 59 60 63 protected void createFormContent(IManagedForm managedForm) { 64 ScrolledForm form = managedForm.getForm(); 68 ISimpleCSModel model = (ISimpleCSModel)getModel(); 70 if ((model == null) || 72 (model.isLoaded() == false)) { 73 Exception e = null; 74 if (model instanceof AbstractModel) { 75 e = ((AbstractModel)model).getException(); 76 } 77 createFormErrorContent(managedForm, 79 PDEUIMessages.SimpleCSPage_msgCheatSheetLoadFailure, 80 PDEUIMessages.SimpleCSPage_msgCheatSheetParsingFailure, 81 e); 82 return; 83 } 84 createUIFormTitleRegisterCSLink(managedForm, model); 86 super.createFormContent(managedForm); 88 form.setImage(PDEPlugin.getDefault().getLabelProvider().get( 90 PDEPluginImages.DESC_CHEATSHEET_OBJ)); 91 String title = PDETextHelper.translateReadText(model.getSimpleCS() 93 .getTitle()); 94 if (title.length() > 0) { 95 form.setText(title); 96 } else { 97 form.setText(PDEUIMessages.SimpleCSPage_0); 98 } 99 fBlock.createContent(managedForm); 102 fBlock.getMastersSection().fireSelection(); 105 model.addModelChangedListener(this); 107 PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), 109 IHelpContextIds.SIMPLE_CS_EDITOR); 110 } 111 112 115 public void dispose() { 116 117 ISimpleCSModel simpleCSModel = (ISimpleCSModel)getModel(); 118 if (simpleCSModel != null) { 119 simpleCSModel.removeModelChangedListener(this); 120 } 121 super.dispose(); 122 } 123 124 127 public void modelChanged(IModelChangedEvent event) { 128 129 if (event.getChangeType() == IModelChangedEvent.CHANGE) { 130 Object [] objects = event.getChangedObjects(); 131 ISimpleCSObject object = (ISimpleCSObject) objects[0]; 132 if (object == null) { 133 } else if (object.getType() == ISimpleCSConstants.TYPE_CHEAT_SHEET) { 135 String changeProperty = event.getChangedProperty(); 136 if ((changeProperty != null) 137 && changeProperty 138 .equals(ISimpleCSConstants.ATTRIBUTE_TITLE)) { 139 getManagedForm().getForm().setText( 142 PDETextHelper.translateReadText((String ) event 143 .getNewValue())); 144 } 145 } 146 } else if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) { 147 handleModelEventWorldChanged(event); 148 } 149 fBlock.modelChanged(event); 151 } 152 153 156 private void handleModelEventWorldChanged(IModelChangedEvent event) { 157 158 Object [] objects = event.getChangedObjects(); 159 ISimpleCSObject object = (ISimpleCSObject) objects[0]; 160 if (object == null) { 161 return; 163 } else if (object.getType() == ISimpleCSConstants.TYPE_CHEAT_SHEET) { 164 String newValue = ((ISimpleCS)object).getTitle(); 165 getManagedForm().getForm().setText( 167 PDETextHelper.translateReadText(newValue)); 168 } 169 } 170 171 174 public ISelection getSelection() { 175 return fBlock.getSelection(); 176 } 177 178 181 public PDEMasterDetailsBlock getBlock() { 182 return fBlock; 183 } 184 185 } 186 | Popular Tags |