Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(728)

Side by Side Diff: plugins/org.chromium.debug.ui/src/org/chromium/debug/ui/launcher/TabBase.java

Issue 10829181: Redesign TabBase to get rid of mandatory inheritance of dialog element interfaces (Closed) Base URL: https://chromedevtools.googlecode.com/svn/trunk
Patch Set: fcr Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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 * Encapsulate tab field list together with a way of accessing them. This incl udes adapting
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 * to inner type of dialog elements that provided list of {@link TabFieldList} accept.
437 * @param list of tab fields that accepts alternative type of dialog elements structure
438 * @param elementsAdapter converts external dialog elements structure type to the inner type
439 */
440 static <E, INNER, P> TabFieldList<E, P> createFieldListAdapting(
441 final TabFieldList<? super INNER, ? super P> list, final Adapter<E, INNER> elementsAdapter) {
442 return new TabFieldList<E, P>() {
443 @Override public void setDefaults(ILaunchConfigurationWorkingCopy configur ation, P params) {
444 list.setDefaults(configuration, params);
445 }
446 @Override public void initializeFrom(E elements, ILaunchConfiguration conf iguration) {
447 list.initializeFrom(elementsAdapter.get(elements), configuration);
448 }
449 @Override
450 public void saveToConfig(E elements, ILaunchConfigurationWorkingCopy confi guration) {
451 list.saveToConfig(elementsAdapter.get(elements), configuration);
452 }
453 };
454 }
455
456 static <E, P> TabFieldList<E, P> createCompositeFieldList(
457 final List<? extends TabFieldList<? super E, ? super P>> listList) {
458 return new TabFieldList<E, P>() {
459 @Override
460 public void setDefaults(ILaunchConfigurationWorkingCopy configuration,
461 P params) {
462 for (TabFieldList<?, ? super P> list : listList) {
463 list.setDefaults(configuration, params);
464 }
465 }
466
467 @Override
468 public void initializeFrom(E elements, ILaunchConfiguration configuration) {
469 for (TabFieldList<? super E, ?> list : listList) {
470 list.initializeFrom(elements, configuration);
471 }
472 }
473
474 @Override
475 public void saveToConfig(E elements,
476 ILaunchConfigurationWorkingCopy configuration) {
477 for (TabFieldList<? super E, ?> list : listList) {
478 list.saveToConfig(elements, configuration);
479 }
480 }
481 };
482 }
395 } 483 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698