Commit 523c1c65 authored by Jay Jay Billings's avatar Jay Jay Billings
Browse files

Updated the way the Client gets the IWidgetFactory.



I updated the Client so that it retrieves the IWidgetFactory using a
static interface method that accesses the Extension Registry. I have
removed several unused components too and made minor adjustments to
other files as required, such as removing files from build.properties. I
fixed a bug in the build that would miss test files that ended in
Test.java instead of Tester.java. I also added an existence test for
IWidgetFactory.getWidgetFactories().
Signed-off-by: default avatarJay Jay Billings <billingsjj@ornl.gov>
parent 7a636d09
/*******************************************************************************
* Copyright (c) 2012, 2014 UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation - Menghan Li
*******************************************************************************/
package org.eclipse.ice.client.test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ice.iclient.uiwidgets.IWidgetFactory;
import org.junit.Test;
/**
* This class tests the static interface operation
* IWidgetFactory.getWidgetFactories().
*
* @author Jay Jay Billings
*
*/
public class IWidgetFactoryTester {
/**
* Test for {@link org.eclipse.ice.client.uiwidgets.IWidgetFactory}.
*
* @throws CoreException
*/
@Test
public void test() throws CoreException {
// Simply get the factories from the registry and make sure they are
// actually there.
IWidgetFactory[] factories = IWidgetFactory.getIWidgetFactories();
assertNotNull(factories);
assertTrue(factories.length > 0);
return;
}
}
......@@ -54,6 +54,5 @@ Import-Package: com.jme3.app,
Export-Package: org.eclipse.ice.client.widgets,
org.eclipse.ice.client.widgets.analysis,
org.eclipse.ice.client.widgets.grid
Service-Component: OSGI-INF/eclipseWidgetsComponent.xml,
OSGI-INF/formEditorVizService.xml
Service-Component: OSGI-INF/formEditorVizService.xml
Bundle-Vendor: Oak Ridge National Laboratory
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="false" name="org.eclipse.ice.client.widgets">
<implementation class="org.eclipse.ice.client.widgets.EclipseUIWidgetFactory"/>
<reference bind="registerFormWidgetBuilder" cardinality="0..n" interface="org.eclipse.ice.client.widgets.IFormWidgetBuilder" name="IFormWidgetBuilder" policy="dynamic"/>
<service>
<provide interface="org.eclipse.ice.iclient.uiwidgets.IWidgetFactory"/>
</service>
</scr:component>
......@@ -9,12 +9,7 @@ bin.includes = META-INF/,\
icons/,\
OSGI-INF/formEditorVizService.xml,\
plugin_customization.ini
src.includes = OSGI-INF/,\
META-INF/,\
build.properties,\
plugin.xml,\
pom.xml,\
src/,\
src.includes = pom.xml,\
icons/
source.. = src/
additional.bundles = org.eclipse.core.resources,\
......
......@@ -359,7 +359,7 @@
<extension
id="eclipsewidgetfactory"
name="Eclipse UI Widget Factory"
point="org.eclipse.ice.client.iwidgetfactory">
point="org.eclipse.ice.client.IWidgetFactory">
<iwidgetfactory
class="org.eclipse.ice.client.widgets.EclipseUIWidgetFactory">
</iwidgetfactory>
......
......@@ -36,6 +36,7 @@ import org.slf4j.LoggerFactory;
* @author Jay Jay Billings
*/
public interface IFormWidgetBuilder {
/**
* <p>
* This operation returns the name of the target Form that the Builder will
......
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" enabled="true" immediate="false" name="org.eclipse.ice.client">
<implementation class="org.eclipse.ice.client.internal.Client"/>
<reference cardinality="1..1" interface="org.eclipse.ice.iclient.uiwidgets.IWidgetFactory" name="IWidgetFactory" policy="static"/>
</scr:component>
......@@ -2,7 +2,6 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
OSGI-INF/,\
build.properties,\
pom.xml,\
schema/,\
......
......@@ -2,7 +2,7 @@
<?eclipse version="3.4"?>
<plugin>
<extension-point id="clientInstance" name="ICE Client" schema="schema/clientInstance.exsd"/>
<extension-point id="iwidgetfactory" name="Widget Factory" schema="schema/iwidgetfactory.exsd"/>
<extension-point id="IWidgetFactory" name="Widget Factory" schema="schema/iwidgetfactory.exsd"/>
<extension-point id="updateEventListener" name="IUpdateEventListener" schema="schema/updateEventListener.exsd"/>
<extension-point id="processEventListener" name="IProcessEventListener" schema="schema/processEventListener.exsd"/>
<extension-point id="simpleResourceProvider" name="ISimpleResourceProvider" schema="schema/simpleResourceProvider.exsd"/>
......
......@@ -37,7 +37,6 @@ import org.eclipse.ice.iclient.uiwidgets.ITextEditor;
import org.eclipse.ice.iclient.uiwidgets.IUpdateEventListener;
import org.eclipse.ice.iclient.uiwidgets.IWidgetClosedListener;
import org.eclipse.ice.iclient.uiwidgets.IWidgetFactory;
import org.eclipse.ui.PlatformUI;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
......@@ -60,8 +59,9 @@ import org.slf4j.LoggerFactory;
*
* @author Jay Jay Billings
*/
public class Client implements IUpdateEventListener, IProcessEventListener, ISimpleResourceProvider,
IWidgetClosedListener, IClient, BundleActivator {
public class Client implements IUpdateEventListener, IProcessEventListener,
ISimpleResourceProvider, IWidgetClosedListener, IClient,
BundleActivator {
/**
* Logger for handling event messages and other information.
......@@ -165,13 +165,15 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
// posted to the IFormWidget based on the status of the process.
statusMessageMap.put(FormStatus.Processed, "Done!");
statusMessageMap.put(FormStatus.Processing, "Processing Form...");
statusMessageMap.put(FormStatus.InfoError, "The Form contains an error" + " and cannot be processed.");
statusMessageMap.put(FormStatus.InfoError,
"The Form contains an error" + " and cannot be processed.");
statusMessageMap.put(FormStatus.ReadyToProcess, "Ready to process.");
statusMessageMap.put(FormStatus.NeedsInfo,
"The Form requires additional information before " + "it can be processed.");
"The Form requires additional information before "
+ "it can be processed.");
statusMessageMap.put(FormStatus.InReview, "In review...");
statusMessageMap.put(FormStatus.Unacceptable,
"This Form will not be " + "processed or updated. It should be considered read-only.");
statusMessageMap.put(FormStatus.Unacceptable, "This Form will not be "
+ "processed or updated. It should be considered read-only.");
// Set the reference to this in the Singleton for the widget classes to
// retrieve as needed.
......@@ -202,11 +204,10 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
logger.error("Unable to access core!.");
}
// Get the widgets factory service by using the Workbench. This is a
// good way to do it that prevents the ResourcesPlugin from being called
// prematurely.
IWidgetFactory factory = PlatformUI.getWorkbench().getService(IWidgetFactory.class);
setUIWidgetFactory(factory);
// Get the widgets factory service by using the static inferace method
// and directly registering it. At the moment we have only a single
// factory, so we will grab the 0-th entry.
setUIWidgetFactory(IWidgetFactory.getIWidgetFactories()[0]);
// I realize how hilarious it is to use two different mechanisms for
// acquiring services here. FIXME! This is just testing for now.
......@@ -288,7 +289,8 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
processorThread.start();
} else {
// Otherwise notify the use that the Item is invalid
throwSimpleError("IClient Message: " + "Item has no parent widget in this client.");
throwSimpleError("IClient Message: "
+ "Item has no parent widget in this client.");
}
}
......@@ -360,7 +362,8 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
if (itemId > 0) {// FIXME Status check!
loadItem(itemId);
} else if (itemId <= 0) {
throwSimpleError("Unable to load Item " + itemType + " after creating it.");
throwSimpleError(
"Unable to load Item " + itemType + " after creating it.");
}
}
......@@ -377,7 +380,8 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
if (iWidgetFactory != null) {
logger.info("IClient Message: Widget Factory set!");
} else {
logger.info("IClient Message: " + "Widget Factory set, but is null.");
logger.info(
"IClient Message: " + "Widget Factory set, but is null.");
}
return;
}
......@@ -406,19 +410,23 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
formWidget.display();
// Set the initial status of the Form
formStatus = getCore().getItemStatus(itemId);
formWidget.updateStatus(statusMessageMap.get(iCore.getItemStatus(itemId)));
formWidget.updateStatus(
statusMessageMap.get(iCore.getItemStatus(itemId)));
// If the FormStatus signifies that the Form is absolutely
// unacceptable, then the user should be warned.
if (formStatus.equals(FormStatus.Unacceptable)) {
formWidget.disable(true);
throwSimpleError("This Form has been set to a read-only mode by "
+ "ICE. Please be advised that it can not be upated" + " or processed.");
throwSimpleError(
"This Form has been set to a read-only mode by "
+ "ICE. Please be advised that it can not be upated"
+ " or processed.");
}
// Register for updates
formWidget.registerUpdateListener(this);
formWidget.registerProcessListener(this);
formWidget.registerResourceProvider(this);
logger.info("IClient Message: Loaded Item " + itemId + ", " + form.getName());
logger.info("IClient Message: Loaded Item " + itemId + ", "
+ form.getName());
// Store the widget in the table of FormWidgets
formWidgetTable.put(itemId, formWidget);
} else {
......@@ -504,12 +512,14 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
}
// Process the item
if (itemForm != null) {
logger.info("IClient Message: Processing Item " + itemId + ", " + itemForm.getName());
logger.info("IClient Message: Processing Item " + itemId + ", "
+ itemForm.getName());
processItem(formWidgetTable.get(itemId), actionName);
}
} else if (itemId < 0 || itemForm == null) {
// Otherwise notify the use that the Item is invalid
throwSimpleError("The Item id is invalid. " + "Please double check it and try again "
throwSimpleError("The Item id is invalid. "
+ "Please double check it and try again "
+ "or notify your systems administrator.");
}
return;
......@@ -592,22 +602,26 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
// Update the Form if needed, skip FormStatus.InReview for now.
// FIXME! - need FormStatus.InReview
if (!status.equals(FormStatus.InfoError) && !status.equals(FormStatus.Unacceptable)) {
if (!status.equals(FormStatus.InfoError)
&& !status.equals(FormStatus.Unacceptable)) {
form = getCore().getItem(formId);
// Update the status of the Item update
if (formWidgetTable.containsKey(form.getItemID())) {
String statusMessage = statusMessageMap.get(status);
formWidgetTable.get(form.getItemID()).updateStatus(statusMessage);
formWidgetTable.get(form.getItemID())
.updateStatus(statusMessage);
}
} else {
// Notify the user that there is some invalid information in the
// Form
throwSimpleError("Form contains invalid information. " + "Please review it for completeness and "
throwSimpleError("Form contains invalid information. "
+ "Please review it for completeness and "
+ "accuracy and resubmit.");
}
} else {
// Otherwise let the user know
throwSimpleError("Fatal Error: " + "Form returned to Client can not be null!");
throwSimpleError("Fatal Error: "
+ "Form returned to Client can not be null!");
}
return;
......@@ -662,7 +676,8 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
// Display the widget
textEditor.display();
} else {
throwSimpleError("The resource that you asked to load does not " + "exist or is erroneously linked.");
throwSimpleError("The resource that you asked to load does not "
+ "exist or is erroneously linked.");
}
}
......@@ -706,7 +721,9 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
/*
* (non-Javadoc)
* @see org.eclipse.ice.iclient.IClient#importFile(java.net.URI, org.eclipse.core.resources.IProject)
*
* @see org.eclipse.ice.iclient.IClient#importFile(java.net.URI,
* org.eclipse.core.resources.IProject)
*/
@Override
public void importFile(URI file, IProject project) {
......@@ -717,7 +734,9 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
/*
* (non-Javadoc)
* @see org.eclipse.ice.iclient.IClient#importFile(java.net.URI, java.lang.String)
*
* @see org.eclipse.ice.iclient.IClient#importFile(java.net.URI,
* java.lang.String)
*/
@Override
public void importFile(URI file, String projectName) {
......@@ -741,17 +760,22 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
/*
* (non-Javadoc)
* @see org.eclipse.ice.iclient.IClient#importFileAsItem(java.net.URI, java.lang.String, org.eclipse.core.resources.IProject)
*
* @see org.eclipse.ice.iclient.IClient#importFileAsItem(java.net.URI,
* java.lang.String, org.eclipse.core.resources.IProject)
*/
@Override
public int importFileAsItem(URI file, String itemType, IProject project) {
// Pass the call on to the core
return Integer.valueOf(getCore().importFileAsItem(file, itemType, project));
return Integer
.valueOf(getCore().importFileAsItem(file, itemType, project));
}
/*
* (non-Javadoc)
* @see org.eclipse.ice.iclient.IClient#importFileAsItem(org.eclipse.core.resources.IFile, java.lang.String)
*
* @see org.eclipse.ice.iclient.IClient#importFileAsItem(org.eclipse.core.
* resources.IFile, java.lang.String)
*/
@Override
public int importFileAsItem(IFile file, String itemType) {
......@@ -761,16 +785,20 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
/*
* (non-Javadoc)
* @see org.eclipse.ice.iclient.IClient#importFileAsItem(java.net.URI, java.lang.String, java.lang.String)
*
* @see org.eclipse.ice.iclient.IClient#importFileAsItem(java.net.URI,
* java.lang.String, java.lang.String)
*/
@Override
public int importFileAsItem(URI file, String itemType, String projectName) {
// Pass the call on to the core
return Integer.valueOf(getCore().importFileAsItem(file, itemType, projectName));
return Integer.valueOf(
getCore().importFileAsItem(file, itemType, projectName));
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.iclient.IClient#renameItem(int, java.lang.String)
*/
@Override
......@@ -780,7 +808,10 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
/*
* (non-Javadoc)
* @see org.eclipse.ice.iclient.IClient#setFormWidget(org.eclipse.ice.iclient.uiwidgets.IFormWidget)
*
* @see
* org.eclipse.ice.iclient.IClient#setFormWidget(org.eclipse.ice.iclient.
* uiwidgets.IFormWidget)
*/
@Override
public void addFormWidget(IFormWidget widget) {
......@@ -790,10 +821,11 @@ public class Client implements IUpdateEventListener, IProcessEventListener, ISim
}
/**
* This operation returns the IFormWidget corresponding to
* the given Item Id.
* This operation returns the IFormWidget corresponding to the given Item
* Id.
*
* @param itemId The id of the Item whose IFormWidget has been requested
* @param itemId
* The id of the Item whose IFormWidget has been requested
* @return formWidget
*/
public IFormWidget getFormWidget(int itemId) {
......
......@@ -12,6 +12,13 @@
*******************************************************************************/
package org.eclipse.ice.iclient.uiwidgets;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* for implementations of IClient. It is implemented separately from the client
* to separate the code needed for drawing to the screen from the code needed to
......@@ -21,6 +28,43 @@ package org.eclipse.ice.iclient.uiwidgets;
* @author Jay Jay Billings
*/
public interface IWidgetFactory {
/**
* This operation retrieves all of the IWidgetFactories from the
* ExtensionRegistry.
*
* @return The array of IWidgetFactories that were found in the registry.
* @throws CoreException
* This exception is thrown if an extension cannot be loaded.
*/
public static IWidgetFactory[] getIWidgetFactories() throws CoreException {
/**
* Logger for handling event messages and other information.
*/
Logger logger = LoggerFactory.getLogger(IWidgetFactory.class);
IWidgetFactory[] builders = null;
String id = "org.eclipse.ice.client.IWidgetFactory";
IExtensionPoint point = Platform.getExtensionRegistry()
.getExtensionPoint(id);
// If the point is available, create all the builders and load them into
// the array.
if (point != null) {
IConfigurationElement[] elements = point.getConfigurationElements();
builders = new IWidgetFactory[elements.length];
for (int i = 0; i < elements.length; i++) {
builders[i] = (IWidgetFactory) elements[i]
.createExecutableExtension("class");
}
} else {
logger.error("Extension Point " + id + "does not exist");
}
return builders;
}
/**
* This operation returns an IFormWidget that is rendered by the underlying
* graphics package.
......@@ -30,8 +74,7 @@ public interface IWidgetFactory {
* This option can be used by classes that realize the
* IWidgetFactory interface for further customization or special
* checks, but it is not required (and may be null).
* @return
* An IFormWidget
* @return An IFormWidget
*/
public IFormWidget getFormWidget(String formName);
......@@ -39,8 +82,7 @@ public interface IWidgetFactory {
* This operation returns an IErrorBox that is rendered by the underlying
* graphics package.
*
* @return
* The IErrorBox
* @return The IErrorBox
*/
public IErrorBox getErrorBox();
......@@ -48,16 +90,14 @@ public interface IWidgetFactory {
* This operation returns an ITextEditor that is rendered by the underlying
* graphics package.
*
* @return
* The ITextEditor
* @return The ITextEditor
*/
public ITextEditor getTextEditor();
/**
* This operation returns an IExtraInfoWidget.
*
* @return
* The IExtraInfoWidget.
* @return The IExtraInfoWidget.
*/
public IExtraInfoWidget getExtraInfoWidget();
......@@ -65,8 +105,7 @@ public interface IWidgetFactory {
* This operation returns a widget that can be used to stream text to a
* client.
*
* @return
* The IStreamingTextWidget that can post messages to be viewed by a
* @return The IStreamingTextWidget that can post messages to be viewed by a
* client.
*/
public IStreamingTextWidget getStreamingTextWidget();
......
......@@ -174,6 +174,7 @@
<configuration>
<includes>
<include>**/*Tester.class</include>
<include>*/*Test.class</include>
</includes>
<argLine>${ui.test.vmargs}</argLine>
</configuration>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment