Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.launcher; | 5 package org.chromium.debug.ui.launcher; |
| 6 | 6 |
| 7 import java.util.Collection; | 7 import java.util.Collection; |
| 8 import java.util.List; | 8 import java.util.List; |
| 9 import java.util.Map; | 9 import java.util.Map; |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 } | 52 } |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 tabElements = createElements(parent, modifyListener); | 55 tabElements = createElements(parent, modifyListener); |
| 56 } | 56 } |
| 57 | 57 |
| 58 protected abstract ELEMENTS createElements(Composite parent, Runnable modifyLi stener); | 58 protected abstract ELEMENTS createElements(Composite parent, Runnable modifyLi stener); |
| 59 | 59 |
| 60 @Override | 60 @Override |
| 61 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { | 61 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { |
| 62 for (TabField<?, ?, ?, PARAMS> field : getTabFields()) { | 62 getTabFields().setDefaults(configuration, getParams()); |
| 63 field.setDefault(configuration, getParams()); | |
| 64 } | |
| 65 } | 63 } |
| 66 | 64 |
| 67 @Override | 65 @Override |
| 68 public void initializeFrom(ILaunchConfiguration configuration) { | 66 public void initializeFrom(ILaunchConfiguration configuration) { |
| 69 for (TabField<?, ?, ? super ELEMENTS, ?> field : getTabFields()) { | 67 getTabFields().initializeFrom(tabElements, configuration); |
| 70 field.initializeFrom(tabElements, configuration); | |
| 71 } | |
| 72 } | 68 } |
| 73 | 69 |
| 74 @Override | 70 @Override |
| 75 public void performApply(ILaunchConfigurationWorkingCopy configuration) { | 71 public void performApply(ILaunchConfigurationWorkingCopy configuration) { |
| 76 for (TabField<?, ?, ? super ELEMENTS, ?> field : getTabFields()) { | 72 getTabFields().saveToConfig(tabElements, configuration); |
| 77 field.saveToConfig(tabElements, configuration); | |
| 78 } | |
| 79 } | 73 } |
| 80 | 74 |
| 81 @Override | 75 @Override |
| 82 public boolean isValid(ILaunchConfiguration config) { | 76 public boolean isValid(ILaunchConfiguration config) { |
| 83 MessageData messageData; | 77 MessageData messageData; |
| 84 try { | 78 try { |
| 85 messageData = isValidImpl(config); | 79 messageData = isValidImpl(config); |
| 86 } catch (CoreException e) { | 80 } catch (CoreException e) { |
| 87 ChromiumDebugPlugin.log(new Exception("Unexpected storage problem", e)); / /$NON-NLS-1$ | 81 ChromiumDebugPlugin.log(new Exception("Unexpected storage problem", e)); / /$NON-NLS-1$ |
| 88 messageData = new MessageData(true, "Internal error " + e.getMessage()); / /$NON-NLS-1$ | 82 messageData = new MessageData(true, "Internal error " + e.getMessage()); / /$NON-NLS-1$ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 this.message = message; | 114 this.message = message; |
| 121 } | 115 } |
| 122 public boolean isValid() { | 116 public boolean isValid() { |
| 123 return valid; | 117 return valid; |
| 124 } | 118 } |
| 125 public String getMessage() { | 119 public String getMessage() { |
| 126 return message; | 120 return message; |
| 127 } | 121 } |
| 128 } | 122 } |
| 129 | 123 |
| 130 protected abstract List<? extends TabField<?, ?, ? super ELEMENTS, PARAMS>> ge tTabFields(); | 124 protected abstract TabFieldList<? super ELEMENTS, ? super PARAMS> getTabFields (); |
| 131 | 125 |
| 132 /** | 126 /** |
| 133 * A dialog window tab field description. It is a static description -- it has no reference to | 127 * A dialog window tab field description. It is a static description -- it has no reference to |
| 134 * a particular element instance. | 128 * a particular element instance. |
| 135 * @param <P> physical type of field as stored in config; used internally | 129 * @param <P> physical type of field as stored in config; used internally |
| 136 * @param <L> logical type of field used in runtime operations | 130 * @param <L> logical type of field used in runtime operations |
| 137 * @param <E> interface to dialog elements | 131 * @param <E> interface to dialog elements |
| 138 * @param <C> context that holds immutable input parameter of the tab dialog | 132 * @param <C> context that holds immutable input parameter of the tab dialog |
| 139 */ | 133 */ |
| 140 static class TabField<P, L, E, C> { | 134 static class TabField<P, L, E, C> { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 } | 379 } |
| 386 }; | 380 }; |
| 387 | 381 |
| 388 for (Button button : buttons) { | 382 for (Button button : buttons) { |
| 389 if ((button.getStyle() & SWT.NO_RADIO_GROUP) == 0) { | 383 if ((button.getStyle() & SWT.NO_RADIO_GROUP) == 0) { |
| 390 throw new IllegalArgumentException(); | 384 throw new IllegalArgumentException(); |
| 391 } | 385 } |
| 392 button.addSelectionListener(selectionListener); | 386 button.addSelectionListener(selectionListener); |
| 393 } | 387 } |
| 394 } | 388 } |
| 389 | |
| 390 /** | |
| 391 * Incapsulate tab field list together with a way of accessing them. This incl udes adapting | |
|
apavlov
2012/08/06 08:19:06
Encapsulate
Peter Rybin
2012/08/06 22:40:35
Done.
| |
| 392 * type of dialog elements structure (<E>) to a type accepted by fields. | |
| 393 * @param <E> type of elements structure that provides getters to dialog eleme nts | |
| 394 * @param <P> type of dialog window parameters | |
| 395 */ | |
| 396 interface TabFieldList<E, P> { | |
| 397 void setDefaults(ILaunchConfigurationWorkingCopy configuration, P params); | |
| 398 void initializeFrom(E elements, ILaunchConfiguration configuration); | |
| 399 void saveToConfig(E elements, ILaunchConfigurationWorkingCopy configuration) ; | |
| 400 } | |
| 401 | |
| 402 /** | |
| 403 * Create a plain implementation of {@link TabFieldList} over a list of tab fi elds. | |
| 404 */ | |
| 405 static <E, P> TabFieldList<E, P> createFieldListImpl( | |
| 406 final List<? extends TabField<?, ?, ? super E, P>> tabFields) { | |
| 407 return new TabFieldList<E, P>() { | |
| 408 public void setDefaults(ILaunchConfigurationWorkingCopy configuration, P p arams) { | |
| 409 for (TabField<?, ?, ?, P> field : tabFields) { | |
| 410 field.setDefault(configuration, params); | |
| 411 } | |
| 412 } | |
| 413 | |
| 414 @Override | |
| 415 public void initializeFrom(E elements, ILaunchConfiguration configuration) { | |
| 416 for (TabField<?, ?, ? super E, ?> field : tabFields) { | |
| 417 field.initializeFrom(elements, configuration); | |
| 418 } | |
| 419 } | |
| 420 | |
| 421 @Override | |
| 422 public void saveToConfig(E elements, ILaunchConfigurationWorkingCopy confi guration) { | |
| 423 for (TabField<?, ?, ? super E, ?> field : tabFields) { | |
| 424 field.saveToConfig(elements, configuration); | |
| 425 } | |
| 426 } | |
| 427 }; | |
| 428 } | |
| 429 | |
| 430 interface Adapter<F, T> { | |
| 431 T get(F from); | |
| 432 } | |
| 433 | |
| 434 /** | |
| 435 * Creates {@link TabFieldList} implementation that adapts dialog elements typ e using the adapter. | |
| 436 * @param list of tab fields that accepts alternative type of dialog elements structure | |
| 437 * @param elementsAdapter converts one dialog elements structure type to anoth er | |
|
apavlov
2012/08/06 08:19:06
what are "one" and "another" in this context? This
Peter Rybin
2012/08/06 22:40:35
Done.
| |
| 438 */ | |
| 439 static <E, INNER, P> TabFieldList<E, P> createFieldListAdapting( | |
| 440 final TabFieldList<? super INNER, ? super P> list, final Adapter<E, INNER> elementsAdapter) { | |
| 441 return new TabFieldList<E, P>() { | |
| 442 @Override public void setDefaults(ILaunchConfigurationWorkingCopy configur ation, P params) { | |
| 443 list.setDefaults(configuration, params); | |
| 444 } | |
| 445 @Override public void initializeFrom(E elements, ILaunchConfiguration conf iguration) { | |
| 446 list.initializeFrom(elementsAdapter.get(elements), configuration); | |
| 447 } | |
| 448 @Override | |
| 449 public void saveToConfig(E elements, ILaunchConfigurationWorkingCopy confi guration) { | |
| 450 list.saveToConfig(elementsAdapter.get(elements), configuration); | |
| 451 } | |
| 452 }; | |
| 453 } | |
| 454 | |
| 455 static <E, P> TabFieldList<E, P> createCompositeFieldList( | |
| 456 final List<? extends TabFieldList<? super E, ? super P>> listList) { | |
| 457 return new TabFieldList<E, P>() { | |
| 458 @Override | |
| 459 public void setDefaults(ILaunchConfigurationWorkingCopy configuration, | |
| 460 P params) { | |
| 461 for (TabFieldList<?, ? super P> list : listList) { | |
| 462 list.setDefaults(configuration, params); | |
| 463 } | |
| 464 } | |
| 465 | |
| 466 @Override | |
| 467 public void initializeFrom(E elements, ILaunchConfiguration configuration) { | |
| 468 for (TabFieldList<? super E, ?> list : listList) { | |
| 469 list.initializeFrom(elements, configuration); | |
| 470 } | |
| 471 } | |
| 472 | |
| 473 @Override | |
| 474 public void saveToConfig(E elements, | |
| 475 ILaunchConfigurationWorkingCopy configuration) { | |
| 476 for (TabFieldList<? super E, ?> list : listList) { | |
| 477 list.saveToConfig(elements, configuration); | |
| 478 } | |
| 479 } | |
| 480 }; | |
| 481 } | |
| 395 } | 482 } |
| OLD | NEW |