Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: dd8713bf5be50665b659b7d4583f80a911dbbc44 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
/*******************************************************************************
 * Copyright (c) 2006, 2014 Soyatec (http://www.soyatec.com), CEA, and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Soyatec - initial API and implementation
 *     Christian W. Damus (CEA) - bug 417409
 *     
 *******************************************************************************/
package org.eclipse.papyrus.xwt;

import java.io.InputStream;
import java.net.URL;
import java.util.Collection;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.databinding.observable.IChangeListener;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
import org.eclipse.core.databinding.observable.set.IObservableSet;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.papyrus.xwt.callback.IBeforeParsingCallback;
import org.eclipse.papyrus.xwt.callback.ICreatedCallback;
import org.eclipse.papyrus.xwt.callback.ILoadedCallback;
import org.eclipse.papyrus.xwt.core.TriggerBase;
import org.eclipse.papyrus.xwt.databinding.IBindingContext;
import org.eclipse.papyrus.xwt.input.ICommand;
import org.eclipse.papyrus.xwt.internal.core.UpdateSourceTrigger;
import org.eclipse.papyrus.xwt.internal.xml.IElementCache;
import org.eclipse.papyrus.xwt.metadata.IMetaclass;
import org.eclipse.papyrus.xwt.metadata.IProperty;
import org.eclipse.swt.widgets.Composite;

/**
 * XWT loader interface
 * 
 * @author yyang (yves.yang@soyatec.com)
 */
public interface IXWTLoader {

	// Properties

	/**
	 * The URL which open XWT file
	 * 
	 */
	String URL_PROPERTY = "XWT.URL";

	/**
	 * style of type int is used to create SWT element
	 */
	String CONTAINER_PROPERTY = "XWT.Container";

	String INIT_STYLE_PROPERTY = "XWT.Style";

	/**
	 * Used for editor/designer to pass design mode
	 */
	String DESIGN_MODE_PROPERTY = "XWT.DesignMode";

	/**
	 * Default styles to apply. The value should be a collection or Array of
	 * IStyle
	 * 
	 */
	String DEFAULT_STYLES_PROPERTY = "XWT.DefaultStyles";

	/**
	 * Enabled or disabled the styles. By default, it is enabled
	 * 
	 */
	String DISABLE_STYLES_PROPERTY = "XWT.DisabledStyles";

	/**
	 * The DataContext to setup in root element
	 * 
	 */
	String DATACONTEXT_PROPERTY = "XWT.DataContext";

	/**
	 * The BindingContext to setup in root element
	 * 
	 */
	String BINDING_CONTEXT_PROPERTY = "XWT.BindingContext";

	/**
	 * The CLR class
	 * 
	 */
	String CLASS_PROPERTY = "XWT.Class";

	/**
	 * The CLR class factory
	 * 
	 */
	String CLASS_FACTORY_PROPERTY = "XWT.ClassFactory";

	/**
	 * Resources to associate to root element
	 * 
	 */
	String RESOURCE_DICTIONARY_PROPERTY = "XWT.Resources";

	/**
	 * Resources to associate to root element
	 * 
	 */
	String LOADED_CALLBACK = ILoadedCallback.class.getName();

	/**
	 * Action to invoke after the creation of each UI element before the properties setting
	 * 
	 */
	String CREATED_CALLBACK = ICreatedCallback.class.getName();

	/**
	 * Action to invoke before parsing the XML file
	 * 
	 */
	String BEFORE_PARSING_CALLBACK = IBeforeParsingCallback.class.getName();
	
