| 1 |
/** |
| 2 |
* Copyright (c) 2010 Kenn Hussey and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Common Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/cpl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Kenn Hussey - Initial API and implementation |
| 10 |
*/ |
| 11 |
package org.eclipse.emf.edit.ui.util; |
| 12 |
|
| 13 |
import java.util.HashMap; |
| 14 |
import java.util.Map; |
| 15 |
|
| 16 |
import org.eclipse.emf.ecore.EClassifier; |
| 17 |
import org.eclipse.jface.text.ITextViewer; |
| 18 |
import org.eclipse.swt.widgets.Composite; |
| 19 |
|
| 20 |
|
| 21 |
/** |
| 22 |
* An interface for text viewers of query delegate expressions. |
| 23 |
* |
| 24 |
* @since 2.7 |
| 25 |
*/ |
| 26 |
public interface QueryDelegateTextViewer extends ITextViewer |
| 27 |
{ |
| 28 |
/** |
| 29 |
* A factory for creating query delegate source viewers. |
| 30 |
*/ |
| 31 |
interface Factory |
| 32 |
{ |
| 33 |
/** |
| 34 |
* Creates a query delegate for the specified <tt>parent</tt>. |
| 35 |
* |
| 36 |
* @param parent the parent container for the text viewer |
| 37 |
* @param styles the styles to apply to the text viewer |
| 38 |
* @return a query delegate text viewer |
| 39 |
*/ |
| 40 |
QueryDelegateTextViewer createTextViewer(Composite parent, int styles); |
| 41 |
|
| 42 |
/** |
| 43 |
* A <code>Factory</code> wrapper that is used by the {@link Factory.Registry}. |
| 44 |
*/ |
| 45 |
interface Descriptor |
| 46 |
{ |
| 47 |
Factory getFactory(); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* A registry of query delegate text viewer factories. |
| 52 |
*/ |
| 53 |
interface Registry extends Map<String, Object> |
| 54 |
{ |
| 55 |
Registry INSTANCE = new Impl(); |
| 56 |
|
| 57 |
Factory getFactory(String uri); |
| 58 |
|
| 59 |
class Impl extends HashMap<String, Object> implements Registry |
| 60 |
{ |
| 61 |
private static final long serialVersionUID = 1L; |
| 62 |
|
| 63 |
@Override |
| 64 |
public Object get(Object key) |
| 65 |
{ |
| 66 |
Object factory = super.get(key); |
| 67 |
if (factory instanceof Descriptor) |
| 68 |
{ |
| 69 |
Descriptor factoryDescriptor = (Descriptor)factory; |
| 70 |
factory = factoryDescriptor.getFactory(); |
| 71 |
put((String)key, factory); |
| 72 |
return factory; |
| 73 |
} |
| 74 |
else |
| 75 |
{ |
| 76 |
return factory; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
public Factory getFactory(String uri) |
| 81 |
{ |
| 82 |
return (Factory)get(uri); |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Sets the context for the text viewer's query. |
| 90 |
* |
| 91 |
* @param context the type of object against which the query will be executed |
| 92 |
*/ |
| 93 |
void setContext(EClassifier context); |
| 94 |
|
| 95 |
/** |
| 96 |
* Sets the parameters for the text viewer's query. |
| 97 |
* |
| 98 |
* @param parameters a map of parameter names to types |
| 99 |
*/ |
| 100 |
void setParameters(Map<String, EClassifier> parameters); |
| 101 |
|
| 102 |
} |