Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.debug.ui.liveedit; | 5 package org.chromium.debug.ui.liveedit; |
| 6 | 6 |
| 7 import java.util.ArrayList; | 7 import java.util.ArrayList; |
| 8 import java.util.List; | 8 import java.util.List; |
| 9 | 9 |
| 10 import org.chromium.debug.core.model.ConnectedTargetData; | 10 import org.chromium.debug.core.model.ConnectedTargetData; |
| 11 import org.chromium.debug.core.model.PushChangesPlan; | 11 import org.chromium.debug.core.model.PushChangesPlan; |
| 12 import org.chromium.debug.core.util.ScriptTargetMapping; | 12 import org.chromium.debug.core.util.ScriptTargetMapping; |
| 13 import org.chromium.debug.ui.TableUtils; | 13 import org.chromium.debug.ui.TableUtils; |
| 14 import org.chromium.debug.ui.TableUtils.ColumnBasedLabelProvider; | 14 import org.chromium.debug.ui.TableUtils.ColumnBasedLabelProvider; |
| 15 import org.chromium.debug.ui.TableUtils.ColumnData; | 15 import org.chromium.debug.ui.TableUtils.ColumnData; |
| 16 import org.chromium.debug.ui.TableUtils.TrivialAdapter; | 16 import org.chromium.debug.ui.TableUtils.TrivialAdapter; |
| 17 import org.chromium.debug.ui.TableUtils.ValueAdapter; | 17 import org.chromium.debug.ui.TableUtils.ValueAdapter; |
| 18 import org.chromium.debug.ui.actions.ChooseVmControl; | 18 import org.chromium.debug.ui.actions.ChooseVmControl; |
| 19 import org.chromium.sdk.TextStreamPosition; | |
| 20 import org.chromium.sdk.UpdatableScript; | |
| 21 import org.chromium.sdk.UpdatableScript.CompileErrorFailure; | |
| 19 import org.eclipse.jface.dialogs.Dialog; | 22 import org.eclipse.jface.dialogs.Dialog; |
| 20 import org.eclipse.jface.dialogs.IDialogConstants; | 23 import org.eclipse.jface.dialogs.IDialogConstants; |
| 21 import org.eclipse.jface.viewers.IStructuredContentProvider; | 24 import org.eclipse.jface.viewers.IStructuredContentProvider; |
| 22 import org.eclipse.jface.viewers.TableViewer; | 25 import org.eclipse.jface.viewers.TableViewer; |
| 23 import org.eclipse.jface.viewers.Viewer; | 26 import org.eclipse.jface.viewers.Viewer; |
| 24 import org.eclipse.osgi.util.NLS; | 27 import org.eclipse.osgi.util.NLS; |
| 25 import org.eclipse.swt.SWT; | 28 import org.eclipse.swt.SWT; |
| 29 import org.eclipse.swt.events.SelectionEvent; | |
| 30 import org.eclipse.swt.events.SelectionListener; | |
| 26 import org.eclipse.swt.graphics.Image; | 31 import org.eclipse.swt.graphics.Image; |
| 27 import org.eclipse.swt.layout.GridData; | 32 import org.eclipse.swt.layout.GridData; |
| 33 import org.eclipse.swt.layout.GridLayout; | |
| 34 import org.eclipse.swt.widgets.Button; | |
| 28 import org.eclipse.swt.widgets.Composite; | 35 import org.eclipse.swt.widgets.Composite; |
| 29 import org.eclipse.swt.widgets.Control; | 36 import org.eclipse.swt.widgets.Control; |
| 30 import org.eclipse.swt.widgets.Display; | 37 import org.eclipse.swt.widgets.Display; |
| 31 import org.eclipse.swt.widgets.Label; | 38 import org.eclipse.swt.widgets.Label; |
| 32 import org.eclipse.swt.widgets.Shell; | 39 import org.eclipse.swt.widgets.Shell; |
| 33 import org.eclipse.swt.widgets.Table; | 40 import org.eclipse.swt.widgets.Table; |
| 34 import org.eclipse.swt.widgets.TableColumn; | 41 import org.eclipse.swt.widgets.TableColumn; |
| 35 import org.eclipse.swt.widgets.Text; | 42 import org.eclipse.swt.widgets.Text; |
| 36 | 43 |
| 37 /** | 44 /** |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 54 <RES> RES acceptSingle(SingleInputVisitor<RES> visitor); | 61 <RES> RES acceptSingle(SingleInputVisitor<RES> visitor); |
| 55 ScriptTargetMapping getFilePair(); | 62 ScriptTargetMapping getFilePair(); |
| 56 } | 63 } |
| 57 | 64 |
| 58 public interface InputVisitor<RES> extends SingleInputVisitor<RES> { | 65 public interface InputVisitor<RES> extends SingleInputVisitor<RES> { |
| 59 RES visitMultipleResult(MultipleResult multipleResult); | 66 RES visitMultipleResult(MultipleResult multipleResult); |
| 60 } | 67 } |
| 61 | 68 |
| 62 public interface SingleInputVisitor<RES> { | 69 public interface SingleInputVisitor<RES> { |
| 63 RES visitSuccess(SuccessResult successResult); | 70 RES visitSuccess(SuccessResult successResult); |
| 64 RES visitErrorMessage(String text); | 71 RES visitErrorMessage(String message, UpdatableScript.Failure failure); |
| 65 } | 72 } |
| 66 | 73 |
| 67 public interface MultipleResult { | 74 public interface MultipleResult { |
| 68 List<? extends SingleInput> getList(); | 75 List<? extends SingleInput> getList(); |
| 69 } | 76 } |
| 70 | 77 |
| 71 public interface SuccessResult { | 78 public interface SuccessResult { |
| 72 boolean hasDroppedFrames(); | 79 boolean hasDroppedFrames(); |
| 73 /** @return may be null */ | 80 /** @return may be null */ |
| 74 OldScriptData getOldScriptData(); | 81 OldScriptData getOldScriptData(); |
| 75 } | 82 } |
| 76 | 83 |
| 77 public interface OldScriptData { | 84 public interface OldScriptData { |
| 78 LiveEditDiffViewer.Input getScriptStructure(); | 85 LiveEditDiffViewer.Input getScriptStructure(); |
| 79 String getOldScriptName(); | 86 String getOldScriptName(); |
| 80 } | 87 } |
| 81 | 88 |
| 89 /** | |
| 90 * Allows dialog to highlight error in source text (presumably, in text editor ). | |
| 91 */ | |
| 92 public interface ErrorPositionHighlighter { | |
| 93 void highlight(int offset, int length); | |
| 94 } | |
| 95 | |
| 82 public static SingleInput createTextInput(final String text, | 96 public static SingleInput createTextInput(final String text, |
| 83 final PushChangesPlan changesPlan) { | 97 final PushChangesPlan changesPlan) { |
| 98 return createTextInput(text, changesPlan, UpdatableScript.Failure.UNSPECIFIE D); | |
| 99 } | |
| 100 | |
| 101 public static SingleInput createTextInput(final String text, | |
| 102 final PushChangesPlan changesPlan, final UpdatableScript.Failure failure) { | |
| 84 return new LiveEditResultDialog.SingleInput() { | 103 return new LiveEditResultDialog.SingleInput() { |
| 85 public <RES> RES accept(LiveEditResultDialog.InputVisitor<RES> visitor) { | 104 public <RES> RES accept(LiveEditResultDialog.InputVisitor<RES> visitor) { |
| 86 return acceptSingle(visitor); | 105 return acceptSingle(visitor); |
| 87 } | 106 } |
| 88 public <RES> RES acceptSingle(LiveEditResultDialog.SingleInputVisitor<RES> visitor) { | 107 public <RES> RES acceptSingle(LiveEditResultDialog.SingleInputVisitor<RES> visitor) { |
| 89 return visitor.visitErrorMessage(text); | 108 return visitor.visitErrorMessage(text, failure); |
| 90 } | 109 } |
| 91 public ScriptTargetMapping getFilePair() { | 110 public ScriptTargetMapping getFilePair() { |
| 92 return changesPlan.getScriptTargetMapping(); | 111 return changesPlan.getScriptTargetMapping(); |
| 93 } | 112 } |
| 94 }; | 113 }; |
| 95 } | 114 } |
| 96 | 115 |
| 97 private final Input input; | 116 private final Input input; |
| 117 private final ErrorPositionHighlighter positionHighlighter; | |
| 98 | 118 |
| 99 public LiveEditResultDialog(Shell shell, Input input) { | 119 public LiveEditResultDialog(Shell shell, Input input, |
| 120 ErrorPositionHighlighter positionHighlighter) { | |
| 100 super(shell); | 121 super(shell); |
| 101 this.input = input; | 122 this.input = input; |
| 123 this.positionHighlighter = positionHighlighter; | |
| 102 } | 124 } |
| 103 | 125 |
| 104 @Override | 126 @Override |
| 105 protected boolean isResizable() { | 127 protected boolean isResizable() { |
| 106 return true; | 128 return true; |
| 107 } | 129 } |
| 108 | 130 |
| 109 @Override | 131 @Override |
| 110 protected void configureShell(Shell shell) { | 132 protected void configureShell(Shell shell) { |
| 111 super.configureShell(shell); | 133 super.configureShell(shell); |
| 112 shell.setText(Messages.LiveEditResultDialog_TITLE); | 134 shell.setText(Messages.LiveEditResultDialog_TITLE); |
| 113 } | 135 } |
| 114 | 136 |
| 115 @Override | 137 @Override |
| 116 protected void createButtonsForButtonBar(Composite parent) { | 138 protected void createButtonsForButtonBar(Composite parent) { |
| 117 // create only OK button | 139 // create only OK button |
| 118 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true ); | 140 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true ); |
| 119 } | 141 } |
| 120 | 142 |
| 121 @Override | 143 @Override |
| 122 protected Control createDialogArea(Composite parent) { | 144 protected Control createDialogArea(Composite parent) { |
| 123 final Composite composite = (Composite) super.createDialogArea(parent); | 145 final Composite composite = (Composite) super.createDialogArea(parent); |
| 124 | 146 |
| 125 input.accept(new InputVisitor<Void>() { | 147 input.accept(new InputVisitor<Void>() { |
| 126 public Void visitErrorMessage(String text) { | 148 public Void visitErrorMessage(final String text, UpdatableScript.Failure f ailure) { |
| 127 createErrorMessageControls(composite, text); | 149 return failure.accept(new UpdatableScript.Failure.Visitor<Void>() { |
| 128 return null; | 150 @Override public Void visitUnspecified() { |
| 151 createErrorMessageControls(composite, text); | |
| 152 return null; | |
| 153 } | |
| 154 @Override public Void visitCompileError(CompileErrorFailure compileErr or) { | |
| 155 createErrorWithPositionControls(composite, Messages.LiveEditResultDi alog_COMPLILE_ERROR, | |
| 156 compileError.getCompilerMessage(), | |
| 157 compileError.getStartPosition(), compileError.getEndPosition()); | |
| 158 return null; | |
| 159 } | |
| 160 }); | |
| 129 } | 161 } |
| 130 public Void visitSuccess(SuccessResult successResult) { | 162 public Void visitSuccess(SuccessResult successResult) { |
| 131 createSuccessResultControls(composite, successResult); | 163 createSuccessResultControls(composite, successResult); |
| 132 return null; | 164 return null; |
| 133 } | 165 } |
| 134 public Void visitMultipleResult(MultipleResult multipleResult) { | 166 public Void visitMultipleResult(MultipleResult multipleResult) { |
| 135 createMultipleResultsControl(composite, multipleResult); | 167 createMultipleResultsControl(composite, multipleResult); |
| 136 return null; | 168 return null; |
| 137 } | 169 } |
| 138 }); | 170 }); |
| 139 | 171 |
| 140 return composite; | 172 return composite; |
| 141 } | 173 } |
| 142 | 174 |
| 143 private void createErrorMessageControls(Composite parent, String text) { | 175 private void createErrorMessageControls(Composite parent, String text) { |
| 144 Text textControl = new Text(parent, SWT.WRAP); | 176 Text textControl = new Text(parent, SWT.WRAP); |
| 145 Display display = textControl.getDisplay(); | 177 Display display = parent.getDisplay(); |
| 146 textControl.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND )); | 178 textControl.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND )); |
| 147 textControl.setText(text); | 179 textControl.setText(text); |
| 148 } | 180 } |
| 149 | 181 |
| 182 private void createErrorWithPositionControls(Composite parent, String localMes sage, | |
| 183 String remoteMessage, | |
| 184 final TextStreamPosition startPosition, | |
| 185 TextStreamPosition endPosition) { | |
| 186 Display display = parent.getDisplay(); | |
| 187 | |
| 188 Composite messageComposite; | |
| 189 { | |
| 190 messageComposite = new Composite(parent, SWT.NONE); | |
| 191 GridLayout gridLayout = new GridLayout(2, false); | |
| 192 messageComposite.setLayout(gridLayout); | |
| 193 | |
| 194 Label localMessageLabel = new Label(messageComposite, SWT.NONE); | |
| 195 localMessageLabel.setText(localMessage); | |
| 196 Text textControl = new Text(messageComposite, SWT.READ_ONLY); | |
| 197 textControl.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROU ND)); | |
| 198 textControl.setText(remoteMessage); | |
| 199 textControl.setEditable(false); | |
| 200 } | |
| 201 | |
| 202 Composite positionComposite; | |
| 203 { | |
| 204 positionComposite = new Composite(parent, SWT.NONE); | |
| 205 GridLayout gridLayout = new GridLayout(2, false); | |
| 206 positionComposite.setLayout(gridLayout); | |
| 207 | |
| 208 Label startLabel = new Label(positionComposite, SWT.NONE); | |
| 209 startLabel.setText(NLS.bind(Messages.LiveEditResultDialog_LINE_COLUMN, | |
| 210 startPosition.getLine(), startPosition.getColumn())); | |
| 211 | |
| 212 Button setPositionButton = new Button(positionComposite, SWT.NONE); | |
| 213 setPositionButton.setText(Messages.LiveEditResultDialog_MOVE_CARET); | |
| 214 if (positionHighlighter == null) { | |
| 215 setPositionButton.setEnabled(false); | |
| 216 } else { | |
| 217 final int length; | |
| 218 if (endPosition == null) { | |
| 219 length = 0; | |
| 220 } else { | |
| 221 length = endPosition.getOffset() - startPosition.getOffset(); | |
| 222 } | |
| 223 setPositionButton.addSelectionListener(new SelectionListener() { | |
| 224 @Override public void widgetSelected(SelectionEvent e) { | |
| 225 positionHighlighter.highlight(startPosition.getOffset(), length); | |
| 226 } | |
| 227 @Override public void widgetDefaultSelected(SelectionEvent e) { | |
| 228 widgetSelected(null); | |
| 229 } | |
| 230 }); | |
| 231 } | |
| 232 } | |
| 233 } | |
| 234 | |
| 150 private void createSuccessResultControls(Composite parent, SuccessResult succe ssResult) { | 235 private void createSuccessResultControls(Composite parent, SuccessResult succe ssResult) { |
| 151 Label label1 = new Label(parent, SWT.NONE); | 236 Label label1 = new Label(parent, SWT.NONE); |
| 152 label1.setText(Messages.LiveEditResultDialog_SUCCESS); | 237 label1.setText(Messages.LiveEditResultDialog_SUCCESS); |
| 153 | 238 |
| 154 if (successResult.hasDroppedFrames()) { | 239 if (successResult.hasDroppedFrames()) { |
| 155 Label label2 = new Label(parent, SWT.NONE); | 240 Label label2 = new Label(parent, SWT.NONE); |
| 156 label2.setText(Messages.LiveEditResultDialog_FRAMES_DROPPED); | 241 label2.setText(Messages.LiveEditResultDialog_FRAMES_DROPPED); |
| 157 } | 242 } |
| 158 | 243 |
| 159 final OldScriptData withOldScript = successResult.getOldScriptData(); | 244 final OldScriptData withOldScript = successResult.getOldScriptData(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 @Override public String getColumnText(SingleInput element) { | 324 @Override public String getColumnText(SingleInput element) { |
| 240 return element.acceptSingle(textGetterVisitor); | 325 return element.acceptSingle(textGetterVisitor); |
| 241 } | 326 } |
| 242 @Override public TableColumn createColumn(Table table) { | 327 @Override public TableColumn createColumn(Table table) { |
| 243 TableColumn statusCol = new TableColumn(table, SWT.NONE); | 328 TableColumn statusCol = new TableColumn(table, SWT.NONE); |
| 244 statusCol.setText(Messages.LiveEditResultDialog_STATUS); | 329 statusCol.setText(Messages.LiveEditResultDialog_STATUS); |
| 245 statusCol.setWidth(200); | 330 statusCol.setWidth(200); |
| 246 return statusCol; | 331 return statusCol; |
| 247 } | 332 } |
| 248 private final SingleInputVisitor<String> textGetterVisitor = new SingleInput Visitor<String>() { | 333 private final SingleInputVisitor<String> textGetterVisitor = new SingleInput Visitor<String>() { |
| 249 public String visitErrorMessage(String text) { | 334 public String visitErrorMessage(final String text, UpdatableScript.Failure failure) { |
| 250 return NLS.bind(Messages.LiveEditResultDialog_FAILURE, text); | 335 String message = failure.accept(new UpdatableScript.Failure.Visitor<Stri ng>() { |
| 336 @Override public String visitUnspecified() { | |
| 337 return text; | |
| 338 } | |
| 339 @Override public String visitCompileError(CompileErrorFailure compileE rror) { | |
| 340 TextStreamPosition start = compileError.getStartPosition(); | |
| 341 return NLS.bind("{0} ({1}:{2})", new Object[] { //$NON-NLS-1$ | |
|
apavlov
2013/01/22 06:38:10
Is it by chance a list... argument?
Peter Rybin
2013/01/22 16:28:59
No
| |
| 342 compileError.getCompilerMessage(), start.getLine(), start.getCol umn() }); | |
| 343 } | |
| 344 }); | |
| 345 return NLS.bind(Messages.LiveEditResultDialog_FAILURE, message); | |
| 251 } | 346 } |
| 252 public String visitSuccess(SuccessResult successResult) { | 347 public String visitSuccess(SuccessResult successResult) { |
| 253 return Messages.LiveEditResultDialog_OK; | 348 return Messages.LiveEditResultDialog_OK; |
| 254 } | 349 } |
| 255 }; | 350 }; |
| 256 } | 351 } |
| 257 } | 352 } |
| OLD | NEW |