|
Added
Link Here
|
| 1 |
/********************************************************************** |
| 2 |
* Copyright (c) 2008 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* $Id: ContextOpenSourceHandlerManager.java,v 1.3 2008/01/24 02:28:55 apnan Exp $ |
| 8 |
* |
| 9 |
* Contributors: |
| 10 |
* IBM - Initial API and implementation |
| 11 |
**********************************************************************/ |
| 12 |
|
| 13 |
package org.eclipse.tptp.platform.common.ui.views; |
| 14 |
|
| 15 |
import java.util.HashMap; |
| 16 |
import java.util.Map; |
| 17 |
import java.util.Vector; |
| 18 |
|
| 19 |
import org.eclipse.core.runtime.IConfigurationElement; |
| 20 |
import org.eclipse.core.runtime.IExtensionPoint; |
| 21 |
import org.eclipse.core.runtime.Platform; |
| 22 |
import org.eclipse.tptp.platform.common.internal.CommonPlugin; |
| 23 |
|
| 24 |
/** |
| 25 |
* This class manages TPTP statistics table column cell hover text provider. |
| 26 |
* It manages all registered hover text provider. It allows them to be |
| 27 |
* accessed by column ID key. |
| 28 |
* |
| 29 |
* @since 4.5 |
| 30 |
*/ |
| 31 |
public class TableCellLabelProviderManager { |
| 32 |
|
| 33 |
//instance of context manager |
| 34 |
protected static TableCellLabelProviderManager instance; |
| 35 |
|
| 36 |
//extension points and elements Id |
| 37 |
protected final String PROVIDER_EXTENSION_POINT = "TableCellLabelProviders"; |
| 38 |
protected final String PROVIDER_EXTENSION_POINT_ELEMENT = "tableCellLabelProvider"; |
| 39 |
|
| 40 |
protected Map providersByColumnKey; |
| 41 |
|
| 42 |
/** |
| 43 |
* Return an instance of the manager. |
| 44 |
* @return instance of manager |
| 45 |
*/ |
| 46 |
public static TableCellLabelProviderManager instance() |
| 47 |
{ |
| 48 |
if (instance == null) |
| 49 |
instance = new TableCellLabelProviderManager(); |
| 50 |
|
| 51 |
return instance; |
| 52 |
} |
| 53 |
|
| 54 |
protected void initializeProviders() |
| 55 |
{ |
| 56 |
providersByColumnKey = new HashMap(); |
| 57 |
|
| 58 |
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.tptp.platform.common.ui", PROVIDER_EXTENSION_POINT); |
| 59 |
|
| 60 |
if (point != null) { |
| 61 |
IConfigurationElement[] elements = point.getConfigurationElements(); |
| 62 |
|
| 63 |
for (int i = 0; i < elements.length; i++) { |
| 64 |
|
| 65 |
IConfigurationElement elem = elements[i]; |
| 66 |
|
| 67 |
if (elem.getName().equals(PROVIDER_EXTENSION_POINT_ELEMENT)) { |
| 68 |
String id = elem.getAttribute("id"); |
| 69 |
// String name = elem.getAttribute("name"); |
| 70 |
// String key = elem.getAttribute("supportColumnIDs"); |
| 71 |
|
| 72 |
TableCellLabelProvider tableCellLabelProvider = null; |
| 73 |
String[] keys = null; |
| 74 |
|
| 75 |
try |
| 76 |
{ |
| 77 |
if (!"".equals(elem.getAttribute("class"))) { |
| 78 |
Object clz = elem.createExecutableExtension("class"); |
| 79 |
if (clz instanceof TableCellLabelProvider) { |
| 80 |
tableCellLabelProvider = (TableCellLabelProvider)clz; |
| 81 |
keys = tableCellLabelProvider.getSupportColumnKeys(); |
| 82 |
} |
| 83 |
else { |
| 84 |
CommonPlugin.logError("Class in extension point org.eclipse.tptp.platform.common.ui"+PROVIDER_EXTENSION_POINT+" must implement TableCellLabelProvider"); |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
catch (Exception e) |
| 89 |
{ |
| 90 |
e.printStackTrace(); |
| 91 |
} |
| 92 |
|
| 93 |
if(id==null || tableCellLabelProvider==null || keys == null) |
| 94 |
continue; |
| 95 |
|
| 96 |
for (int j=0;j<keys.length;j++) { |
| 97 |
String colID = keys[j]; |
| 98 |
|
| 99 |
Vector providerList = (Vector)(providersByColumnKey.get(colID)); |
| 100 |
if (providerList==null) { |
| 101 |
providerList = new Vector(); |
| 102 |
providerList.add(tableCellLabelProvider); |
| 103 |
providersByColumnKey.put(colID, providerList); |
| 104 |
} |
| 105 |
else { |
| 106 |
providerList.add(tableCellLabelProvider); |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
protected void initialize() |
| 115 |
{ |
| 116 |
initializeProviders(); |
| 117 |
} |
| 118 |
|
| 119 |
protected Vector getProvidersByColID(String colID) |
| 120 |
{ |
| 121 |
if (providersByColumnKey==null) |
| 122 |
initialize(); |
| 123 |
|
| 124 |
Vector v = (Vector)providersByColumnKey.get(colID); |
| 125 |
return v; |
| 126 |
} |
| 127 |
|
| 128 |
public static Vector getProvidersByColIDLKey(String colID) { |
| 129 |
return TableCellLabelProviderManager.instance().getProvidersByColID(colID); |
| 130 |
} |
| 131 |
} |
| 132 |
|