	/**
	 * Parsed XML element caching option. In the public API, this may be only either a {@link Boolean} indicating whether to cache the XML content
	 * parsed from XWT resources (the cache having some unspecified default size) or a positive {@link Integer} indicating the size of XML cache.
	 * This load option is a bit odd in that, if specified, it is replaced by the actual cache, which then should be supplied as the option value
	 * for subsequent calls. Thus, the following idiom is recommended:
	 * 
	 * <pre>
	 *   private Object xmlCache; // the XML cache
	 *   
	 *   // other fields ...
	 *   
	 *   void whatever() {
	 *       Map<String, Object> options = new HashMap&lt;String, Object&gt;();
	 *       options.put(IXWTLoader.XML_CACHE_PROPERTY, (xmlCache != null) ? xmlCache : Boolean.TRUE);
	 *       // ... set other options as needed ...
	 *   
	 *       URL url = getResourceURL(); // however this is obtained
	 *       
	 *       Object ui = XWT.loadWithOptions(url, options);
	 *       
	 *       // Get the cache to reuse next time
	 *       xmlCache = options.get(IXWTLoader.XML_CACHE_PROPERTY);
	 *       
	 *       doSomethingWithTheUI(ui);
	 *   }
	 * </pre>
	 */
	String XML_CACHE_PROPERTY = IElementCache.class.getName();


	String[] ALL_PROPERTIES = { URL_PROPERTY, CONTAINER_PROPERTY, INIT_STYLE_PROPERTY, DATACONTEXT_PROPERTY, BINDING_CONTEXT_PROPERTY, RESOURCE_DICTIONARY_PROPERTY, CLASS_PROPERTY, CLASS_FACTORY_PROPERTY, LOADED_CALLBACK, CREATED_CALLBACK, BEFORE_PARSING_CALLBACK, DESIGN_MODE_PROPERTY, XML_CACHE_PROPERTY };

	/**
	 * Register an Observable IChangeListener for a given UI element. The second
	 * registration of the same listener on the same UI Element has no effect.
	 * 
	 * @param control
	 * @param listener
	 * @return
	 */
	boolean addObservableChangeListener(Object control, IChangeListener listener);

	/**
	 * Undo the registration of the Observable IChangeListener for a given UI
	 * element.
	 * 
	 * @param context
	 * @param listener
	 */
	void removeObservableChangeListener(Object context, IChangeListener listener);

	/**
	 * Find the used IObservable value for given data.
	 * 
	 * @param nsmapace
	 * @return
	 */
	IObservable observe(Object context, Object data, String propertyName, UpdateSourceTrigger updateSourceTrigger);

	/**
	 * Find the used IObservableFactory value for given data.
	 * 
	 * @param nsmapace
	 * @return
	 */
	IObservableFactory observableFactory(Object context, String propertyName, UpdateSourceTrigger updateSourceTrigger);

	/**
	 * Find the used IObservableValue value for given data.
	 * 
	 * @param nsmapace
	 * @return
	 */
	IObservableValue observableValue(Object context, Object data, String propertyName, UpdateSourceTrigger updateSourceTrigger);

	/**
	 * Find the used IObservableList value for given data.
	 * 
	 * @param nsmapace
	 * @return
	 */
	IObservableList findObservableList(Object context, Object data, String propertyName);

	/**
	 * Find the used IObservableList value for given data.
	 * 
	 * @param nsmapace
	 * @return
	 */
	IObservableSet findObservableSet(Object context, Object data, String propertyName);

	/**
	 * Find the used IObservableValue value for given data.
	 * 
	 * @param context
	 * @param data
	 * @param propertyName
	 * @return
	 */
	IObservableValue findObservableValue(Object context, Object data, String propertyName);

	/**
	 * Find the resource in Resources Dictionary attached in the UI Element.
	 * If the key isn't found, the research will be propagated in its parent.
	 * 
	 * @param object
	 * @param key
	 * @return
	 */
	Object findResource(Object object, String key);

	/**
	 * Get the Resources Dictionary attached in the UI Element.
	 * 
	 * @param object
	 * @return
	 */
	Map<String, Object> getResources(Object object);

	/**
	 * 
	 * @param nsmapace
	 * @param handler
	 */
	void registerNamespaceHandler(String nsmapace, INamespaceHandler handler);

	/**
	 * 
	 * @param nsmapace
	 */
	void unregisterNamespaceHandler(String nsmapace);

	/**
	 * 
	 * @param nsmapace
	 * @return
	 */
	INamespaceHandler getNamespaceHandler(String nsmapace);

