📄 deviceeditorregistry.java
字号:
/**
* Copyright (c) 2003-2006 Craig Setera
* All Rights Reserved.
* Licensed under the Eclipse Public License - v 1.0
* For more information see http://www.eclipse.org/legal/epl-v10.html
*/
package eclipseme.ui.internal.devices;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import eclipseme.core.model.device.IDevice;
import eclipseme.ui.internal.EclipseMEUIPlugin;
/**
* Provides registry functionality for attaching editors to
* particular device types.
* <p />
* Copyright (c) 2003-2006 Craig Setera<br>
* All Rights Reserved.<br>
* Licensed under the Eclipse Public License - v 1.0<p/>
* <br>
* $Revision: 1.1 $
* <br>
* $Date: 2006/02/25 01:55:03 $
* <br>
* @author Craig Setera
*/
public class DeviceEditorRegistry {
/** The extension point */
public static final String ID_EXTENSION = "deviceEditor";
private static DeviceEditorConfigElement[] editors;
/**
* Return the editor configuration element for editing the specified
* device or <code>null</code> if no editor element can be found.
*
* @param device
* @return
*/
public static DeviceEditorConfigElement findEditorElement(IDevice device) {
DeviceEditorConfigElement element = null;
DeviceEditorConfigElement[] elements = getEditors();
Class deviceClass = device.getClass();
for (int i = 0; i < elements.length; i++) {
String matchClassName = elements[i].getDeviceClass();
if (isMatchingType(deviceClass, matchClassName)) {
element = elements[i];
break;
}
}
return element;
}
/**
* Return a boolean if the specified class matches the specified class
* name directly or via supertypes and interfaces.
*
* @param type
* @param matchClassName
* @return
*/
private static boolean isMatchingType(Class type, String matchClassName) {
boolean matches = false;
if (type != null) {
matches = type.getName().equals(matchClassName);
// Test superclasses
if (!matches) {
matches = isMatchingType(type.getSuperclass(), matchClassName);
}
// Test interfaces
if (!matches) {
Class[] interfaces = type.getInterfaces();
for (int i = 0; !matches && i < interfaces.length; i++) {
matches = isMatchingType(interfaces[i], matchClassName);
}
}
}
return matches;
}
/**
* Return the editor extensions as an array of DeviceEditorConfigElement
* instances.
*
* @return
*/
private static DeviceEditorConfigElement[] getEditors() {
if (editors == null) {
editors = readEditors();
}
return editors;
}
/**
* Return the editor extensions as a list of DeviceEditorConfigElement
* instances.
*
* @return
*/
private static DeviceEditorConfigElement[] readEditors() {
String plugin = EclipseMEUIPlugin.getDefault().getBundle().getSymbolicName();
IConfigurationElement[] configElements =
Platform.getExtensionRegistry().getConfigurationElementsFor(plugin, ID_EXTENSION);
DeviceEditorConfigElement[] elements = new DeviceEditorConfigElement[configElements.length];
for (int i = 0; i < configElements.length; i++) {
elements[i] = new DeviceEditorConfigElement(configElements[i]);
}
return elements;
}
/**
* Static-only access.
*/
private DeviceEditorRegistry() {
super();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -