Java Code Examples for org.eclipse.core.runtime.IConfigurationElement.getAttribute()

The following are Jave code examples for showing how to use getAttribute() of the org.eclipse.core.runtime.IConfigurationElement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: gemoc-studio   File: AbstractNewProjectWizardWithTemplates.java   Source Code and License Vote up 6 votes
protected WizardElement createWizardElement(IConfigurationElement config) {
	String name = config.getAttribute(WizardElement.ATT_NAME);
	String id = config.getAttribute(WizardElement.ATT_ID);
	String className = config.getAttribute(WizardElement.ATT_CLASS);
	if (name == null || id == null || className == null)
		return null;
	WizardElement element = new WizardElement(config);
	element.id = id;
	String imageName = config.getAttribute(WizardElement.ATT_ICON);
	if (imageName != null) {
		String pluginID = config.getNamespaceIdentifier();
		Image image = PDEPlugin.getDefault().getLabelProvider().getImageFromPlugin(pluginID, imageName);
		element.setImage(image);
	}
	return element;
}
 
Example 2
Project: scanning   File: PointGeneratorService.java   Source Code and License Vote up 6 votes
private static void readExtensions(Map<Class<? extends IScanPathModel>, Class<? extends IPointGenerator<?>>> gens,
		                           Map<String,   GeneratorInfo> tids) throws CoreException {

	if (Platform.getExtensionRegistry()!=null) {
		final IConfigurationElement[] eles = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.scanning.api.generator");
		for (IConfigurationElement e : eles) {
			final IPointGenerator<?>    generator = (IPointGenerator<?>)e.createExecutableExtension("class");
			final IScanPathModel     model = (IScanPathModel)e.createExecutableExtension("model");

			final Class<? extends IScanPathModel> modelClass = model.getClass();
			@SuppressWarnings("unchecked")
			final Class<? extends IPointGenerator<?>> generatorClass = (Class<? extends IPointGenerator<?>>) generator.getClass();
			gens.put(modelClass, generatorClass);

			final GeneratorInfo info = new GeneratorInfo();
			info.setModelClass(model.getClass());
			info.setGeneratorClass(generator.getClass());
			info.setLabel(e.getAttribute("label"));
			info.setDescription(e.getAttribute("description"));

			String id = e.getAttribute("id");
			tids.put(id, info);
		}
	}
}
 
Example 3
Project: neoscada   File: ConnectionCreatorHelper.java   Source Code and License Vote up 6 votes
public static ConnectionService createConnection ( final ConnectionInformation info, final Integer autoReconnectDelay, final boolean lazyActivation )
{
    if ( info == null )
    {
        return null;
    }

    for ( final IConfigurationElement ele : Platform.getExtensionRegistry ().getConfigurationElementsFor ( Activator.EXTP_CONNECTON_CREATOR ) )
    {
        final String interfaceName = ele.getAttribute ( "interface" );
        final String driverName = ele.getAttribute ( "driver" );
        if ( interfaceName == null || driverName == null )
        {
            continue;
        }
        if ( interfaceName.equals ( info.getInterface () ) && driverName.equals ( info.getDriver () ) )
        {
            final ConnectionService service = createConnection ( info, ele, autoReconnectDelay, lazyActivation );
            if ( service != null )
            {
                return service;
            }
        }
    }
    return null;
}
 
Example 4
Project: neoscada   File: StyleGeneratorInformation.java   Source Code and License Vote up 6 votes
public static List<StyleGeneratorInformation> list ()
{
    final List<StyleGeneratorInformation> result = new LinkedList<StyleGeneratorInformation> ();

    for ( final IConfigurationElement ele : Platform.getExtensionRegistry ().getConfigurationElementsFor ( EXTP_STYLE_GENERATOR ) )
    {
        if ( !ELE_STYLE_GENERATOR.equals ( ele.getName () ) )
        {
            continue;
        }

        final String id = ele.getAttribute ( "id" ); //$NON-NLS-1$
        final String name = ele.getAttribute ( "name" ); //$NON-NLS-1$
        final String description = getText ( ele.getChildren ( "description" ) ); //$NON-NLS-1$

        result.add ( new StyleGeneratorInformation ( id, name, description ) );
    }

    return result;
}
 
Example 5
Project: neoscada   File: ConfigurationHelper.java   Source Code and License Vote up 6 votes
private static MonitorViewConfiguration convertMonitor ( final IConfigurationElement ele )
{
    try
    {
        final String id = ele.getAttribute ( "id" ); //$NON-NLS-1$
        final String monitorQueryId = ele.getAttribute ( "monitorQueryId" ); //$NON-NLS-1$
        final String connectionString = ele.getAttribute ( "connectionString" ); //$NON-NLS-1$
        final ConnectionType connectionType = ConnectionType.valueOf ( ele.getAttribute ( "connectionType" ) ); //$NON-NLS-1$
        final String label = ele.getAttribute ( "label" ); //$NON-NLS-1$
        final List<ColumnProperties> columns = parseColumnSettings ( ele.getAttribute ( "columns" ) ); //$NON-NLS-1$

        return new MonitorViewConfiguration ( id, monitorQueryId, connectionString, connectionType, label, columns );
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to convert monitor configuration: {}", ele ); //$NON-NLS-1$
        return null;
    }
}
 
Example 6
Project: scanning   File: GeneratorDescriptor.java   Source Code and License Vote up 6 votes
private void createIcons() {
	icons   = new HashMap<String, Image>(7);

	final IConfigurationElement[] eles = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.scanning.api.generator");
	for (IConfigurationElement e : eles) {
		final String     identity = e.getAttribute("id");

		final String icon = e.getAttribute("icon");
		if (icon !=null) {
			final String   cont  = e.getContributor().getName();
			final Bundle   bundle= Platform.getBundle(cont);
			final URL      entry = bundle.getEntry(icon);
			final ImageDescriptor des = ImageDescriptor.createFromURL(entry);
			icons.put(identity, des.createImage());
		}

	}
}
 
Example 7
Project: neoscada   File: DetailViewManager.java   Source Code and License Vote up 6 votes
public static DetailView openView ( final String id, final Map<String, String> properties ) throws CoreException
{
    logger.info ( "Searching view: {}", id ); //$NON-NLS-1$

    for ( final IConfigurationElement ele : Platform.getExtensionRegistry ().getConfigurationElementsFor ( EXTP_DETAIL_VIEW ) )
    {
        final String cfgId = ele.getAttribute ( "id" ); //$NON-NLS-1$

        logger.debug ( "Checking: {}", cfgId ); //$NON-NLS-1$

        if ( cfgId != null && cfgId.equals ( id ) )
        {
            return createDetailView ( id, ele, properties );
        }
    }
    return null;
}
 