	/**
	 * 
	 * @return
	 */
	Realm getRealm();

	/**
	 * Get the system logger.
	 * 
	 * @return
	 */
	ILogger getLogger();

	/**
	 * Change the system logger
	 * 
	 * @param logger
	 */
	void setLogger(ILogger log);

	/**
	 * This namespace service returns the associated or declared namespace for a
	 * given class.
	 * 
	 * @param javaclass
	 * @return
	 */
	String getNamespace(Class<?> javaclass);

	/**
	 * Get the name of the element, which is defined by <code>Name</code> or <code>x:Name</code>. Return <code>null</code>
	 * 
	 * @param object
	 * @return
	 */
	String getElementName(Object object);

	/**
	 * Find a named UI element.
	 * 
	 * @param context
	 *        the start point of research.
	 * @param name
	 * @return
	 */
	Object findElementByName(Object context, String name);

	/**
	 * Get the DataContext of given element
	 * 
	 * @param context
	 * @return
	 */
	Object getDataContext(Object element);

	/**
	 * Get the Triggers of given element
	 * 
	 * @param context
	 * @return
	 */
	TriggerBase[] getTriggers(Object element);

	/**
	 * Change the DataContext of given element
	 * 
	 * @param context
	 * @return
	 */
	void setDataContext(Object widget, Object dataContext);

	/**
	 * Changes the default data context of given element
	 * 
	 * @param widget
	 * @param dataBindingContext
	 */
	void setDataBindingContext(Object widget, Object dataBindingContext);

	/**
	 * Change the Triggers of given element
	 * 
	 * @param context
	 * @return
	 */
	void setTriggers(Object widget, TriggerBase[] triggers);

	/**
	 * Find the closet parent of type Composite
	 * 
	 * @param context
	 * @return
	 */
	Composite findCompositeParent(Object context);

	/**
	 * Get the Metaclass of the given object
	 * 
	 * @param context
	 * @return
	 */
	IMetaclass getMetaclass(Object object);

	/**
	 * Load the file content. All widget will be created but they are showed.
	 * This method return the root element.
	 * 
	 */
	Object load(URL file) throws Exception;

	/**
	 * Load the file content with a DataContext. All widget will be created but
	 * they are showed. This method returns the root element. The DataContext
	 * will be associated to the root element.
	 */
	Object load(URL file, Object dataContext) throws Exception;

	Object load(IUIResource resource, Object dataContext) throws Exception;

	/**
	 * Load the file content under a UI Object. All widget will be created. This
	 * method returns the root element. The DataContext will be associated to
	 * the root element.
	 */
	Object load(Object parent, URL file) throws Exception;

	/**
	 * Load the file content under a UI Object. All widget will be created. This
	 * method returns the root element. The DataContext will be associated to
	 * the root element.
	 */
	Object load(Object parent, IUIResource resource) throws Exception;

	/**
	 * Load the file content under a UI Object with a DataContext. All widget
	 * will be created. This method returns the root element. The DataContext
	 * will be associated to the root element.
	 */
	Object load(Object parent, URL file, Object dataContext) throws Exception;

	/**
	 * Load the file content under a UI Object with a DataContext. All widget
	 * will be created. This method returns the root element. The DataContext
	 * will be associated to the root element.
	 */
	Object load(Object parent, IUIResource resource, Object dataContext) throws Exception;

	/**
	 * Load the file content under a UI Object with a DataContext. All widget
	 * will be created. This method returns the root element. The DataContext
	 * will be associated to the root element.
	 */
	Object load(Object parent, IUIResource resource, Map<String, Object> options) throws Exception;

	/**
	 * Load the file content under a UI Object with a DataContext. All widget
	 * will be created. This method returns the root element. The DataContext
	 * will be associated to the root element.
	 */
	Object load(Object parent, Class<?> viewType, Object dataContext) throws Exception;

	/**
	 * Load the file content under a UI Object with a DataContext. All widget
	 * will be created. This method returns the root element. The DataContext
	 * will be associated to the root element.
	 */
	Object loadWithOptions(Class<?> viewType, Map<String, Object> options) throws Exception;

