Issue #1462 Created new BundleLoader and BundleProductLoader to consolidate code for loading Bundles to the screen asynchronously.
Amend: Switched to proper ticket Change-Id: Iacfc73f574aef64bba43323818ea3484b1f5a9b9 Former-commit-id:aa88b83859
[formerly9aac1d2871
[formerly02e7c79de9
] [formerlyaa88b83859
[formerly 86aa1a7febbd1b8671e546c2b9eaca10f82860a4]]] Former-commit-id:9aac1d2871
[formerly02e7c79de9
] Former-commit-id:9aac1d2871
Former-commit-id:f51398595e
This commit is contained in:
parent
5697b53376
commit
438316f63e
14 changed files with 585 additions and 567 deletions
|
@ -578,6 +578,8 @@ public abstract class AbstractDescriptor extends ResourceGroup implements
|
|||
}
|
||||
}
|
||||
synchronized (timeManager) {
|
||||
DataTime[] oldTimes = timeManager.frames;
|
||||
int oldIdx = this.frameIndex;
|
||||
if (info.setFrames) {
|
||||
if (info.frameTimes != null) {
|
||||
DataTime[] newTimes = Arrays.copyOf(info.frameTimes,
|
||||
|
@ -594,6 +596,14 @@ public abstract class AbstractDescriptor extends ResourceGroup implements
|
|||
timeMatchingMap = new ConcurrentHashMap<AbstractVizResource<?, ?>, DataTime[]>(
|
||||
info.timeMap);
|
||||
}
|
||||
FramesInfo currInfo = getFramesInfo();
|
||||
FramesInfo oldInfo = new FramesInfo(oldTimes, oldIdx);
|
||||
DataTime oldTime = oldInfo.getCurrentFrame();
|
||||
DataTime currTime = currInfo.getCurrentFrame();
|
||||
if ((oldTime != null && oldTime.equals(currTime) == false)
|
||||
|| (currTime != null && currTime.equals(oldTime) == false)) {
|
||||
notifyFrameChanged(oldTime, currTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -624,20 +634,8 @@ public abstract class AbstractDescriptor extends ResourceGroup implements
|
|||
* @param frame
|
||||
*/
|
||||
private void setFrameInternal(int frame) {
|
||||
FramesInfo currInfo = getFramesInfo();
|
||||
int frameIndex = currInfo.frameIndex;
|
||||
if (frame != frameIndex) {
|
||||
DataTime[] times = currInfo.frameTimes;
|
||||
DataTime oldTime = null, newTime = null;
|
||||
// Get the old and new time
|
||||
if (times != null && frameIndex >= 0 && frameIndex < times.length) {
|
||||
oldTime = times[frameIndex];
|
||||
}
|
||||
if (times != null && frame >= 0 && frame < times.length) {
|
||||
newTime = times[frame];
|
||||
}
|
||||
this.frameIndex = frame;
|
||||
notifyFrameChanged(oldTime, newTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -828,19 +828,23 @@ public class D2DTimeMatcher extends AbstractTimeMatcher {
|
|||
*/
|
||||
public void changeTimeMatchBasis(AbstractVizResource<?, ?> resource) {
|
||||
if (timeMatchBasis != resource) {
|
||||
TimeMatchingConfiguration config = getConfiguration(resource
|
||||
.getLoadProperties());
|
||||
TimeCache timeCache = getTimeCache(resource);
|
||||
if (timeMatchBasis != null) {
|
||||
TimeMatchingConfiguration config = getConfiguration(timeMatchBasis
|
||||
.getLoadProperties());
|
||||
config.setTimeMatchBasis(false);
|
||||
TimeCache timeCache = getTimeCache(timeMatchBasis);
|
||||
timeCache.setTimes(null, null);
|
||||
timeMatchBasis
|
||||
.unregisterListener(timeMatchBasisDisposeListener);
|
||||
}
|
||||
|
||||
timeMatchBasis = resource;
|
||||
|
||||
if (timeMatchBasis != null) {
|
||||
TimeMatchingConfiguration config = getConfiguration(timeMatchBasis
|
||||
.getLoadProperties());
|
||||
config.setTimeMatchBasis(true);
|
||||
TimeCache timeCache = getTimeCache(timeMatchBasis);
|
||||
timeCache.setTimes(null, null);
|
||||
timeMatchBasis.registerListener(timeMatchBasisDisposeListener);
|
||||
}
|
||||
|
|
|
@ -47,8 +47,6 @@ import com.raytheon.viz.ui.HistoryList;
|
|||
import com.raytheon.viz.ui.HistoryList.IHistoryListener;
|
||||
import com.raytheon.viz.ui.UiPlugin;
|
||||
import com.raytheon.viz.ui.UiUtil;
|
||||
import com.raytheon.viz.ui.actions.LoadSerializedXml;
|
||||
import com.raytheon.viz.ui.actions.SaveBundle;
|
||||
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
|
||||
import com.raytheon.viz.ui.dialogs.ICloseCallback;
|
||||
import com.raytheon.viz.ui.editor.AbstractEditor;
|
||||
|
@ -331,28 +329,22 @@ public class HistoryListDlg extends CaveSWTDialog {
|
|||
}
|
||||
|
||||
private void loadAlterBundle(Bundle b) {
|
||||
try {
|
||||
String editorName = null;
|
||||
String editorName = null;
|
||||
|
||||
if (b.getDisplays().length > 0) {
|
||||
editorName = DescriptorMap.getEditorId(b.getDisplays()[0]
|
||||
.getDescriptor().getClass().getName());
|
||||
}
|
||||
|
||||
AbstractEditor editor = UiUtil.createOrOpenEditor(editorName,
|
||||
b.getDisplays());
|
||||
|
||||
for (IDisplayPane pane : editor.getDisplayPanes()) {
|
||||
pane.getRenderableDisplay().getDescriptor().getResourceList()
|
||||
.clear();
|
||||
}
|
||||
|
||||
LoadSerializedXml.loadTo(editor, b);
|
||||
HistoryList.getInstance().addBundle(b);
|
||||
} catch (VizException e) {
|
||||
final String err = "Error loading bundle";
|
||||
statusHandler.handle(Priority.PROBLEM, err, e);
|
||||
if (b.getDisplays().length > 0) {
|
||||
editorName = DescriptorMap.getEditorId(b.getDisplays()[0]
|
||||
.getDescriptor().getClass().getName());
|
||||
}
|
||||
|
||||
AbstractEditor editor = UiUtil.createOrOpenEditor(editorName,
|
||||
b.getDisplays());
|
||||
|
||||
for (IDisplayPane pane : editor.getDisplayPanes()) {
|
||||
pane.getRenderableDisplay().getDescriptor().getResourceList()
|
||||
.clear();
|
||||
}
|
||||
|
||||
ProcedureLoadJob.getInstance().enqueue(b, editor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -378,10 +370,7 @@ public class HistoryListDlg extends CaveSWTDialog {
|
|||
return;
|
||||
}
|
||||
|
||||
LoadSerializedXml.loadTo(editor, b);
|
||||
Bundle currBundle = SaveBundle.extractCurrentBundle();
|
||||
|
||||
HistoryList.getInstance().refreshLatestBundle(currBundle);
|
||||
ProcedureLoadJob.getInstance().enqueue(b, editor);
|
||||
} catch (VizException e) {
|
||||
statusHandler.handle(Priority.SIGNIFICANT, "Error loading bundle",
|
||||
e);
|
||||
|
|
|
@ -28,12 +28,8 @@ import org.eclipse.core.runtime.IStatus;
|
|||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.raytheon.uf.viz.core.procedures.Bundle;
|
||||
import com.raytheon.viz.ui.actions.LoadSerializedXml;
|
||||
import com.raytheon.viz.ui.BundleLoader;
|
||||
import com.raytheon.viz.ui.editor.AbstractEditor;
|
||||
|
||||
/**
|
||||
|
@ -54,8 +50,6 @@ import com.raytheon.viz.ui.editor.AbstractEditor;
|
|||
*/
|
||||
|
||||
public class ProcedureLoadJob {
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(ProcedureLoadJob.class);
|
||||
|
||||
private static final ProcedureLoadJob instance = new ProcedureLoadJob();
|
||||
|
||||
|
@ -79,12 +73,7 @@ public class ProcedureLoadJob {
|
|||
AbstractEditor editor = entry.getKey();
|
||||
Bundle b = entry.getValue();
|
||||
|
||||
try {
|
||||
LoadSerializedXml.loadTo(editor, b);
|
||||
} catch (VizException e) {
|
||||
statusHandler.handle(Priority.PROBLEM,
|
||||
"Error loading bundle", e);
|
||||
}
|
||||
new BundleLoader(editor, b).run();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,10 +63,10 @@ import com.raytheon.uf.viz.d2d.core.legend.D2DLegendResource.LegendMode;
|
|||
import com.raytheon.uf.viz.d2d.core.map.MapScales;
|
||||
import com.raytheon.uf.viz.d2d.core.map.MapScales.MapScale;
|
||||
import com.raytheon.uf.viz.d2d.core.map.MapScales.PartId;
|
||||
import com.raytheon.viz.ui.BundleLoader;
|
||||
import com.raytheon.viz.ui.EditorUtil;
|
||||
import com.raytheon.viz.ui.HistoryList;
|
||||
import com.raytheon.viz.ui.UiUtil;
|
||||
import com.raytheon.viz.ui.actions.LoadSerializedXml;
|
||||
import com.raytheon.viz.ui.color.BackgroundColor;
|
||||
import com.raytheon.viz.ui.color.IBackgroundColorChangedListener;
|
||||
import com.raytheon.viz.ui.editor.AbstractEditor;
|
||||
|
@ -207,12 +207,7 @@ public class SideView extends ViewPart implements IMultiPaneEditor,
|
|||
}
|
||||
|
||||
if (bundleToLoad != null) {
|
||||
try {
|
||||
LoadSerializedXml.loadTo(this, bundleToLoad);
|
||||
} catch (VizException e) {
|
||||
statusHandler.handle(Priority.PROBLEM,
|
||||
"Error loading bundle view", e);
|
||||
}
|
||||
new BundleLoader(this, bundleToLoad).run();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -604,12 +599,12 @@ public class SideView extends ViewPart implements IMultiPaneEditor,
|
|||
if (editableResource != null) {
|
||||
EditableManager.makeEditable(editableResource, false);
|
||||
}
|
||||
|
||||
this.editableResource = editableResource;
|
||||
|
||||
this.editableResource = editableResource;
|
||||
if (this.editableResource != null) {
|
||||
EditableManager.makeEditable(this.editableResource, true);
|
||||
}
|
||||
|
||||
|
||||
theEditor.getBackgroundColor().setColor(BGColorMode.EDITOR,
|
||||
myRenderables[0].getBackgroundColor());
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ import com.raytheon.uf.viz.core.rsc.capabilities.ColorableCapability;
|
|||
import com.raytheon.uf.viz.core.rsc.capabilities.EditableCapability;
|
||||
import com.raytheon.uf.viz.core.rsc.capabilities.MagnificationCapability;
|
||||
import com.raytheon.uf.viz.npp.crimss.CrimssNSharpResourceData;
|
||||
import com.raytheon.viz.ui.MenuLoader;
|
||||
import com.raytheon.viz.ui.BundleProductLoader;
|
||||
import com.raytheon.viz.ui.UiUtil;
|
||||
import com.raytheon.viz.ui.editor.AbstractEditor;
|
||||
import com.raytheon.viz.ui.input.EditableManager;
|
||||
|
@ -218,7 +218,7 @@ public class CrimssMapResource extends
|
|||
display.cloneDisplay());
|
||||
Bundle b = new Bundle();
|
||||
b.setDisplays(new AbstractRenderableDisplay[] { display });
|
||||
Job j = new MenuLoader(b, editor);
|
||||
Job j = new BundleProductLoader(editor, b);
|
||||
j.schedule();
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ import com.raytheon.uf.viz.core.rsc.ResourceProperties;
|
|||
import com.raytheon.uf.viz.core.rsc.ResourceType;
|
||||
import com.raytheon.uf.viz.productbrowser.ProductBrowserPreference.PreferenceType;
|
||||
import com.raytheon.viz.ui.EditorUtil;
|
||||
import com.raytheon.viz.ui.MenuLoader;
|
||||
import com.raytheon.viz.ui.BundleProductLoader;
|
||||
import com.raytheon.viz.ui.VizWorkbenchManager;
|
||||
import com.raytheon.viz.ui.editor.AbstractEditor;
|
||||
import com.raytheon.viz.ui.perspectives.AbstractVizPerspectiveManager;
|
||||
|
@ -216,8 +216,7 @@ public abstract class AbstractRequestableProductBrowserDataDefinition<T extends
|
|||
display.getDescriptor().getResourceList().add(pair);
|
||||
Bundle b = new Bundle();
|
||||
b.setDisplays(new AbstractRenderableDisplay[] { display });
|
||||
new MenuLoader(b, (AbstractEditor) EditorUtil.getActiveEditor())
|
||||
.schedule();
|
||||
new BundleProductLoader(EditorUtil.getActiveVizContainer(), b).schedule();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,8 +56,11 @@ import com.raytheon.uf.viz.core.procedures.BundleUtil.BundleDataItem;
|
|||
import com.raytheon.uf.viz.core.rsc.URICatalog;
|
||||
import com.raytheon.uf.viz.core.rsc.URICatalog.IURIRefreshCallback;
|
||||
import com.raytheon.uf.viz.ui.menus.xml.BundleMenuContribution;
|
||||
import com.raytheon.viz.ui.MenuLoader;
|
||||
import com.raytheon.viz.ui.actions.LoadSerializedXml;
|
||||
import com.raytheon.viz.ui.BundleLoader;
|
||||
import com.raytheon.viz.ui.BundleLoader.BundleInfoType;
|
||||
import com.raytheon.viz.ui.BundleProductLoader;
|
||||
import com.raytheon.viz.ui.UiUtil;
|
||||
import com.raytheon.viz.ui.editor.AbstractEditor;
|
||||
|
||||
/**
|
||||
* Provides an Eclipse menu contribution that loads a bundle, and is decorated
|
||||
|
@ -345,15 +348,19 @@ public class BundleContributionItem extends ContributionItem {
|
|||
|
||||
private void loadBundle(Event event) {
|
||||
try {
|
||||
Bundle bundle = BundleLoader.getBundle(
|
||||
this.menuContribution.xml.bundleFile, substitutions,
|
||||
BundleInfoType.FILE_LOCATION);
|
||||
AbstractEditor editor = UiUtil.createOrOpenEditor(
|
||||
this.menuContribution.xml.editorType, bundle.getDisplays());
|
||||
BundleLoader loader;
|
||||
if (this.menuContribution.xml.fullBundleLoad == null
|
||||
|| this.menuContribution.xml.fullBundleLoad == false) {
|
||||
MenuLoader.loadProduct(this.menuContribution.xml.editorType,
|
||||
this.menuContribution.xml.bundleFile, substitutions);
|
||||
loader = new BundleProductLoader(editor, bundle);
|
||||
} else {
|
||||
LoadSerializedXml.loadTo(PathManagerFactory.getPathManager()
|
||||
.getStaticFile(this.menuContribution.xml.bundleFile),
|
||||
substitutions);
|
||||
loader = new BundleLoader(editor, bundle);
|
||||
}
|
||||
loader.schedule();
|
||||
|
||||
if (this.menuContribution.xml.command != null) {
|
||||
ICommandService service = (ICommandService) PlatformUI
|
||||
|
|
|
@ -0,0 +1,346 @@
|
|||
package com.raytheon.viz.ui;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.viz.core.AbstractTimeMatcher;
|
||||
import com.raytheon.uf.viz.core.IDisplayPane;
|
||||
import com.raytheon.uf.viz.core.IDisplayPaneContainer;
|
||||
import com.raytheon.uf.viz.core.VizApp;
|
||||
import com.raytheon.uf.viz.core.drawables.AbstractRenderableDisplay;
|
||||
import com.raytheon.uf.viz.core.drawables.IDescriptor;
|
||||
import com.raytheon.uf.viz.core.drawables.IRenderableDisplay;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.raytheon.uf.viz.core.globals.VizGlobalsManager;
|
||||
import com.raytheon.uf.viz.core.procedures.Bundle;
|
||||
import com.raytheon.viz.ui.editor.IMultiPaneEditor;
|
||||
|
||||
/**
|
||||
*
|
||||
* Loads a bundle to a container. Replaces contents of bundle on the container
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jan 8, 2013 mschenke Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author mschenke
|
||||
* @version 1.0
|
||||
*/
|
||||
public class BundleLoader extends Job {
|
||||
|
||||
protected static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(BundleLoader.class);
|
||||
|
||||
public static enum BundleInfoType {
|
||||
FILE_LOCATION, XML
|
||||
}
|
||||
|
||||
protected static class LoadItem {
|
||||
|
||||
public final IDisplayPane loadTo;
|
||||
|
||||
public final IRenderableDisplay loadFrom;
|
||||
|
||||
public LoadItem(IDisplayPane loadTo, IRenderableDisplay loadFrom) {
|
||||
this.loadTo = loadTo;
|
||||
this.loadFrom = loadFrom;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class InstantiationTask implements Runnable {
|
||||
|
||||
private LoadItem loadItem;
|
||||
|
||||
private InstantiationTask(LoadItem loadItem) {
|
||||
this.loadItem = loadItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
IDisplayPane loadTo = loadItem.loadTo;
|
||||
IRenderableDisplay loadFrom = loadItem.loadFrom;
|
||||
if (loadTo.getDescriptor() != loadFrom.getDescriptor()) {
|
||||
load(loadTo, loadFrom);
|
||||
}
|
||||
loadTo.getDescriptor().getResourceList()
|
||||
.instantiateResources(loadTo.getDescriptor(), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected IDisplayPaneContainer container;
|
||||
|
||||
private Bundle bundle;
|
||||
|
||||
public BundleLoader(IDisplayPaneContainer container, Bundle bundle) {
|
||||
this("Bundle Loader", container, bundle);
|
||||
}
|
||||
|
||||
protected BundleLoader(String name, IDisplayPaneContainer container,
|
||||
Bundle bundle) {
|
||||
super(name);
|
||||
this.container = container;
|
||||
this.bundle = bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the loading synchronously.
|
||||
*/
|
||||
public final void run() {
|
||||
run(new NullProgressMonitor());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final IStatus run(IProgressMonitor monitor) {
|
||||
long t0 = System.currentTimeMillis();
|
||||
try {
|
||||
loadBundleToContainer(container, bundle);
|
||||
if (bundle.getLoopProperties() != null) {
|
||||
container.setLoopProperties(bundle.getLoopProperties());
|
||||
}
|
||||
|
||||
/** refresh the editor */
|
||||
container.refresh();
|
||||
|
||||
if (container instanceof IEditorPart) {
|
||||
/** update the history list */
|
||||
HistoryList.getInstance().refreshLatestBundle(
|
||||
HistoryList.prepareHistoryEntry(container));
|
||||
}
|
||||
|
||||
if (container instanceof IEditorPart) {
|
||||
VizApp.runAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
VizGlobalsManager.getCurrentInstance().updateUI(
|
||||
container);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (VizException e) {
|
||||
return new Status(IStatus.ERROR, UiPlugin.PLUGIN_ID,
|
||||
"Error loading bundle", e);
|
||||
}
|
||||
long t2 = System.currentTimeMillis();
|
||||
System.out.println("Total bundle retrieval: " + (t2 - t0));
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a {@link Bundle} onto an {@link IDisplayPaneContainer}
|
||||
*
|
||||
* @param container
|
||||
* @param bundle
|
||||
* @throws VizException
|
||||
*/
|
||||
private final void loadBundleToContainer(IDisplayPaneContainer container,
|
||||
Bundle bundle) throws VizException {
|
||||
LoadItem[] items = getLoadItems(container, bundle);
|
||||
int numItems = items.length;
|
||||
|
||||
if (numItems > 0) {
|
||||
Thread[] threads = new Thread[numItems - 1];
|
||||
for (int i = 0; i < numItems; ++i) {
|
||||
Thread t = new Thread(new InstantiationTask(items[i]));
|
||||
if (i == 0) {
|
||||
IRenderableDisplay loadFrom = items[i].loadFrom;
|
||||
IDisplayPane loadTo = items[i].loadTo;
|
||||
AbstractTimeMatcher srcTimeMatcher = loadFrom
|
||||
.getDescriptor().getTimeMatcher();
|
||||
if (srcTimeMatcher != null) {
|
||||
loadTo.getDescriptor().getTimeMatcher()
|
||||
.copyFrom(srcTimeMatcher);
|
||||
}
|
||||
loadTo.getDescriptor().getTimeMatcher().resetMultiload();
|
||||
t.run();
|
||||
} else {
|
||||
t.start();
|
||||
threads[i - 1] = t;
|
||||
}
|
||||
}
|
||||
|
||||
for (Thread t : threads) {
|
||||
try {
|
||||
t.join();
|
||||
} catch (InterruptedException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pairing of display->pane loading that should occur. Each item
|
||||
* will have {@link #load(IDisplayPane, IRenderableDisplay)} called on it
|
||||
*
|
||||
* @param container
|
||||
* @param bundle
|
||||
* @return
|
||||
* @throws VizException
|
||||
*/
|
||||
protected LoadItem[] getLoadItems(IDisplayPaneContainer container,
|
||||
Bundle bundle) throws VizException {
|
||||
IDisplayPane[] containerPanes = container.getDisplayPanes();
|
||||
AbstractRenderableDisplay[] bundleDisplays = bundle.getDisplays();
|
||||
|
||||
if (containerPanes.length != bundleDisplays.length) {
|
||||
boolean success = ensureOneToOne(container, bundle);
|
||||
containerPanes = container.getDisplayPanes();
|
||||
if (success) {
|
||||
throw new VizException("Unable to load "
|
||||
+ bundleDisplays.length
|
||||
+ " displays onto container with "
|
||||
+ containerPanes.length + " panes");
|
||||
}
|
||||
}
|
||||
|
||||
int numPanes = containerPanes.length;
|
||||
LoadItem[] items = new LoadItem[numPanes];
|
||||
|
||||
List<AbstractRenderableDisplay> orderedDisplays = Arrays
|
||||
.asList(bundleDisplays);
|
||||
for (int i = 0; i < numPanes; ++i) {
|
||||
IDescriptor desc = bundleDisplays[i].getDescriptor();
|
||||
if (desc.getTimeMatcher() != null) {
|
||||
orderedDisplays = desc.getTimeMatcher().getDisplayLoadOrder(
|
||||
orderedDisplays);
|
||||
for (AbstractRenderableDisplay d : orderedDisplays) {
|
||||
d.getDescriptor().synchronizeTimeMatching(desc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (orderedDisplays.size() != numPanes) {
|
||||
throw new VizException(
|
||||
"Error ordering bundle displays. Number of displays returned not same as passed in");
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
for (AbstractRenderableDisplay display : orderedDisplays) {
|
||||
for (int i = 0; i < numPanes; ++i) {
|
||||
if (display == bundleDisplays[i]) {
|
||||
items[j] = new LoadItem(containerPanes[i],
|
||||
bundleDisplays[i]);
|
||||
}
|
||||
}
|
||||
++j;
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures there is a one to one relationship for number of panes on
|
||||
* container to number of displays in bundle
|
||||
*
|
||||
* @param container
|
||||
* @param bundle
|
||||
* @return true of mapping is 1-1, false otherwise
|
||||
*/
|
||||
protected boolean ensureOneToOne(IDisplayPaneContainer container,
|
||||
Bundle bundle) {
|
||||
IDisplayPane[] containerPanes = container.getDisplayPanes();
|
||||
AbstractRenderableDisplay[] bundleDisplays = bundle.getDisplays();
|
||||
|
||||
// Attempt to match 1-1 pane to display
|
||||
if (container instanceof IMultiPaneEditor) {
|
||||
final IMultiPaneEditor mpe = (IMultiPaneEditor) container;
|
||||
final int numPanes = containerPanes.length;
|
||||
final int numDisplays = bundleDisplays.length;
|
||||
final IDisplayPane[] cPanes = containerPanes;
|
||||
final AbstractRenderableDisplay[] bDisplays = bundleDisplays;
|
||||
VizApp.runSync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = numPanes; i < numDisplays; ++i) {
|
||||
// This will hit if fewer panes than displays
|
||||
mpe.addPane(bDisplays[i]);
|
||||
}
|
||||
for (int i = numDisplays; i < numPanes; ++i) {
|
||||
// This will hit if fewer displays than panes
|
||||
mpe.removePane(cPanes[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
containerPanes = container.getDisplayPanes();
|
||||
return containerPanes.length == bundleDisplays.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the renderable display onto the pane
|
||||
*
|
||||
* @param loadTo
|
||||
* @param loadFrom
|
||||
*/
|
||||
protected void load(final IDisplayPane loadTo,
|
||||
final IRenderableDisplay loadFrom) {
|
||||
VizApp.runSync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadTo.setRenderableDisplay(loadFrom);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a bundle object from bundle text, text type is specified by
|
||||
* {@link BundleInfoType} passed in
|
||||
*
|
||||
* @param bundleText
|
||||
* @param variables
|
||||
* @param type
|
||||
* @return
|
||||
* @throws VizException
|
||||
*/
|
||||
public static Bundle getBundle(String bundleText,
|
||||
Map<String, String> variables, BundleInfoType type)
|
||||
throws VizException {
|
||||
/** Make sure bundle text is not null */
|
||||
if (bundleText == null) {
|
||||
throw new IllegalArgumentException("Bundle text cannot be null");
|
||||
}
|
||||
|
||||
Bundle b = null;
|
||||
/** Is the bundle location the bundle xml or a file with the xml? */
|
||||
if (type == BundleInfoType.FILE_LOCATION) {
|
||||
/** File with xml */
|
||||
b = Bundle.unmarshalBundle(PathManagerFactory.getPathManager()
|
||||
.getStaticFile(bundleText), variables);
|
||||
} else {
|
||||
/** bundleLocation variable contains the xml */
|
||||
b = Bundle.unmarshalBundle(bundleText, variables);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a {@link BundleLoader} to run to load the bundle on the
|
||||
* container
|
||||
*
|
||||
* @param container
|
||||
* @param b
|
||||
*/
|
||||
public static void loadTo(IDisplayPaneContainer container, Bundle b) {
|
||||
new BundleLoader(container, b).schedule();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
package com.raytheon.viz.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.viz.core.IDisplayPane;
|
||||
import com.raytheon.uf.viz.core.IDisplayPaneContainer;
|
||||
import com.raytheon.uf.viz.core.drawables.AbstractRenderableDisplay;
|
||||
import com.raytheon.uf.viz.core.drawables.IDescriptor;
|
||||
import com.raytheon.uf.viz.core.drawables.IDescriptor.FramesInfo;
|
||||
import com.raytheon.uf.viz.core.drawables.IRenderableDisplay;
|
||||
import com.raytheon.uf.viz.core.drawables.ResourcePair;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.raytheon.uf.viz.core.procedures.Bundle;
|
||||
import com.raytheon.uf.viz.core.rsc.AbstractResourceData;
|
||||
import com.raytheon.uf.viz.core.rsc.ResourceList;
|
||||
import com.raytheon.uf.viz.core.rsc.capabilities.ColorableCapability;
|
||||
import com.raytheon.viz.core.ColorUtil;
|
||||
import com.raytheon.viz.ui.editor.IMultiPaneEditor;
|
||||
|
||||
/**
|
||||
*
|
||||
* Loads a bundle as a product to a container. This will add the resources from
|
||||
* the bundle displays onto the container instead of replacing
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jan 8, 2013 mschenke Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author mschenke
|
||||
* @version 1.0
|
||||
*/
|
||||
public class BundleProductLoader extends BundleLoader {
|
||||
|
||||
public BundleProductLoader(IDisplayPaneContainer container, Bundle bundle) {
|
||||
super("Product Loader", container, bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LoadItem[] getLoadItems(IDisplayPaneContainer container,
|
||||
Bundle bundle) throws VizException {
|
||||
IDisplayPane[] containerPanes = container.getDisplayPanes();
|
||||
AbstractRenderableDisplay[] bundleDisplays = bundle.getDisplays();
|
||||
|
||||
int bundleSize = bundleDisplays.length;
|
||||
int editorSize = containerPanes.length;
|
||||
|
||||
IDisplayPane[] loadTo;
|
||||
IRenderableDisplay[] loadFrom;
|
||||
|
||||
IDisplayPane selected = null;
|
||||
if (container instanceof IMultiPaneEditor) {
|
||||
selected = ((IMultiPaneEditor) container)
|
||||
.getSelectedPane(IMultiPaneEditor.LOAD_ACTION);
|
||||
}
|
||||
|
||||
// Figure out what panes to load to
|
||||
if (selected != null && bundleSize == 1) {
|
||||
// Only load to selected pane
|
||||
loadTo = new IDisplayPane[] { selected };
|
||||
loadFrom = new IRenderableDisplay[] { bundleDisplays[0] };
|
||||
} else if (bundleSize == 1 && editorSize >= 1) {
|
||||
loadTo = new IDisplayPane[editorSize];
|
||||
loadFrom = new IRenderableDisplay[editorSize];
|
||||
for (int i = 0; i < editorSize; ++i) {
|
||||
loadTo[i] = containerPanes[i];
|
||||
loadFrom[i] = bundleDisplays[0].cloneDisplay();
|
||||
}
|
||||
} else {
|
||||
// Load 1-1
|
||||
if (editorSize < bundleSize) {
|
||||
// If fewer container panes than bundle displays, attempt to
|
||||
// ensure 1-1 by adding panes
|
||||
ensureOneToOne(container, bundle);
|
||||
containerPanes = container.getDisplayPanes();
|
||||
editorSize = containerPanes.length;
|
||||
}
|
||||
// Load what is possible
|
||||
int maxCanLoad = Math.min(editorSize, bundleSize);
|
||||
loadTo = new IDisplayPane[maxCanLoad];
|
||||
loadFrom = new IRenderableDisplay[maxCanLoad];
|
||||
for (int i = 0; i < maxCanLoad; ++i) {
|
||||
loadTo[i] = containerPanes[i];
|
||||
loadFrom[i] = bundleDisplays[i];
|
||||
}
|
||||
}
|
||||
|
||||
LoadItem[] items = new LoadItem[loadTo.length];
|
||||
for (int i = 0; i < items.length; ++i) {
|
||||
items[i] = new LoadItem(loadTo[i], loadFrom[i]);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load(IDisplayPane loadTo, IRenderableDisplay loadFrom) {
|
||||
IDescriptor existingDescriptor = loadTo.getDescriptor();
|
||||
IDescriptor fromDescriptor = loadFrom.getDescriptor();
|
||||
|
||||
/**
|
||||
* Update the frame count based on what has been listed in the bundle if
|
||||
* we don't have times already loaded
|
||||
*/
|
||||
FramesInfo info = existingDescriptor.getFramesInfo();
|
||||
if (info.getFrameCount() == 0) {
|
||||
existingDescriptor.setNumberOfFrames(fromDescriptor
|
||||
.getNumberOfFrames());
|
||||
}
|
||||
|
||||
// Pull out the resources to load
|
||||
ResourceList rscs = loadFrom.getDescriptor().getResourceList();
|
||||
List<ResourcePair> resourcesToLoad = new ArrayList<ResourcePair>();
|
||||
|
||||
for (ResourcePair rp : rscs) {
|
||||
if (rp.getProperties().isSystemResource() == false) {
|
||||
resourcesToLoad.add(rp);
|
||||
}
|
||||
}
|
||||
|
||||
rscs.clear();
|
||||
|
||||
/**
|
||||
* For each resource pair in the bundle resources: Give a unique color
|
||||
* for the legend if one isn't set, add to pane's descriptor's resource
|
||||
* list
|
||||
*/
|
||||
for (ResourcePair rp : resourcesToLoad) {
|
||||
AbstractResourceData ard = rp.getResourceData();
|
||||
|
||||
try {
|
||||
ard.configure(rp.getLoadProperties(), existingDescriptor);
|
||||
} catch (VizException e) {
|
||||
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
|
||||
e);
|
||||
}
|
||||
|
||||
boolean newRP = true;
|
||||
if (existingDescriptor.getResourceList().contains(rp)) {
|
||||
newRP = false;
|
||||
}
|
||||
if (newRP
|
||||
&& (rp.getProperties().isSystemResource() == false && !rp
|
||||
.getLoadProperties().getCapabilities()
|
||||
.hasCapability(ColorableCapability.class))) {
|
||||
rp.getLoadProperties()
|
||||
.getCapabilities()
|
||||
.getCapability(rp.getResourceData(),
|
||||
ColorableCapability.class)
|
||||
.setColor(
|
||||
ColorUtil.getNewColor(
|
||||
container.getDisplayPanes(),
|
||||
existingDescriptor, rp));
|
||||
}
|
||||
|
||||
if (newRP) {
|
||||
existingDescriptor.getResourceList().add(rp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -256,7 +256,10 @@ public class HistoryList {
|
|||
}
|
||||
|
||||
public static Bundle prepareHistoryEntry() {
|
||||
IDisplayPaneContainer cont = EditorUtil.getActiveVizContainer();
|
||||
return prepareHistoryEntry(EditorUtil.getActiveVizContainer());
|
||||
}
|
||||
|
||||
public static Bundle prepareHistoryEntry(IDisplayPaneContainer cont) {
|
||||
if (cont != null) {
|
||||
Bundle b = new Bundle();
|
||||
com.raytheon.uf.viz.core.IDisplayPane[] panes = cont
|
||||
|
|
|
@ -1,350 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.viz.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.viz.core.AbstractTimeMatcher;
|
||||
import com.raytheon.uf.viz.core.IDisplayPane;
|
||||
import com.raytheon.uf.viz.core.VizApp;
|
||||
import com.raytheon.uf.viz.core.drawables.IDescriptor;
|
||||
import com.raytheon.uf.viz.core.drawables.IDescriptor.FramesInfo;
|
||||
import com.raytheon.uf.viz.core.drawables.IRenderableDisplay;
|
||||
import com.raytheon.uf.viz.core.drawables.ResourcePair;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.raytheon.uf.viz.core.globals.VizGlobalsManager;
|
||||
import com.raytheon.uf.viz.core.procedures.Bundle;
|
||||
import com.raytheon.uf.viz.core.rsc.AbstractResourceData;
|
||||
import com.raytheon.uf.viz.core.rsc.ResourceList;
|
||||
import com.raytheon.uf.viz.core.rsc.capabilities.ColorableCapability;
|
||||
import com.raytheon.viz.core.ColorUtil;
|
||||
import com.raytheon.viz.ui.editor.AbstractEditor;
|
||||
import com.raytheon.viz.ui.editor.IMultiPaneEditor;
|
||||
|
||||
/**
|
||||
* TODO Add Description
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 2, 2009 chammack Initial creation
|
||||
* Apr 7, 2009 2215 jsanchez Updated the scaleFile.
|
||||
* June 25, 2010 1691 bkowal The frame count for the created /
|
||||
* discovered editor will now be
|
||||
* updated to match the frame
|
||||
* count that was specified in the bundle.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author chammack
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class MenuLoader extends Job {
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(MenuLoader.class);
|
||||
|
||||
private Bundle bundle;
|
||||
|
||||
private AbstractEditor editor;
|
||||
|
||||
private class InstantiationThread extends Thread {
|
||||
private IDisplayPane loadTo;
|
||||
|
||||
private IRenderableDisplay loadFrom;
|
||||
|
||||
public InstantiationThread(IDisplayPane loadTo,
|
||||
IRenderableDisplay loadFrom) {
|
||||
this.loadTo = loadTo;
|
||||
this.loadFrom = loadFrom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
IDescriptor existingDescriptor = loadTo.getDescriptor();
|
||||
|
||||
/**
|
||||
* Update the frame count based on what has been listed in the
|
||||
* bundle if we don't have times already loaded
|
||||
*/
|
||||
FramesInfo info = existingDescriptor.getFramesInfo();
|
||||
if (info.getFrameCount() == 0) {
|
||||
existingDescriptor.setNumberOfFrames(loadFrom.getDescriptor()
|
||||
.getNumberOfFrames());
|
||||
}
|
||||
|
||||
// Pull out the resources to load
|
||||
ResourceList rscs = loadFrom.getDescriptor().getResourceList();
|
||||
List<ResourcePair> resourcesToLoad = new ArrayList<ResourcePair>();
|
||||
|
||||
for (ResourcePair rp : rscs) {
|
||||
if (rp.getProperties().isSystemResource() == false) {
|
||||
resourcesToLoad.add(rp);
|
||||
}
|
||||
}
|
||||
|
||||
rscs.clear();
|
||||
|
||||
/**
|
||||
* For each resource pair in the bundle resources: Give a unique
|
||||
* color for the legend if one isn't set, add to pane's descriptor's
|
||||
* resource list
|
||||
*/
|
||||
for (ResourcePair rp : resourcesToLoad) {
|
||||
AbstractResourceData ard = rp.getResourceData();
|
||||
|
||||
try {
|
||||
ard.configure(rp.getLoadProperties(), existingDescriptor);
|
||||
} catch (VizException e) {
|
||||
statusHandler.handle(Priority.PROBLEM,
|
||||
e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
boolean newRP = true;
|
||||
if (existingDescriptor.getResourceList().contains(rp)) {
|
||||
newRP = false;
|
||||
}
|
||||
if (newRP
|
||||
&& (rp.getProperties().isSystemResource() == false && !rp
|
||||
.getLoadProperties().getCapabilities()
|
||||
.hasCapability(ColorableCapability.class))) {
|
||||
rp.getLoadProperties()
|
||||
.getCapabilities()
|
||||
.getCapability(rp.getResourceData(),
|
||||
ColorableCapability.class)
|
||||
.setColor(
|
||||
ColorUtil.getNewColor(
|
||||
editor.getDisplayPanes(),
|
||||
existingDescriptor, rp));
|
||||
}
|
||||
|
||||
if (newRP) {
|
||||
existingDescriptor.getResourceList().add(rp);
|
||||
}
|
||||
}
|
||||
|
||||
existingDescriptor.getResourceList().instantiateResources(
|
||||
existingDescriptor, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static enum BundleInfoType {
|
||||
FILE_LOCATION, XML
|
||||
}
|
||||
|
||||
public MenuLoader(Bundle b, AbstractEditor editor) {
|
||||
super("Request EDEX Product");
|
||||
this.bundle = b;
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
public static void loadProduct(final String editorType,
|
||||
final String bundleLocation, final Map<String, String> variables)
|
||||
throws VizException {
|
||||
loadProduct(editorType, bundleLocation, variables,
|
||||
BundleInfoType.FILE_LOCATION);
|
||||
}
|
||||
|
||||
public static void loadProduct(String editorType, String bundleLocation,
|
||||
Map<String, String> variables, BundleInfoType type)
|
||||
throws VizException {
|
||||
Bundle b = null;
|
||||
|
||||
/** Make sure bundle location is not null */
|
||||
if (bundleLocation == null) {
|
||||
throw new VizException("bundleLocation was null");
|
||||
}
|
||||
|
||||
/** Is the bundle location the bundle xml or a file with the xml? */
|
||||
if (type.equals(BundleInfoType.FILE_LOCATION)) {
|
||||
/** File with xml */
|
||||
b = Bundle.unmarshalBundle(PathManagerFactory.getPathManager()
|
||||
.getStaticFile(bundleLocation), variables);
|
||||
} else {
|
||||
/** bundleLocation variable contains the xml */
|
||||
b = Bundle.unmarshalBundle(bundleLocation, null);
|
||||
}
|
||||
|
||||
/** Load the editor from the bundle */
|
||||
AbstractEditor editor = null;
|
||||
editor = UiUtil.createOrOpenEditor(editorType, b.getDisplays());
|
||||
|
||||
/** Error loading the editor */
|
||||
if (editor == null) {
|
||||
throw new VizException("unable to get editor: " + editorType);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the descriptor in the bundle did not get set as the descriptor in
|
||||
* the editor, we need to go through and add the resources in the
|
||||
* bundle's IDisplayPane's descriptor to the editor's IDisplayPane's
|
||||
* descriptor, which is done in the job
|
||||
*/
|
||||
if (editor.getDisplayPanes()[0].getDescriptor() != b.getDisplays()[0]
|
||||
.getDescriptor()) {
|
||||
Job j = new MenuLoader(b, editor);
|
||||
j.schedule();
|
||||
} else {
|
||||
/**
|
||||
* The editor and bundle have the same descriptors meaning the
|
||||
* editor was opened from the bundle so we need to instantiate the
|
||||
* resources on them only (this needs to be done outside the job bc
|
||||
* paint will be called immediately after this and the resources may
|
||||
* not have been instantiated yet.
|
||||
*
|
||||
* TODO: There may be a way to create a list of resources from the
|
||||
* bundle and in this statement just remove the resources from the
|
||||
* editor then re add them in the job. so this doesn't hang on
|
||||
* construction of the resource
|
||||
*/
|
||||
for (IDisplayPane pane : editor.getDisplayPanes()) {
|
||||
pane.getDescriptor().getResourceList()
|
||||
.instantiateResources(pane.getDescriptor(), true);
|
||||
}
|
||||
HistoryList.getInstance().refreshLatestBundle();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
long t0 = System.currentTimeMillis();
|
||||
try {
|
||||
/** extracted to method when doing a refactor, not really needed */
|
||||
loadExisting();
|
||||
/** refresh the editor */
|
||||
editor.refresh();
|
||||
/** update the history list */
|
||||
HistoryList.getInstance().refreshLatestBundle();
|
||||
} catch (VizException e) {
|
||||
return new Status(IStatus.ERROR, UiPlugin.PLUGIN_ID,
|
||||
"Error loading bundle", e);
|
||||
}
|
||||
long t2 = System.currentTimeMillis();
|
||||
System.out.println("Total bundle retrieval: " + (t2 - t0));
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
private void loadExisting() throws VizException {
|
||||
IDisplayPane selected = null;
|
||||
if (editor instanceof IMultiPaneEditor) {
|
||||
selected = ((IMultiPaneEditor) editor)
|
||||
.getSelectedPane(IMultiPaneEditor.LOAD_ACTION);
|
||||
}
|
||||
|
||||
int bundleSize = bundle.getDisplays().length;
|
||||
int editorSize = editor.getDisplayPanes().length;
|
||||
|
||||
List<IDisplayPane> loadToPanes = new ArrayList<IDisplayPane>();
|
||||
List<IRenderableDisplay> loadFromBundle = new ArrayList<IRenderableDisplay>();
|
||||
List<Thread> executionThreads = new ArrayList<Thread>();
|
||||
|
||||
// Figure out what panes to load to
|
||||
if (selected != null && bundleSize == 1) {
|
||||
loadToPanes.add(selected);
|
||||
loadFromBundle.add(bundle.getDisplays()[0]);
|
||||
} else if (selected == null && bundleSize == 1) {
|
||||
// load to all panes the single bundle display
|
||||
for (IDisplayPane pane : editor.getDisplayPanes()) {
|
||||
loadToPanes.add(pane);
|
||||
loadFromBundle.add(bundle.getDisplays()[0].cloneDisplay());
|
||||
}
|
||||
} else {
|
||||
int max = Math.max(bundleSize, editorSize);
|
||||
for (int i = 0; i < max; ++i) {
|
||||
if (editorSize > i) {
|
||||
loadToPanes.add(editor.getDisplayPanes()[i]);
|
||||
} else {
|
||||
loadToPanes.add(null);
|
||||
}
|
||||
|
||||
if (bundleSize > i) {
|
||||
loadFromBundle.add(bundle.getDisplays()[i]);
|
||||
} else {
|
||||
loadFromBundle.add(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < loadToPanes.size(); ++i) {
|
||||
IDisplayPane loadTo = loadToPanes.get(i);
|
||||
final IRenderableDisplay loadFrom = loadFromBundle.get(i);
|
||||
if (i == 0) {
|
||||
AbstractTimeMatcher srcTimeMatcher = loadFrom.getDescriptor()
|
||||
.getTimeMatcher();
|
||||
if (srcTimeMatcher != null) {
|
||||
loadTo.getDescriptor().getTimeMatcher()
|
||||
.copyFrom(srcTimeMatcher);
|
||||
}
|
||||
loadTo.getDescriptor().getTimeMatcher().resetMultiload();
|
||||
new InstantiationThread(loadTo, loadFrom).run();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (loadFrom == null) {
|
||||
continue;
|
||||
} else if (loadTo == null) {
|
||||
if (editor instanceof IMultiPaneEditor) {
|
||||
VizApp.runSync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
((IMultiPaneEditor) (editor)).addPane(loadFrom);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
Thread t = new InstantiationThread(loadTo, loadFrom);
|
||||
t.start();
|
||||
executionThreads.add(t);
|
||||
}
|
||||
|
||||
for (Thread t : executionThreads) {
|
||||
try {
|
||||
t.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
VizApp.runAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
VizGlobalsManager.getCurrentInstance().updateUI(editor);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
|
@ -20,9 +20,6 @@
|
|||
package com.raytheon.viz.ui.actions;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
|
@ -46,21 +43,16 @@ import com.raytheon.uf.common.status.IUFStatusHandler;
|
|||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.viz.core.DescriptorMap;
|
||||
import com.raytheon.uf.viz.core.IDisplayPane;
|
||||
import com.raytheon.uf.viz.core.IDisplayPaneContainer;
|
||||
import com.raytheon.uf.viz.core.VizApp;
|
||||
import com.raytheon.uf.viz.core.drawables.AbstractRenderableDisplay;
|
||||
import com.raytheon.uf.viz.core.drawables.IDescriptor;
|
||||
import com.raytheon.uf.viz.core.drawables.IRenderableDisplay;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.raytheon.uf.viz.core.globals.VizGlobalsManager;
|
||||
import com.raytheon.uf.viz.core.procedures.Bundle;
|
||||
import com.raytheon.uf.viz.core.procedures.Procedure;
|
||||
import com.raytheon.uf.viz.core.rsc.ResourceList;
|
||||
import com.raytheon.viz.ui.BundleLoader;
|
||||
import com.raytheon.viz.ui.UiUtil;
|
||||
import com.raytheon.viz.ui.VizWorkbenchManager;
|
||||
import com.raytheon.viz.ui.editor.AbstractEditor;
|
||||
import com.raytheon.viz.ui.editor.IMultiPaneEditor;
|
||||
|
||||
/**
|
||||
* Handles loading of bundles or procedures
|
||||
|
@ -133,11 +125,10 @@ public class LoadSerializedXml extends AbstractHandler {
|
|||
IDescriptor bundleDescriptor = renderableDisplay.getDescriptor();
|
||||
String bundleEditorId = DescriptorMap.getEditorId(bundleDescriptor
|
||||
.getClass().getName());
|
||||
synchronizeDisplays(bundle);
|
||||
AbstractEditor editor = UiUtil.createOrOpenEditor(bundleEditorId,
|
||||
bundle.getDisplays());
|
||||
|
||||
loadTo(editor, bundle);
|
||||
BundleLoader.loadTo(editor, bundle);
|
||||
}
|
||||
|
||||
public static void loadProcedureToScreen(Procedure procedure,
|
||||
|
@ -183,7 +174,6 @@ public class LoadSerializedXml extends AbstractHandler {
|
|||
for (Bundle b : bundles) {
|
||||
// If an editor is specified, or no view part is specified,
|
||||
// assume an editor part
|
||||
synchronizeDisplays(b);
|
||||
if (b.getView() == null) {
|
||||
String editorName = b.getEditor();
|
||||
AbstractEditor openedEditor = UiUtil.createEditor(editorName,
|
||||
|
@ -202,33 +192,22 @@ public class LoadSerializedXml extends AbstractHandler {
|
|||
}
|
||||
}
|
||||
|
||||
loadTo(openedEditor, b);
|
||||
BundleLoader.loadTo(openedEditor, b);
|
||||
} else {
|
||||
// There is a view part specified
|
||||
IViewPart part = UiUtil.findView(windowToLoadTo, b.getView(),
|
||||
false);
|
||||
|
||||
if (part != null && part instanceof IDisplayPaneContainer) {
|
||||
loadTo((IDisplayPaneContainer) part, b);
|
||||
BundleLoader.loadTo((IDisplayPaneContainer) part, b);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void synchronizeDisplays(Bundle b) {
|
||||
IDescriptor firstDesc = null;
|
||||
for (AbstractRenderableDisplay d : b.getDisplays()) {
|
||||
if (firstDesc == null) {
|
||||
firstDesc = d.getDescriptor();
|
||||
} else {
|
||||
d.getDescriptor().synchronizeTimeMatching(firstDesc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a bundle to a container
|
||||
* Use {@link BundleLoader} instead
|
||||
*
|
||||
* @param editor
|
||||
* the container to load to
|
||||
|
@ -236,119 +215,10 @@ public class LoadSerializedXml extends AbstractHandler {
|
|||
* the bundle
|
||||
* @throws VizException
|
||||
*/
|
||||
public static void loadTo(final IDisplayPaneContainer container,
|
||||
final Bundle b) throws VizException {
|
||||
final int containerSize = container.getDisplayPanes().length;
|
||||
final boolean multiEditor = container instanceof IMultiPaneEditor;
|
||||
|
||||
if (multiEditor) {
|
||||
if (container.getDisplayPanes().length > b.getDisplays().length) {
|
||||
VizApp.runSync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (container.getDisplayPanes().length > b
|
||||
.getDisplays().length) {
|
||||
((IMultiPaneEditor) container).removePane(container
|
||||
.getDisplayPanes()[container
|
||||
.getDisplayPanes().length - 1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
List<AbstractRenderableDisplay> orderedDisplays = Arrays.asList(b
|
||||
.getDisplays());
|
||||
IDescriptor firstDesc = orderedDisplays.get(0).getDescriptor();
|
||||
if (firstDesc != null && firstDesc.getTimeMatcher() != null) {
|
||||
orderedDisplays = firstDesc.getTimeMatcher().getDisplayLoadOrder(
|
||||
orderedDisplays);
|
||||
}
|
||||
for (AbstractRenderableDisplay d : orderedDisplays) {
|
||||
d.getDescriptor().synchronizeTimeMatching(firstDesc);
|
||||
ResourceList rl = d.getDescriptor().getResourceList();
|
||||
rl.instantiateResources(d.getDescriptor(), true);
|
||||
}
|
||||
|
||||
final VizException[] errors = new VizException[1];
|
||||
|
||||
VizApp.runSync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int i = 0;
|
||||
for (AbstractRenderableDisplay d : b.getDisplays()) {
|
||||
if (i >= containerSize && multiEditor) {
|
||||
((IMultiPaneEditor) container).addPane(d);
|
||||
} else if (i >= containerSize) {
|
||||
errors[0] = new VizException(
|
||||
"Unable to add panes to non IMultiPaneEditor");
|
||||
return;
|
||||
} else {
|
||||
IRenderableDisplay oldDisplay = container
|
||||
.getDisplayPanes()[i].getRenderableDisplay();
|
||||
if (oldDisplay != null && oldDisplay != d) {
|
||||
oldDisplay.dispose();
|
||||
}
|
||||
container.getDisplayPanes()[i].setRenderableDisplay(d);
|
||||
container.getDisplayPanes()[i].resize();
|
||||
container.getDisplayPanes()[i].refresh();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (b.getLoopProperties() != null) {
|
||||
container.setLoopProperties(b.getLoopProperties());
|
||||
}
|
||||
|
||||
// if loading to an editor, update the globals
|
||||
if (container instanceof IEditorPart) {
|
||||
VizGlobalsManager.getCurrentInstance().updateUI(container);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (errors[0] != null) {
|
||||
throw errors[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a bundle from a file into a container
|
||||
*
|
||||
* @param editor
|
||||
* the container to load to
|
||||
* @param f
|
||||
* the file containing the bundle
|
||||
* @param descriptor
|
||||
* Optional: A descriptor that should be used for time matching
|
||||
* @throws VizException
|
||||
*/
|
||||
public static void loadTo(File f, Map<String, String> variables)
|
||||
@Deprecated
|
||||
public static void loadTo(final IDisplayPaneContainer container, Bundle b)
|
||||
throws VizException {
|
||||
Bundle b = Bundle.unmarshalBundle(f, variables);
|
||||
|
||||
IRenderableDisplay renderableDisplay = b.getDisplays()[0];
|
||||
IDescriptor bundleDescriptor = renderableDisplay.getDescriptor();
|
||||
String bundleEditorId = DescriptorMap.getEditorId(bundleDescriptor
|
||||
.getClass().getName());
|
||||
AbstractEditor editor = UiUtil.createOrOpenEditor(bundleEditorId,
|
||||
b.getDisplays());
|
||||
|
||||
loadTo(editor, b);
|
||||
new BundleLoader(container, b).run();
|
||||
}
|
||||
|
||||
public static void loadTo(IDisplayPane pane, File f,
|
||||
Map<String, String> variables) throws VizException {
|
||||
|
||||
Bundle b = Bundle.unmarshalBundle(f, variables);
|
||||
|
||||
for (AbstractRenderableDisplay d : b.getDisplays()) {
|
||||
ResourceList rl = d.getDescriptor().getResourceList();
|
||||
rl.instantiateResources(d.getDescriptor(), true);
|
||||
|
||||
pane.setRenderableDisplay(d);
|
||||
pane.resize();
|
||||
pane.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ import com.raytheon.viz.core.slice.request.VerticalPointRequest.TimeDirection;
|
|||
import com.raytheon.viz.skewt.SkewtDisplay;
|
||||
import com.raytheon.viz.skewt.rscdata.SkewTResourceData;
|
||||
import com.raytheon.viz.ui.EditorUtil;
|
||||
import com.raytheon.viz.ui.MenuLoader;
|
||||
import com.raytheon.viz.ui.BundleProductLoader;
|
||||
import com.raytheon.viz.ui.UiUtil;
|
||||
import com.raytheon.viz.ui.editor.AbstractEditor;
|
||||
import com.raytheon.viz.ui.editor.IMultiPaneEditor;
|
||||
|
@ -1078,7 +1078,7 @@ public class ProductTableComp extends Composite {
|
|||
|
||||
Bundle b = new Bundle();
|
||||
b.setDisplays(new AbstractRenderableDisplay[] { display });
|
||||
Job j = new MenuLoader(b, editor);
|
||||
Job j = new BundleProductLoader(editor, b);
|
||||
j.schedule();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue