From b2e374c7fb1d5cb2bc323b13e2294380fcd3ada9 Mon Sep 17 00:00:00 2001 From: Max Schenkelberg Date: Wed, 20 Mar 2013 17:20:55 -0500 Subject: [PATCH] Issue #1638 Created AWIPSWorkbenchAdvisor which sends MenuCreation request to run so core cave applications will not depend on uf.edex.menus being deployed in EDEX. Changed DbQuery to use DbQueryRequest under the hood to remove dependency on ScriptCreator. Amend: Added header comments and more unused code Change-Id: Ib9285d0472e41473ba79bbada8ea2bf57b55d686 Former-commit-id: e40808621cfee3cabe6b6cf124440632ef08d5d7 --- .../raytheon/uf/viz/core/catalog/DbQuery.java | 295 ++++-------------- .../cave/ThinClientWorkbenchAdvisor.java | 13 +- .../ui/menus/DiscoverMenuContributions.java | 27 +- .../META-INF/MANIFEST.MF | 1 + .../awips/AWIPSWorkbenchAdvisor.java} | 47 +-- .../awips/AbstractCAVEComponent.java | 2 +- .../awips/VizWorkbenchAdvisor.java | 23 +- .../awips/VizWorkbenchWindowAdvisor.java | 5 +- .../AbstractVizPerspectiveManager.java | 21 +- 9 files changed, 110 insertions(+), 324 deletions(-) rename cave/{com.raytheon.uf.viz.ui.menus/src/com/raytheon/uf/viz/ui/menus/MenuCreationJob.java => com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/AWIPSWorkbenchAdvisor.java} (57%) diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/catalog/DbQuery.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/catalog/DbQuery.java index 70a4a1008b..db3d88fd86 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/catalog/DbQuery.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/catalog/DbQuery.java @@ -20,6 +20,20 @@ package com.raytheon.uf.viz.core.catalog; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.raytheon.uf.common.dataquery.db.OrderField.ResultOrder; +import com.raytheon.uf.common.dataquery.requests.DbQueryRequest; +import com.raytheon.uf.common.dataquery.requests.DbQueryRequest.OrderMode; +import com.raytheon.uf.common.dataquery.requests.DbQueryRequest.RequestField; +import com.raytheon.uf.common.dataquery.requests.RequestConstraint; +import com.raytheon.uf.common.dataquery.requests.RequestConstraint.ConstraintType; +import com.raytheon.uf.common.dataquery.responses.DbQueryResponse; +import com.raytheon.uf.viz.core.exception.VizException; +import com.raytheon.uf.viz.core.requests.ThriftClient; + /** * Performs a database query. * @@ -30,71 +44,25 @@ package com.raytheon.uf.viz.core.catalog; * 06/05/08 #875 bphillip Initial Creation. * 06/12/08 M. Duff Added ordering and convenience methods. * 10/13/08 chammack Improve error handling on server-side exceptions + * Mar 20, 2013 #1638 mschenke Rewrote to use DbQueryRequest under the hood to remove use of ScriptCreator * * * @author bphillip * @version 1.0 */ -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.raytheon.uf.common.dataquery.db.JoinField; -import com.raytheon.uf.common.dataquery.db.OrderField; -import com.raytheon.uf.common.dataquery.db.OrderField.ResultOrder; -import com.raytheon.uf.common.dataquery.db.ReturnedField; -import com.raytheon.uf.common.dataquery.requests.RequestConstraint; -import com.raytheon.uf.common.dataquery.requests.RequestConstraint.ConstraintType; -import com.raytheon.uf.common.message.Message; -import com.raytheon.uf.common.message.response.AbstractResponseMessage; -import com.raytheon.uf.common.message.response.ResponseMessageError; -import com.raytheon.uf.common.message.response.ResponseMessageGeneric; -import com.raytheon.uf.viz.core.RecordFactory; -import com.raytheon.uf.viz.core.comm.Connector; -import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.uf.viz.core.exception.VizServerSideException; - public class DbQuery { - /** The database to query */ - protected String dbName; + private DbQueryRequest request = new DbQueryRequest(); - /** The class to query against */ - protected String className; - - protected String plugin = "satellite"; - - protected ReturnedField distinctField; - - protected String distinctClass; - - protected List columns = new ArrayList(); - - protected List orderBy = new ArrayList(); - - protected List joinFields = new ArrayList(); - - protected ResultOrder ascending = ResultOrder.ASC; - - protected Map constraints = new HashMap(); - - protected Integer maxResults; + private ResultOrder ascending = ResultOrder.ASC; public DbQuery(Class clazz, String databaseName) { - this.className = clazz.getName(); - this.dbName = databaseName; + request.setEntityClass(clazz); + request.setDatabase(databaseName); } public DbQuery(String pluginName) { - try { - this.className = RecordFactory.getInstance() - .getPluginClass(pluginName).getName(); - this.dbName = "metadata"; - this.plugin = pluginName; - } catch (Exception e) { - e.printStackTrace(); - } + setPlugin(pluginName); } /** @@ -103,164 +71,30 @@ public class DbQuery { * @return The response * @throws VizException */ - @SuppressWarnings("unchecked") public List performQuery() throws VizException { - String query = assembleQuery(); - // System.out.println("[" + query + "]"); + DbQueryResponse response = (DbQueryResponse) ThriftClient + .sendRequest(request); + List fields = request.getFields(); + if (fields == null || fields.size() == 0) { + fields = new ArrayList(); + RequestField entity = new RequestField(); + entity.setField(DbQueryResponse.ENTITY_RESULT_KEY); + fields.add(entity); + } - Message message = Connector.getInstance().connectMessage(query, null, - 60000); - AbstractResponseMessage[] absresponses = message.getBody() - .getResponses(); + List> results = response.getResults(); + List rval = new ArrayList(results.size()); - List retVal = new ArrayList(); - for (AbstractResponseMessage response : absresponses) { - - if (response instanceof ResponseMessageGeneric) { - if (((ResponseMessageGeneric) response).getContents() instanceof List) { - ArrayList list = (ArrayList) ((ResponseMessageGeneric) response) - .getContents(); - Object[] vals = new Object[list.size()]; - for (int i = 0; i < list.size(); i++) { - vals[i] = list.get(i); - } - retVal.add(vals); - } else { - Object obj = ((ResponseMessageGeneric) response) - .getContents(); - Object[] vals = new Object[1]; - vals[0] = obj; - retVal.add(vals); - } - } else if (response instanceof ResponseMessageError) { - ResponseMessageError rme = (ResponseMessageError) response; - VizServerSideException innerException = new VizServerSideException( - rme.toString()); - throw new VizServerSideException(rme.getErrorMsg(), - innerException); + for (Map result : results) { + Object[] objs = new Object[fields.size()]; + int i = 0; + for (RequestField field : fields) { + objs[i++] = result.get(field.field); } - } - return retVal; - } - - public List performQuery(boolean bool) throws VizException { - String query = assembleQuery(); - System.out.println("[" + query + "]"); - - Message message = Connector.getInstance().connectMessage(query, null, - 60000); - AbstractResponseMessage[] absresponses = message.getBody() - .getResponses(); - - List retVal = new ArrayList(); - for (AbstractResponseMessage response : absresponses) { - - if (response instanceof ResponseMessageGeneric) { - if (((ResponseMessageGeneric) response).getContents() instanceof List) { - ArrayList list = (ArrayList) ((ResponseMessageGeneric) response) - .getContents(); - Object[] vals = new Object[list.size()]; - for (int i = 0; i < list.size(); i++) { - vals[i] = list.get(i); - } - retVal.add(vals); - } else { - Object obj = ((ResponseMessageGeneric) response) - .getContents(); - Object[] vals = new Object[1]; - vals[0] = obj; - retVal.add(vals); - } - } else if (response instanceof ResponseMessageError) { - ResponseMessageError rme = (ResponseMessageError) response; - VizServerSideException innerException = new VizServerSideException( - rme.toString()); - throw new VizServerSideException(rme.getErrorMsg(), - innerException); - } - } - return retVal; - } - - /** - * Assembles the database query - * - * @param dbName - * The database name - * @param className - * The class name to query for - * @param distinctField - * The distinct field (optional) - * @param columns - * The fields to be returned (required) - * @param constraints - * The constraints to apply to the query - * @return - * @throws VizException - */ - private String assembleQuery() throws VizException { - - addConstraint("pluginName", plugin); - addConstraint("dbName", dbName); - addConstraint("className", className); - - if (distinctField != null) { - addConstraint("distinctField", - new RequestConstraint(distinctField.getField())); - addConstraint("distinctClass", new RequestConstraint(distinctClass)); + rval.add(objs); } - if (!columns.isEmpty()) { - StringBuffer fieldList = new StringBuffer(); - for (int i = 0; i < columns.size(); i++) { - fieldList.append(columns.get(i).getField() + "---" - + columns.get(i).getClassName()); - if (i != columns.size() - 1) { - fieldList.append(","); - } - - } - addConstraint("columns", fieldList); - } - - if (!joinFields.isEmpty()) { - StringBuffer joinFieldList = new StringBuffer(); - for (int i = 0; i < joinFields.size(); i++) { - joinFieldList.append(joinFields.get(i).getJoinClassOne()) - .append("---"); - joinFieldList.append(joinFields.get(i).getJoinClassTwo()) - .append("---"); - joinFieldList.append(joinFields.get(i).getJoinFieldOne()); - if (joinFields.get(i).getJoinFieldTwo() != null) { - joinFieldList.append("---"); - joinFieldList.append(joinFields.get(i).getJoinFieldTwo()); - } - if (i != joinFields.size() - 1) { - joinFieldList.append(","); - } - } - addConstraint("joinFields", joinFieldList); - } - - if (!orderBy.isEmpty()) { - StringBuffer orderList = new StringBuffer(); - for (int i = 0; i < orderBy.size(); i++) { - orderList.append(orderBy.get(i).getField() + "---" - + orderBy.get(i).getClassName() + "---" - + orderBy.get(i).getOrder()); - if (i != orderBy.size() - 1) { - orderList.append(","); - } - } - addConstraint("orderBy", orderList); - addConstraint("sortOrder", String.valueOf(ascending)); - } - - if (maxResults != null) { - addConstraint("maxResults", maxResults); - } - return ScriptCreator.createScript(constraints, Integer.MAX_VALUE, - "dbquery"); + return rval; } /** @@ -268,12 +102,7 @@ public class DbQuery { * the plugin to set */ public void setPlugin(String plugin) { - this.plugin = plugin; - } - - public void setDistinctField(String distinctField, String className) { - distinctClass = className; - this.distinctField = new ReturnedField(distinctField, className); + request.addConstraint("pluginName", new RequestConstraint(plugin)); } /** @@ -281,14 +110,11 @@ public class DbQuery { * the distinctField to set */ public void setDistinctField(String distinctField) { - setDistinctField(distinctField, className); + request.setDistinct(true); + addColumn(distinctField); } - public void addConstraint(String key, ConstraintType operator, - Object value, String className) { - if (constraints == null) { - constraints = new HashMap(); - } + public void addConstraint(String key, ConstraintType operator, Object value) { RequestConstraint constraint = new RequestConstraint(); switch (operator) { @@ -307,24 +133,16 @@ public class DbQuery { break; } constraint.setConstraintType(operator); - constraints.put(key, constraint); + request.addConstraint(key, constraint); } public void addConstraint(String key, RequestConstraint constraint) { addConstraint(key, constraint.getConstraintType(), - constraint.getConstraintValue(), className); - } - - public void addConstraint(String key, ConstraintType operator, Object value) { - addConstraint(key, operator, value, className); + constraint.getConstraintValue()); } public void addConstraint(String key, Object value) { - addConstraint(key, ConstraintType.EQUALS, value, className); - } - - public void addColumn(String columnName, String className) { - columns.add(new ReturnedField(columnName, className)); + addConstraint(key, ConstraintType.EQUALS, value); } /** @@ -334,12 +152,18 @@ public class DbQuery { * A column name */ public void addColumn(String columnName) { - addColumn(columnName, className); + request.addRequestField(columnName); } + public void addOrderBy(String columnName, ResultOrder order) { + request.setOrderByField(columnName, + order == ResultOrder.ASC ? OrderMode.ASC : OrderMode.DESC); + } + + @Deprecated public void addOrderBy(String columnName, ResultOrder order, String className) { - orderBy.add(new OrderField(columnName, className, order)); + addOrderBy(columnName, order); } /** @@ -349,7 +173,7 @@ public class DbQuery { * A column name */ public void addOrderBy(String columnName) { - addOrderBy(columnName, ascending, className); + addOrderBy(columnName, ascending, null); } /** @@ -369,16 +193,7 @@ public class DbQuery { * - the maximum number of rows to return use -999 for all rows */ public void setMaxResults(Integer maxResults) { - this.maxResults = maxResults; + request.setLimit(maxResults); } - public void addJoinField(Class class1, Class class2, String field1, - String field2) { - joinFields.add(new JoinField(field1, field2, class1.getName(), class2 - .getName())); - } - - public void addJoinField(Class class1, Class class2, String field) { - addJoinField(class1, class2, field, field); - } } \ No newline at end of file diff --git a/cave/com.raytheon.uf.viz.thinclient.cave/src/com/raytheon/uf/viz/thinclient/cave/ThinClientWorkbenchAdvisor.java b/cave/com.raytheon.uf.viz.thinclient.cave/src/com/raytheon/uf/viz/thinclient/cave/ThinClientWorkbenchAdvisor.java index 24657a9775..ae0add4bdd 100644 --- a/cave/com.raytheon.uf.viz.thinclient.cave/src/com/raytheon/uf/viz/thinclient/cave/ThinClientWorkbenchAdvisor.java +++ b/cave/com.raytheon.uf.viz.thinclient.cave/src/com/raytheon/uf/viz/thinclient/cave/ThinClientWorkbenchAdvisor.java @@ -22,8 +22,6 @@ package com.raytheon.uf.viz.thinclient.cave; import org.eclipse.jface.preference.IPreferencePage; import org.eclipse.jface.preference.PreferenceManager; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.application.IWorkbenchWindowConfigurer; -import org.eclipse.ui.application.WorkbenchWindowAdvisor; import com.raytheon.uf.viz.thinclient.cave.preferences.DynamicPreferenceNode; import com.raytheon.uf.viz.thinclient.cave.preferences.DynamicPreferenceNode.IPreferencePageFactory; @@ -32,7 +30,6 @@ import com.raytheon.uf.viz.thinclient.cave.preferences.ThinClientConnectionPrefe import com.raytheon.uf.viz.thinclient.cave.preferences.ThinClientPreferencePage; import com.raytheon.uf.viz.thinclient.cave.preferences.ThinClientServerPreferences; import com.raytheon.viz.ui.personalities.awips.VizWorkbenchAdvisor; -import com.raytheon.viz.ui.personalities.awips.VizWorkbenchWindowAdvisor; /** * Thin Client workbench advisor, adds the thin client preference page @@ -43,7 +40,8 @@ import com.raytheon.viz.ui.personalities.awips.VizWorkbenchWindowAdvisor; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Oct 21, 2011 mschenke Initial creation + * Oct 21, 2011 mschenke Initial creation + * Mar 20, 2013 1638 mschenke Removed overriding of createWorkbenchWindowAdvisor as not needed * * * @@ -53,13 +51,6 @@ import com.raytheon.viz.ui.personalities.awips.VizWorkbenchWindowAdvisor; public class ThinClientWorkbenchAdvisor extends VizWorkbenchAdvisor { - @Override - public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor( - IWorkbenchWindowConfigurer configurer) { - return new VizWorkbenchWindowAdvisor(configurer, singlePerspective, - false); - } - /* * (non-Javadoc) * diff --git a/cave/com.raytheon.uf.viz.ui.menus/src/com/raytheon/uf/viz/ui/menus/DiscoverMenuContributions.java b/cave/com.raytheon.uf.viz.ui.menus/src/com/raytheon/uf/viz/ui/menus/DiscoverMenuContributions.java index c3791e0b14..c9a89f84cb 100644 --- a/cave/com.raytheon.uf.viz.ui.menus/src/com/raytheon/uf/viz/ui/menus/DiscoverMenuContributions.java +++ b/cave/com.raytheon.uf.viz.ui.menus/src/com/raytheon/uf/viz/ui/menus/DiscoverMenuContributions.java @@ -54,7 +54,6 @@ 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.localization.LocalizationManager; import com.raytheon.uf.viz.ui.menus.xml.IncludeMenuItem; /** @@ -78,6 +77,7 @@ import com.raytheon.uf.viz.ui.menus.xml.IncludeMenuItem; * Apr 27, 2012 #562 dgilling Ensure call to MenuCreationJob * uses proper method to retrieve * localized site. + * Mar 20, 2013 1638 mschenke Removed menu creation job use * * * @@ -94,36 +94,15 @@ public class DiscoverMenuContributions { public static Schema schema; public static void discoverContributions() { - discoverContributions(new String[] { "menus" }, true); - } - - public static void discoverContributions(boolean scheduleJob) { - discoverContributions(new String[] { "menus" }, scheduleJob); - } - - public static void discoverContributions(final String[] menuArray) { - discoverContributions(menuArray, true); + discoverContributions(new String[] { "menus" }); } public static synchronized void discoverContributions( - final String[] menuArray, boolean scheduleJob) { + final String[] menuArray) { if (ran) { return; } - if (scheduleJob) { - MenuCreationJob job = new MenuCreationJob(LocalizationManager - .getInstance().getSite()); - - job.schedule(); - try { - job.join(); - } catch (InterruptedException e2) { - statusHandler.handle(Priority.PROBLEM, - e2.getLocalizedMessage(), e2); - } - } - ran = true; try { diff --git a/cave/com.raytheon.viz.ui.personalities.awips/META-INF/MANIFEST.MF b/cave/com.raytheon.viz.ui.personalities.awips/META-INF/MANIFEST.MF index b5eb2acb91..df286feb86 100644 --- a/cave/com.raytheon.viz.ui.personalities.awips/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.viz.ui.personalities.awips/META-INF/MANIFEST.MF @@ -17,6 +17,7 @@ Require-Bundle: org.eclipse.ui, com.raytheon.uf.common.serialization.comm;bundle-version="1.0.0", org.eclipse.core.resources;bundle-version="3.6.0", com.raytheon.uf.viz.ui.menus;bundle-version="1.12.1174", + com.raytheon.uf.common.menus;bundle-version="1.12.1174", com.raytheon.uf.viz.application;bundle-version="1.0.0", com.raytheon.viz.alerts;bundle-version="1.12.1174", com.raytheon.uf.common.comm;bundle-version="1.12.1174" diff --git a/cave/com.raytheon.uf.viz.ui.menus/src/com/raytheon/uf/viz/ui/menus/MenuCreationJob.java b/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/AWIPSWorkbenchAdvisor.java similarity index 57% rename from cave/com.raytheon.uf.viz.ui.menus/src/com/raytheon/uf/viz/ui/menus/MenuCreationJob.java rename to cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/AWIPSWorkbenchAdvisor.java index 1a336c9837..54832355df 100644 --- a/cave/com.raytheon.uf.viz.ui.menus/src/com/raytheon/uf/viz/ui/menus/MenuCreationJob.java +++ b/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/AWIPSWorkbenchAdvisor.java @@ -17,22 +17,18 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.uf.viz.ui.menus; - -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; +package com.raytheon.viz.ui.personalities.awips; import com.raytheon.uf.common.menus.MenuCreationRequest; -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.localization.LocalizationManager; import com.raytheon.uf.viz.core.requests.ThriftClient; /** - * Job to create the menus on demand in CAVE + * AWIPS {@link VizWorkbenchAdvisor} that reqeusts menu creation service to run + * before discovering dynamic menus * *
  * 
@@ -40,43 +36,28 @@ import com.raytheon.uf.viz.core.requests.ThriftClient;
  * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * Jun 23, 2011            mnash     Initial creation
+ * Mar 20, 2013            mschenke     Initial creation
  * 
  * 
* - * @author mnash + * @author mschenke * @version 1.0 */ -public class MenuCreationJob extends Job { - private static final transient IUFStatusHandler statusHandler = UFStatus - .getHandler(MenuCreationJob.class); +public class AWIPSWorkbenchAdvisor extends VizWorkbenchAdvisor { - private String site = ""; - - /** - * - */ - public MenuCreationJob(String site) { - super("Building CAVE menus for " + site + "..."); - this.site = site; - } - - /** - * Run the menu generation code - */ @Override - protected IStatus run(IProgressMonitor monitor) { + protected void createDynamicMenus() { // create the request to send to EDEX to generate the menus MenuCreationRequest request = new MenuCreationRequest(); - request.setSite(site); + request.setSite(LocalizationManager.getInstance().getSite()); try { ThriftClient.sendRequest(request); - } catch (VizException e1) { - statusHandler - .handle(Priority.PROBLEM, e1.getLocalizedMessage(), e1); - return Status.CANCEL_STATUS; + } catch (VizException e) { + UFStatus.getHandler(AWIPSWorkbenchAdvisor.class).handle( + Priority.PROBLEM, e.getLocalizedMessage(), e); } - return Status.OK_STATUS; + super.createDynamicMenus(); } + } diff --git a/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/AbstractCAVEComponent.java b/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/AbstractCAVEComponent.java index c02b576f17..6e16d7cbc4 100644 --- a/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/AbstractCAVEComponent.java +++ b/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/AbstractCAVEComponent.java @@ -255,7 +255,7 @@ public abstract class AbstractCAVEComponent implements IStandaloneComponent { * @return */ protected WorkbenchAdvisor getWorkbenchAdvisor() { - return new VizWorkbenchAdvisor(); + return new AWIPSWorkbenchAdvisor(); } /** diff --git a/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/VizWorkbenchAdvisor.java b/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/VizWorkbenchAdvisor.java index 335cb5c505..90bde5aae5 100644 --- a/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/VizWorkbenchAdvisor.java +++ b/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/VizWorkbenchAdvisor.java @@ -45,6 +45,7 @@ import org.eclipse.ui.contexts.IContextService; import com.raytheon.uf.viz.application.ProgramArguments; import com.raytheon.uf.viz.core.Activator; import com.raytheon.uf.viz.core.preferences.PreferenceConstants; +import com.raytheon.uf.viz.ui.menus.DiscoverMenuContributions; import com.raytheon.viz.ui.VizWorkbenchManager; /** @@ -55,7 +56,8 @@ import com.raytheon.viz.ui.VizWorkbenchManager; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 7/1/06 chammack Initial Creation. - * Mar 5, 2013 1753 njensen Added shutdown printout + * Mar 5, 2013 1753 njensen Added shutdown printout + * Mar 20, 2013 1638 mschenke Added overrideable method for dynamic menu creation * * * @@ -74,6 +76,8 @@ public class VizWorkbenchAdvisor extends WorkbenchAdvisor { protected boolean singlePerspective; + private boolean createdMenus = false; + public VizWorkbenchAdvisor() { performanceListener = CaveCommandExecutionListener.getInstance(); jobChangeListener = CaveJobChangeListener.getInstance(); @@ -292,8 +296,11 @@ public class VizWorkbenchAdvisor extends WorkbenchAdvisor { @Override public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor( IWorkbenchWindowConfigurer configurer) { - return new VizWorkbenchWindowAdvisor(configurer, singlePerspective, - true); + if (createdMenus == false) { + createdMenus = true; + createDynamicMenus(); + } + return new VizWorkbenchWindowAdvisor(configurer, singlePerspective); } /* @@ -330,6 +337,8 @@ public class VizWorkbenchAdvisor extends WorkbenchAdvisor { public void postStartup() { super.postStartup(); + // createDynamicMenus(); + Boolean log = Activator.getDefault().getPreferenceStore() .getBoolean(PreferenceConstants.P_LOG_PERF); @@ -341,6 +350,14 @@ public class VizWorkbenchAdvisor extends WorkbenchAdvisor { service.activateContext("com.raytheon.uf.viz.application.awips"); } + /** + * Uses {@link DiscoverMenuContributions} to create dynamic menu + * contributions + */ + protected void createDynamicMenus() { + DiscoverMenuContributions.discoverContributions(); + } + /** * Toggle whether we are logging or not */ diff --git a/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/VizWorkbenchWindowAdvisor.java b/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/VizWorkbenchWindowAdvisor.java index f7b4755d1d..379c265c96 100644 --- a/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/VizWorkbenchWindowAdvisor.java +++ b/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/VizWorkbenchWindowAdvisor.java @@ -32,7 +32,6 @@ import org.eclipse.ui.application.IActionBarConfigurer; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchWindowAdvisor; -import com.raytheon.uf.viz.ui.menus.DiscoverMenuContributions; import com.raytheon.uf.viz.ui.menus.widgets.tearoff.TearOffMenuListener; import com.raytheon.viz.ui.dialogs.ModeListener; import com.raytheon.viz.ui.perspectives.AbstractVizPerspectiveManager; @@ -48,6 +47,7 @@ import com.raytheon.viz.ui.statusline.VizActionBarAdvisor; * ------------ ---------- ----------- -------------------------- * 7/1/06 chammack Initial Creation. * Oct 21, 2008 #1450 randerso Fixed to support multipane editors + * Mar 20, 2013 1638 mschenke Removed call to DiscoverMenuContributions as now handled in VizWorkbenchAdvisor * * * @@ -68,10 +68,9 @@ public class VizWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { * @param configurer */ public VizWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer, - boolean singlePerspective, boolean createMenuJob) { + boolean singlePerspective) { super(configurer); this.singlePerspective = singlePerspective; - DiscoverMenuContributions.discoverContributions(createMenuJob); } /* diff --git a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/perspectives/AbstractVizPerspectiveManager.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/perspectives/AbstractVizPerspectiveManager.java index 779fd25940..5ff6bdd283 100644 --- a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/perspectives/AbstractVizPerspectiveManager.java +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/perspectives/AbstractVizPerspectiveManager.java @@ -78,7 +78,6 @@ import com.raytheon.viz.ui.tools.ModalToolManager; * @author randerso * @version 1.0 */ - public abstract class AbstractVizPerspectiveManager implements IBackgroundColorChangedListener { private static final transient IUFStatusHandler statusHandler = UFStatus @@ -139,13 +138,17 @@ public abstract class AbstractVizPerspectiveManager implements // update editor on last selected modal tool if (part instanceof IEditorPart && part instanceof IDisplayPaneContainer) { - AbstractVizPerspectiveManager mgr = VizPerspectiveListener - .getCurrentPerspectiveManager(); - if (mgr != null) { - for (AbstractModalTool tool : mgr.getToolManager() - .getSelectedModalTools()) { - if (tool.getCurrentEditor() == part) { - tool.deactivate(); + IWorkbenchPart newPart = part.getSite().getPage() + .getActivePart(); + if (newPart instanceof IEditorPart) { + AbstractVizPerspectiveManager mgr = VizPerspectiveListener + .getCurrentPerspectiveManager(); + if (mgr != null) { + for (AbstractModalTool tool : mgr.getToolManager() + .getSelectedModalTools()) { + if (tool.getCurrentEditor() == part) { + tool.deactivate(); + } } } } @@ -344,7 +347,7 @@ public abstract class AbstractVizPerspectiveManager implements if (activeEditor != null) { page.bringToTop(activeEditor.getPart(false)); activeEditor = null; - } + } // Activate any perspective dialogs activateDialogs();