	/**
	 * Open and show the file content in a new Shell.
	 */
	void open(Class<?> type) throws Exception;

	/**
	 * Open and show the file content in a new Shell.
	 */
	void open(URL url) throws Exception;

	void open(IUIResource resource) throws Exception;

	/**
	 * load the content from a stream with a style, a DataContext and a
	 * ResourceDictionary. The root elements will be hold by UI Object parent
	 */
	Object load(Object parent, InputStream stream, URL file, Object dataContext) throws Exception;

	/**
	 * load the file content. The corresponding UI element is not yet created
	 */
	void open(URL url, Object dataContext) throws Exception;

	void open(IUIResource resource, Object dataContext) throws Exception;

	/**
	 * load the file content. The corresponding UI element is not yet created
	 */
	void open(Class<?> type, Object dataContext) throws Exception;

	/**
	 * load the file content. The corresponding UI element is not yet created
	 */
	void open(URL url, Map<String, Object> options) throws Exception;

	void open(IUIResource resource, final Map<String, Object> options) throws Exception;

	/**
	 * Data conversion service from String to a given type
	 * 
	 * @param type
	 * @param string
	 * @return
	 */
	Object convertFrom(IMetaclass type, String string);

	/**
	 * Data conversion service from String to a given type
	 * 
	 * @param targetType
	 * @param string
	 * @return
	 */
	Object convertFrom(Class<?> targetType, String string);

	Object loadWithOptions(URL url, Map<String, Object> options) throws Exception;

	/**
	 * 
	 * @param stream
	 * @param url
	 * @param options
	 * @return
	 * @throws Exception
	 */
	Object load(InputStream stream, URL url) throws Exception;

	Object load(IUIResource resource) throws Exception;

	public IUIResource loadAsResource(InputStream stream, URL input) throws Exception;

	public IUIResource loadAsResource(InputStream stream, URL input, IBeforeParsingCallback parsingCallback) throws Exception;

	public IUIResource loadAsResource(URL input) throws Exception;

	public IUIResource loadAsResource(URL input, IBeforeParsingCallback parsingCallback) throws Exception;

	/**
	 * Generic load method
	 * 
	 * @param stream
	 * @param url
	 * @param loadData
	 * @return
	 * @throws Exception
	 */
	Object loadWithOptions(InputStream stream, URL url, Map<String, Object> options) throws Exception;

	Object loadWithOptions(IUIResource resource, Map<String, Object> options) throws Exception;

	/**
	 * Metaclass services to return all registered Metaclasses.
	 * 
	 * @param stream
	 * @param url
	 * @param loadData
	 * @return
	 * @throws Exception
	 */
	IMetaclass[] getAllMetaclasses();

	/**
	 * Get the corresponding Metaclass
	 * 
	 * @param tagName
	 * @param ns
	 *        The namespace
	 * @return
	 */
	IMetaclass getMetaclass(String tagName, String ns);

	/**
	 * Register UI type
	 * 
	 * @param javaclass
	 */
	IMetaclass registerMetaclass(Class<?> type);

	/**
	 * Register UI type
	 * 
	 * @param javaclass
	 */
	void registerMetaclass(IMetaclass type);

	/**
	 * Get the dynamic property value
	 * 
	 * @param javaclass
	 */
	Object getPropertyValue(Object uiElement, IProperty property);

	/**
	 * Set the dynamic property value
	 * 
	 * @param javaclass
	 */
	void setPropertyValue(Object uiElement, IProperty property, Object value);

	/**
	 * Remove the dynamic property value
	 * 
	 * @param javaclass
	 */
	void removePropertyValue(Object uiElement, IProperty property);

	/**
	 * Remove the dynamic property value
	 * 
	 * @param javaclass
	 */
	boolean hasPropertyValue(Object uiElement, IProperty property);

	/**
	 * Register Metaclass factory
	 * 
	 * @param javaclass
	 */
	void registerMetaclassFactory(IMetaclassFactory metaclassFactory);