Example 8
Project: neoscada   File: ConfigurationHelper.java   Source Code and License Vote up 6 votes
private static AlarmNotifierConfiguration convertAlarmNotifier ( final IConfigurationElement ele )
{
    try
    {
        final String connectionId = ele.getAttribute ( "connectionId" ); //$NON-NLS-1$
        final String prefix = ele.getAttribute ( "prefix" ) == null ? "ae.server.info" : ele.getAttribute ( "prefix" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ $NON-NLS-2$
        final URL soundFile = Platform.getBundle ( ele.getContributor ().getName () ).getEntry ( ele.getAttribute ( "soundFile" ) ); //$NON-NLS-1$
        final ParameterizedCommand ackAlarmsAvailableCommand = convertCommand ( ele.getChildren ( "ackAlarmsAvailableCommand" )[0] ); //$NON-NLS-1$
        final ParameterizedCommand alarmsAvailableCommand = convertCommand ( ele.getChildren ( "alarmsAvailableCommand" )[0] ); //$NON-NLS-1$
        return new AlarmNotifierConfiguration ( connectionId, prefix, soundFile, ackAlarmsAvailableCommand, alarmsAvailableCommand );
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to convert alarm notifier configuration: {}", ele ); //$NON-NLS-1$
        return null;
    }
}
 
Example 9
Project: neoscada   File: Activator.java   Source Code and License Vote up 5 votes
private void createConnections ()
{
    for ( final IConfigurationElement ele : Platform.getExtensionRegistry ().getConfigurationElementsFor ( "org.eclipse.scada.core.ui.connection.provider.connectionInstance" ) )
    {
        if ( !"connectionInstance".equals ( ele.getName () ) )
        {
            continue;
        }
        final String id = ele.getAttribute ( "servicePid" );
        final String uri = ele.getAttribute ( "uri" );
        final String autoReconnect = ele.getAttribute ( "autoReconnect" );
        createConnection ( id, uri, autoReconnect );
    }
}
 
Example 10
Project: n4js   File: SubGeneratorRegistry.java   Source Code and License Vote up 5 votes
/**
 * Read information from extensions defined in plugin.xml files
 */
private void initialize() {
	if (isInitialized) {
		throw new IllegalStateException("may invoke method initialize() only once");
	}
	isInitialized = true;

	final IExtensionRegistry registry = RegistryFactory.getRegistry();
	if (registry != null) {
		final IExtension[] extensions = registry.getExtensionPoint(SUBGENERATORS_EXTENSIONS_POINT_ID)
				.getExtensions();
		for (IExtension extension : extensions) {
			final IConfigurationElement[] configElems = extension.getConfigurationElements();
			for (IConfigurationElement elem : configElems) {
				try {
					String fileExtensions = elem.getAttribute(ATT_FILE_EXTENSIONS);
					List<String> fileExtensionList = Splitter.on(',').trimResults().omitEmptyStrings()
							.splitToList(fileExtensions);
					ISubGenerator generator = (ISubGenerator) elem
							.createExecutableExtension(ATT_SUB_GENERATOR_CLASS);
					for (String fileExtension : fileExtensionList) {
						register(generator, fileExtension);
					}

				} catch (Exception ex) {
					LOGGER.error(
							"Error while reading extensions for extension point "
									+ SUBGENERATORS_EXTENSIONS_POINT_ID,
							ex);
				}
			}
		}
	}
}
 
Example 11
Project: gemoc-studio-modeldebugging   File: MelangeHelper.java   Source Code and License Vote up 5 votes
/**
 * @param languageId
 * @return the URI of the given language or null if no such language exists in the registry
 */
public static String getLanguageURI(String languageId){
	IConfigurationElement[] melangeLanguages = Platform
			.getExtensionRegistry().getConfigurationElementsFor(
					"fr.inria.diverse.melange.language");
	for (IConfigurationElement lang : melangeLanguages) {
		if(lang.getAttribute("id").equals(languageId)){
			return lang.getAttribute("uri");
		}
	}
	return null;
}
 
Example 12
Project: gemoc-studio-modeldebugging   File: MelangeHelper.java   Source Code and License Vote up 5 votes
/**
 * Note: in some situations, the same uri can be declared for several languages ! (for example using external keyword)
 * this is usually a deployment issue
 * @param uri
 * @return the first language with the given URI or null if no such language exists in the registry
 */
public static String getLanguageNameForURI(String uri){
	IConfigurationElement[] melangeLanguages = Platform
			.getExtensionRegistry().getConfigurationElementsFor(
					"fr.inria.diverse.melange.language");
	for (IConfigurationElement lang : melangeLanguages) {
		if(lang.getAttribute("uri").equals(uri)){
			return lang.getAttribute("id");
		}
	}
	return null;
}
 
Example 13
Project: gemoc-studio-modeldebugging   File: MelangeHelper.java   Source Code and License Vote up 5 votes
public static List<String> getLanguageNamesForURI(String uri){
	List<String> languagesNames = new ArrayList<String>();
	IConfigurationElement[] melangeLanguages = Platform
			.getExtensionRegistry().getConfigurationElementsFor(
					"fr.inria.diverse.melange.language");
	for (IConfigurationElement lang : melangeLanguages) {
		if(lang.getAttribute("uri").equals(uri)){
			String id = lang.getAttribute("id");
			if(!languagesNames.contains(id)){
				languagesNames.add(id);
			}
		}
	}
	return languagesNames;
}
 
Example 14
Project: gemoc-studio-modeldebugging   File: MelangeHelper.java   Source Code and License Vote up 5 votes
/**
 * Return the  ModelType for 'language' or null if not found
 */
public static String getModelType(String language){
	IConfigurationElement[] melangeLanguages = Platform
			.getExtensionRegistry().getConfigurationElementsFor(
					"fr.inria.diverse.melange.language");
	for (IConfigurationElement lang : melangeLanguages) {
		if (lang.getAttribute("id").equals(language)) {
			return lang.getAttribute("modeltypeId");
		}
	}
	return null;
}
 
Example 15
Project: neoscada   File: TimeZoneInitializer.java   Source Code and License Vote up 5 votes
@Override
public void initializeDefaultPreferences ()
{
    String defaultTimeZone = TimeZone.getDefault ().getID ();
    for ( final IConfigurationElement ele : Platform.getExtensionRegistry ().getConfigurationElementsFor ( EXTP_CFG_ID ) )
    {
        if ( !Activator.TIME_ZONE_KEY.equals ( ele.getName () ) )
        {
            continue;
        }
        defaultTimeZone = ele.getAttribute ( "id" ); //$NON-NLS-1$
    }
    final Preferences node = DefaultScope.INSTANCE.getNode ( Activator.PLUGIN_ID );
    node.put ( Activator.TIME_ZONE_KEY, defaultTimeZone );
}
 
Example 16
Project: neoscada   File: StyleGeneratorInformation.java   Source Code and License Vote up 5 votes
public static IConfigurationElement getConfiguration ( final String generatorId )
{
    if ( generatorId == null )
    {
        return null;
    }

    for ( final IConfigurationElement ele : Platform.getExtensionRegistry ().getConfigurationElementsFor ( EXTP_STYLE_GENERATOR ) )
    {
        if ( !ELE_STYLE_GENERATOR.equals ( ele.getName () ) )
        {
            continue;
        }

        final String id = ele.getAttribute ( "id" ); //$NON-NLS-1$
        if ( id == null )
        {
            continue;
        }
        if ( id.equals ( generatorId ) )
        {
            return ele;
        }
    }

    return null;
}
 
Example 17
Project: knime-json-node-doc-generator   File: RepositoryManager.java   Source Code and License Vote up 5 votes
private void readMetanodes() {
	// iterate over the meta node config elements and create meta node templates
	IExtension[] metanodeExtensions = getExtensions(ID_META_NODE);
	for (IExtension mnExt : metanodeExtensions) {
		IConfigurationElement[] mnConfigElems = mnExt.getConfigurationElements();
		for (IConfigurationElement mnConfig : mnConfigElems) {

			try {
				MetaNodeTemplate metaNode = RepositoryFactory.createMetaNode(mnConfig);
				LOGGER.debug("Found meta node definition '" + metaNode.getID() + "': " + metaNode.getName());

				IContainerObject parentContainer = m_root.findContainer(metaNode.getCategoryPath());
				// If parent category is illegal, log an error and append the node to the
				// repository root.
				if (parentContainer == null) {
					LOGGER.warn("Invalid category-path for node contribution: '" + metaNode.getCategoryPath()
							+ "' - adding to root instead");
					m_root.addChild(metaNode);
				} else {
					// everything is fine, add the node to its parent category
					parentContainer.addChild(metaNode);
				}
			} catch (Throwable t) {
				String message = "MetaNode " + mnConfig.getAttribute("id") + "' from plugin '"
						+ mnConfig.getNamespaceIdentifier() + "' could not be created: " + t.getMessage();
				Bundle bundle = Platform.getBundle(mnConfig.getNamespaceIdentifier());

				if (bundle == null || bundle.getState() != Bundle.ACTIVE) {
					// if the plugin is null, the plugin could not be activated maybe due to a not
					// activateable plugin (plugin class cannot be found)
					message = message + " The corresponding plugin bundle could not be activated!";
				}

				LOGGER.error(message, t);
			}
		}
	}
}
 
Example 18
Project: knime-json-node-doc-generator   File: RepositoryManager.java   Source Code and License Vote up 4 votes
private void readCategories() {
	IExtension[] categoryExtensions = getExtensions(ID_CATEGORY);
	ArrayList<IConfigurationElement> allElements = new ArrayList<IConfigurationElement>();

	for (IExtension ext : categoryExtensions) {
		// iterate through the config elements and create 'Category' objects
		IConfigurationElement[] elements = ext.getConfigurationElements();
		allElements.addAll(Arrays.asList(elements));
	}

	removeDuplicatesFromCategories(allElements);

	// sort first by path-depth, so that everything is there in the
	// right order
	Collections.sort(allElements, (o1, o2) -> {
		String element1 = o1.getAttribute("path");
		String element2 = o2.getAttribute("path");
		if (element1 == element2) {
			return 0;
		} else if (element1 == null) {
			return -1;
		} else if (element2 == null) {
			return 1;
		} else if (element1.equals(element2)) {
			return 0;
		} else if ("/".equals(element1)) {
			return -1;
		} else if ("/".equals(element2)) {
			return 1;
		} else {
			int countSlashes1 = 0;
			for (int i1 = 0; i1 < element1.length(); i1++) {
				if (element1.charAt(i1) == '/') {
					countSlashes1++;
				}
			}

			int countSlashes2 = 0;
			for (int i2 = 0; i2 < element2.length(); i2++) {
				if (element2.charAt(i2) == '/') {
					countSlashes2++;
				}
			}
			return countSlashes1 - countSlashes2;
		}
	});

	for (IConfigurationElement e : allElements) {
		try {
			Category category = RepositoryFactory.createCategory(m_root, e);
			LOGGER.debug(
					"Found category extension '" + category.getID() + "' on path '" + category.getPath() + "'");
		} catch (Exception ex) {
			String message = "Category '" + e.getAttribute("level-id") + "' from plugin '"
					+ e.getDeclaringExtension().getNamespaceIdentifier() + "' could not be created in parent path '"
					+ e.getAttribute("path") + "'.";
			LOGGER.error(message, ex);
		}
	}
}
 
Example 19
Project: neoscada   File: Activator.java   Source Code and License Vote up 4 votes
private void createDiscoverers ()
{
    final WritableSet resultDiscoverers = new WritableSet ( DisplayRealm.getRealm ( getWorkbench ().getDisplay () ) );
    final WritableSet resultStores = new WritableSet ( DisplayRealm.getRealm ( getWorkbench ().getDisplay () ) );

    for ( final IConfigurationElement ele : Platform.getExtensionRegistry ().getConfigurationElementsFor ( EXTP_CONNECTON_DISCOVERER ) )
    {
        if ( ELE_DISCOVERER.equals ( ele.getName () ) )
        {
            final String id = ele.getAttribute ( "id" );
            String name = ele.getAttribute ( "name" );
            if ( name == null )
            {
                name = id;
            }

            final String icon = ele.getAttribute ( "icon" );
            ImageDescriptor imageDescriptor = null;
            if ( icon != null )
            {
                imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin ( ele.getContributor ().getName (), icon );
            }

            final String description = ele.getAttribute ( "description" );

            // create
            try
            {
                final ConnectionDiscovererBean bean = new ConnectionDiscovererBean ( id, name, description, imageDescriptor, (ConnectionDiscoverer)ele.createExecutableExtension ( "class" ) );
                resultDiscoverers.add ( bean );

                if ( bean.isStore () )
                {
                    resultStores.add ( bean );
                }
            }
            catch ( final CoreException e )
            {
                getLog ().log ( e.getStatus () );
            }
        }
    }

    this.discoverers = resultDiscoverers;
    this.stores = resultStores;
}
 
Example 20
Project: neoscada   File: ConnectionLoginFactory.java   Source Code and License Vote up 4 votes
protected Set<LoginConnection> loadConnections ( final String contextId )
{
    final Set<LoginConnection> result = new HashSet<LoginConnection> ();

    for ( final IConfigurationElement ele : Platform.getExtensionRegistry ().getConfigurationElementsFor ( "org.eclipse.scada.core.ui.connection.login.context" ) ) //$NON-NLS-1$
    {
        if ( !"context".equals ( ele.getName () ) ) //$NON-NLS-1$
        {
            continue;
        }

        if ( !contextId.equals ( ele.getAttribute ( "id" ) ) )
        {
            continue;
        }

        for ( final IConfigurationElement child : ele.getChildren ( "connection" ) )
        {
            final ConnectionInformation ci = ConnectionInformation.fromURI ( child.getAttribute ( "uri" ) );

            if ( ci == null )
            {
                throw new IllegalArgumentException ( String.format ( "Unable to parse connection uri: %s", child.getAttribute ( "uri" ) ) );
            }

            final Set<String> servicePids = new HashSet<String> ();

            final String modeString = child.getAttribute ( "mode" );
            final LoginConnection.Mode mode = modeString == null ? Mode.NORMAL : Mode.valueOf ( modeString );

            // load single service pid
            addServicePid ( servicePids, child.getAttribute ( "servicePid" ) );

            // load multi service pids
            for ( final IConfigurationElement registrationElement : child.getChildren ( "registration" ) )
            {
                addServicePid ( servicePids, registrationElement.getAttribute ( "servicePid" ) );
            }

            final Integer servicePriority;
            if ( child.getAttribute ( "servicePriority" ) != null )
            {
                servicePriority = Integer.parseInt ( child.getAttribute ( "servicePriority" ) );
            }
            else
            {
                servicePriority = null;
            }

            final Integer autoReconnectDelay;
            if ( child.getAttribute ( "autoReconnectDelay" ) != null )
            {
                autoReconnectDelay = Integer.parseInt ( child.getAttribute ( "autoReconnectDelay" ) );
            }
            else
            {
                autoReconnectDelay = null;
            }

            final boolean useCallbacks = Boolean.parseBoolean ( child.getAttribute ( "authUseCallbacks" ) );

            final LoginConnection lc = new LoginConnection ( ci, servicePids, autoReconnectDelay, servicePriority, mode, useCallbacks );
            result.add ( lc );
        }
    }

    return result;
}