1 8 9 package de.loskutov.bco.compare; 10 11 import org.eclipse.compare.CompareConfiguration; 12 import org.eclipse.compare.CompareEditorInput; 13 import org.eclipse.compare.CompareUI; 14 import org.eclipse.compare.CompareViewerPane; 15 import org.eclipse.compare.CompareViewerSwitchingPane; 16 import org.eclipse.compare.structuremergeviewer.Differencer; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.OperationCanceledException; 19 import org.eclipse.core.runtime.SubProgressMonitor; 20 import org.eclipse.jface.action.Action; 21 import org.eclipse.jface.action.IAction; 22 import org.eclipse.jface.action.Separator; 23 import org.eclipse.jface.action.ToolBarManager; 24 import org.eclipse.jface.util.IPropertyChangeListener; 25 import org.eclipse.jface.util.PropertyChangeEvent; 26 import org.eclipse.swt.widgets.Composite; 27 import org.eclipse.swt.widgets.Control; 28 import org.eclipse.ui.IReusableEditor; 29 30 import de.loskutov.bco.preferences.BCOConstants; 31 import de.loskutov.bco.ui.actions.DefaultToggleAction; 32 33 35 public class BytecodeCompare extends CompareEditorInput { 36 37 38 protected TypedElement left; 39 40 protected TypedElement right; 41 42 protected Action toggleAsmifierModeAction; 43 44 protected Action hideLineInfoAction; 45 46 protected Action hideLocalsAction; 47 protected Action hideStackMapAction; 48 protected Action expandStackMapAction; 49 50 protected IReusableEditor myEditor; 51 52 57 public BytecodeCompare(TypedElement left, TypedElement right) { 58 super(new CompareConfiguration()); 59 this.left = left; 60 this.right = right; 61 62 toggleAsmifierModeAction = new DefaultToggleAction(BCOConstants.SHOW_ASMIFIER_CODE, 63 new IPropertyChangeListener(){ 64 public void propertyChange(PropertyChangeEvent event) { 65 if(IAction.CHECKED.equals(event.getProperty())){ 66 boolean asmifier = Boolean.TRUE == event.getNewValue(); 67 toggleMode(BCOConstants.F_SHOW_ASMIFIER_CODE, asmifier, asmifier); 68 } 69 } 70 }); 71 72 hideLineInfoAction = new DefaultToggleAction(BCOConstants.SHOW_LINE_INFO, new IPropertyChangeListener(){ 73 public void propertyChange(PropertyChangeEvent event) { 74 if(IAction.CHECKED.equals(event.getProperty())){ 75 toggleMode( 76 BCOConstants.F_SHOW_LINE_INFO, 77 Boolean.TRUE == event.getNewValue(), 78 toggleAsmifierModeAction.isChecked()); 79 } 80 } 81 }); 82 83 hideLocalsAction = new DefaultToggleAction(BCOConstants.SHOW_VARIABLES, 84 new IPropertyChangeListener(){ 85 public void propertyChange(PropertyChangeEvent event) { 86 if(IAction.CHECKED.equals(event.getProperty())){ 87 toggleMode( 88 BCOConstants.F_SHOW_VARIABLES, 89 Boolean.TRUE == event.getNewValue(), 90 toggleAsmifierModeAction.isChecked()); 91 } 92 } 93 }); 94 95 hideStackMapAction = new DefaultToggleAction(BCOConstants.SHOW_STACKMAP, 96 new IPropertyChangeListener(){ 97 public void propertyChange(PropertyChangeEvent event) { 98 if(IAction.CHECKED.equals(event.getProperty())){ 99 toggleMode( 100 BCOConstants.F_SHOW_STACKMAP, 101 Boolean.TRUE == event.getNewValue(), 102 toggleAsmifierModeAction.isChecked()); 103 } 104 } 105 }); 106 107 expandStackMapAction = new DefaultToggleAction(BCOConstants.EXPAND_STACKMAP, 108 new IPropertyChangeListener(){ 109 public void propertyChange(PropertyChangeEvent event) { 110 if(IAction.CHECKED.equals(event.getProperty())){ 111 toggleMode( 112 BCOConstants.F_EXPAND_STACKMAP, 113 Boolean.TRUE == event.getNewValue(), 114 toggleAsmifierModeAction.isChecked()); 115 } 116 } 117 }); 118 } 119 120 121 protected Object prepareInput(IProgressMonitor monitor) 122 throws InterruptedException { 123 if (right == null || left == null) { 124 return null; 125 } 126 127 try { 128 initLabels(); 129 Differencer differencer = new Differencer(); 130 monitor.beginTask("Bytecode Outline: comparing...", 30); IProgressMonitor sub = new SubProgressMonitor(monitor, 10); 132 try { 133 sub.beginTask("Bytecode Outline: comparing...", 100); 135 return differencer.findDifferences( 136 false, sub, null, null, left, right); 137 } finally { 138 sub.done(); 139 } 140 } catch (OperationCanceledException e) { 141 throw new InterruptedException (e.getMessage()); 142 } finally { 143 monitor.done(); 144 } 145 } 146 147 150 private void initLabels() { 151 CompareConfiguration cc = getCompareConfiguration(); 152 153 cc.setLeftLabel(left.getName()); 154 cc.setLeftImage(left.getImage()); 155 156 cc.setRightLabel(right.getName()); 157 cc.setRightImage(right.getImage()); 158 159 setTitle("Bytecode compare: " + left.getElementName() + " - " + right.getElementName()); } 162 163 164 167 public Control createContents(Composite parent) { 168 Object obj = parent.getData(); 169 170 if(obj instanceof IReusableEditor){ 173 myEditor = (IReusableEditor)obj; 174 } 175 176 Control control = super.createContents(parent); 177 178 Object obj2 = control.getData("Nav"); if (obj2 instanceof CompareViewerSwitchingPane[]) { 185 CompareViewerSwitchingPane[] panels = (CompareViewerSwitchingPane[])obj2; 187 if(panels.length > 0){ 188 Composite comparePane = panels[panels.length-1]; 189 ToolBarManager toolBarManager2 = CompareViewerPane 190 .getToolBarManager(comparePane); 191 boolean separatorExist = false; 192 if (toolBarManager2.find(hideLineInfoAction.getId()) == null) { 193 if(!separatorExist) { 194 separatorExist = true; 195 toolBarManager2.insert(0, new Separator("bco")); } 197 toolBarManager2.insertBefore("bco", hideLineInfoAction); toolBarManager2.update(true); 199 } 200 if (toolBarManager2.find(hideLocalsAction.getId()) == null) { 201 if(!separatorExist) { 202 separatorExist = true; 203 toolBarManager2.insert(0, new Separator("bco")); } 205 toolBarManager2.insertBefore("bco", hideLocalsAction); toolBarManager2.update(true); 207 } 208 209 if (toolBarManager2.find(hideStackMapAction.getId()) == null) { 210 if(!separatorExist) { 211 separatorExist = true; 212 toolBarManager2.insert(0, new Separator("bco")); } 214 toolBarManager2.insertBefore("bco", hideStackMapAction); toolBarManager2.update(true); 216 } 217 if (toolBarManager2.find(expandStackMapAction.getId()) == null) { 218 if(!separatorExist) { 219 separatorExist = true; 220 toolBarManager2.insert(0, new Separator("bco")); } 222 toolBarManager2.insertBefore("bco", expandStackMapAction); toolBarManager2.update(true); 224 } 225 226 if (toolBarManager2.find(toggleAsmifierModeAction.getId()) == null) { 227 if(!separatorExist) { 228 toolBarManager2.insert(0, new Separator("bco")); separatorExist = true; 230 } 231 toolBarManager2.insertBefore("bco", toggleAsmifierModeAction); toolBarManager2.update(true); 233 } 234 try { 235 toolBarManager2.getControl().getParent().layout(true); 236 toolBarManager2.getControl().getParent().update(); 237 } catch (NullPointerException e) { 238 } 241 } 242 } 243 244 return control; 245 } 246 247 protected void toggleMode(int mode, boolean value, boolean isASMifierMode) { 248 String contentType = isASMifierMode 249 ? TypedElement.TYPE_ASM_IFIER 250 : TypedElement.TYPE_BYTECODE; 251 252 left.setMode(mode, value); 253 left.setMode(BCOConstants.F_SHOW_ASMIFIER_CODE, isASMifierMode); 254 left.setType(contentType); 255 256 right.setMode(mode, value); 257 right.setMode(BCOConstants.F_SHOW_ASMIFIER_CODE, isASMifierMode); 258 right.setType(contentType); 259 CompareUI.reuseCompareEditor(this, myEditor); 260 } 261 } | Popular Tags |