	/**
	 * Find a Data converter
	 * 
	 * @param converter
	 * @param type
	 */
	IConverter findConvertor(Class<?> source, Class<?> target);

	/**
	 * Register a Data converter
	 * 
	 * @param converter
	 * @param type
	 */
	void registerConvertor(IConverter converter);

	/**
	 * Add a tracking option
	 * 
	 * @param tracking
	 */
	void addTracking(Tracking tracking);

	/**
	 * Test if the tracking on argument is enabled.
	 * 
	 * @param tracking
	 * @return
	 */
	boolean isTracking(Tracking tracking);

	/**
	 * Get all tracking options
	 * 
	 * @return
	 */
	Set<Tracking> getTrackings();

	/**
	 * Remove a tracking option.
	 * 
	 * @param tracking
	 */
	void removeTracking(Tracking tracking);

	/**
	 * Register a command to a name
	 * 
	 * @param name
	 * @param command
	 */
	void registerCommand(String name, ICommand command);

	/**
	 * Register a command to a name
	 * 
	 * @param name
	 * @param command
	 */
	void registerEventGroup(Class<?> type, IEventGroup eventGroup);

	/**
	 * Find a command by name
	 * 
	 * @param name
	 * @return
	 */
	ICommand getCommand(String name);

	/**
	 * Return all registered commands
	 * 
	 * @return
	 */
	Map<String, ICommand> getCommands();

	/**
	 * Unregister a command
	 * 
	 * @param name
	 */
	void unregisterCommand(String name);

	/**
	 * Add a default style
	 * 
	 * @param style
	 * @return
	 */
	void addDefaultStyle(IStyle style);

	/**
	 * Remove a default style
	 * 
	 * @param style
	 * @return
	 */
	void removeDefaultStyle(IStyle style);

	Collection<IStyle> getDefaultStyles();

	void addDataProviderFactory(String name, IDataProviderFactory dataProviderFactory);

	void removeDataProviderFactory(String name);

	void removeDataProviderFactory(IDataProviderFactory dataProvider);

	Collection<IDataProviderFactory> getDataProviderFactories();

	IDataProvider findDataProvider(Object dataContext);

	ILoadingContext findLoadingContext(Object container);

	ILoadingContext getLoadingContext(Object object);

	ILoadingContext getLoadingContext();

	void setLoadingContext(ILoadingContext loadingContext);

	/**
	 * Create a UI Profile with the provide data and apply it immediately.
	 * 
	 * @param profileData
	 * @return
	 */
	public Object createUIProfile();

	/**
	 * Put the Profile in place
	 * 
	 * @param profile
	 * @return
	 */
	public boolean applyProfile(Object profile);

	/**
	 * Restore the previous profile
	 * 
	 * @return
	 */
	public Object restoreProfile();

	/**
	 * Set up the default ICLRFactory
	 * 
	 * @param factory
	 */
	public void setCLRFactory(ICLRFactory factory);

	/**
	 * The default CLRFactory.
	 * 
	 * @return
	 */
	public ICLRFactory getCLRFactory();

	/**
	 * Returns the {@link BindingContext} of the element
	 * 
	 * @param element
	 * @param contextName
	 * @return
	 */
	IBindingContext getBindingContext(Object element);

	/**
	 * Check if the value of a property is to resolve.
	 * 
	 * @param type
	 *        type of property
	 * @return
	 */
	boolean isFileResolveType(Class<?> type);

	/**
	 * Register the value of a property is to resolve.
	 * 
	 * @param type
	 *        type of property
	 * @return
	 */
	void registerFileResolveType(Class<?> type);

	/**
	 * Register the value of a property is to resolve.
	 * 
	 * @param type
	 *        type of property
	 * @return
	 */
	void unregisterFileResolveType(Class<?> type);

	public class Utilities {

		public static boolean isPropertyName(String name) {
			for(String propertyName : ALL_PROPERTIES) {
				if(propertyName.equalsIgnoreCase(name)) {
					return true;
				}
			}
			return false;
		}
	}
}

Back to the top