Skip to content

Commit

Permalink
TEIIDDES-2098 Added New... drop-down action to Model Explorer Toolbar
Browse files Browse the repository at this point in the history
* Includes New Project, New VDB and New XXXXX Model actions
  • Loading branch information
blafond committed Apr 2, 2014
1 parent 5437695 commit 729ab19
Show file tree
Hide file tree
Showing 11 changed files with 231 additions and 0 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ interface Images extends UiConstants.Images {

String TEIID_SERVER_DEFAULT_ICON = CVIEW16 + "teiid-server-default.png"; //$NON-NLS-1$
String TEIID_SERVER_DISCONNECTED_ICON = CVIEW16 + "teiid-server-disconnected.png"; //$NON-NLS-1$

String NEW_WIZARD_ICON = OBJ16 + "new-wizard.png"; //$NON-NLS-1$
String NEW_MODEL_PROJECT_ICON = OBJ16 + "new-model-project.png"; //$NON-NLS-1$
String NEW_SOURCE_MODEL_ICON = OBJ16 + "new-source-model.png"; //$NON-NLS-1$
String NEW_VIEW_MODEL_ICON = OBJ16 + "new-view-model.png"; //$NON-NLS-1$
String NEW_WEB_SERVICE_MODEL_ICON = OBJ16 + "new-web-service-model.png"; //$NON-NLS-1$
String NEW_XML_DOCUMENT_MODEL_ICON = OBJ16 + "new-xml-document-model.png"; //$NON-NLS-1$
String NEW_VDB_ICON = OBJ16 + "newvdb_wiz.gif"; //$NON-NLS-1$
}

// ======================================================================================================
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
package org.teiid.designer.ui.explorer;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuCreator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IWorkbenchWindow;
import org.teiid.designer.metamodels.core.ModelType;
import org.teiid.designer.ui.PluginConstants;
import org.teiid.designer.ui.UiConstants;
import org.teiid.designer.ui.UiPlugin;
import org.teiid.designer.ui.common.product.ProductCustomizerMgr;
import org.teiid.designer.ui.viewsupport.DesignerPropertiesUtil;
import org.teiid.designer.ui.viewsupport.IPropertiesContext;
import org.teiid.designer.ui.viewsupport.ModelerUiViewUtils;
import org.teiid.designer.ui.wizards.NewModelWizard;
import org.teiid.designer.ui.wizards.NewModelWizardInput;

public class ModelExplorerNewAction extends Action implements IMenuCreator{
static final String RELATIONAL = "Relational"; //$NON-NLS-1$
static final String XML = "XML"; //$NON-NLS-1$
static final String XML_SCHEMA = "XML Schema (XSD)"; //$NON-NLS-1$
static final String WEB_SERVICE = "Web Service"; //$NON-NLS-1$
static final String FUNCTION = "Function"; //$NON-NLS-1$

private List<IAction> actions;



public ModelExplorerNewAction() {
super("", SWT.DROP_DOWN);
setImageDescriptor(UiPlugin.getDefault().getImageDescriptor(PluginConstants.Images.NEW_MODEL_PROJECT_ICON));
actions = createActions();
setMenuCreator(this);

setToolTipText("New..."); //$NON-NLS-1$
}

@Override
public void run() {
// TODO Auto-generated method stub
ModelerUiViewUtils.launchWizard("newModelProject", new StructuredSelection(), new Properties(), false); //$NON-NLS-1$
}

/**
* Helper method that wraps the given action in an ActionContributionItem
* and then adds it to the given menu.
*
* @param parent
* The menu to which the given action is to be added
* @param action
* The action that is to be added to the given menu
*/
protected void addActionToMenu(Menu parent, IAction action) {
ActionContributionItem item = new ActionContributionItem(action);
item.fill(parent, -1);
}

/**
* @return A list of actions that can switch to one of the supported layout
* modes
*/
protected List<IAction> createActions() {
ArrayList<IAction> list = new ArrayList<IAction>();

list.add( new Action("New Model Project", UiPlugin.getDefault().getImageDescriptor(PluginConstants.Images.NEW_MODEL_PROJECT_ICON)) {

@Override
public void run() {
ModelerUiViewUtils.launchWizard("newModelProject", new StructuredSelection(), new Properties(), false); //$NON-NLS-1$
}

});

list.add( new Action("New Source Model", UiPlugin.getDefault().getImageDescriptor(PluginConstants.Images.NEW_SOURCE_MODEL_ICON)) {

@Override
public void run() {
launchNewModelWizard(ModelType.PHYSICAL_LITERAL, RELATIONAL, new Properties());
}

});
list.add( new Action("New View Model", UiPlugin.getDefault().getImageDescriptor(PluginConstants.Images.NEW_VIEW_MODEL_ICON)) {

@Override
public void run() {
launchNewModelWizard(ModelType.VIRTUAL_LITERAL, RELATIONAL, new Properties());
}

});
list.add( new Action("New Web Service Model", UiPlugin.getDefault().getImageDescriptor(PluginConstants.Images.NEW_WEB_SERVICE_MODEL_ICON)) {

@Override
public void run() {
launchNewModelWizard(ModelType.VIRTUAL_LITERAL, WEB_SERVICE, new Properties());
}

});
list.add( new Action("New XML Document Model", UiPlugin.getDefault().getImageDescriptor(PluginConstants.Images.NEW_XML_DOCUMENT_MODEL_ICON)) {

@Override
public void run() {
launchNewModelWizard(ModelType.VIRTUAL_LITERAL, XML, new Properties());
}

});
list.add( new Action("New VDB", UiPlugin.getDefault().getImageDescriptor(PluginConstants.Images.NEW_VDB_ICON)) {

@Override
public void run() {
ModelerUiViewUtils.launchWizard("newVdbWizard", new StructuredSelection(), new Properties(), false); //$NON-NLS-1$
}

});

return list;
}

@Override
public void dispose() {
// TODO Auto-generated method stub

}

private Menu fillMenu(Menu menu) {
for (IAction action : actions) {
addActionToMenu(menu, action);
}

setEnabled(!actions.isEmpty());

return menu;
}

/**
* @see org.eclipse.jface.action.IMenuCreator#getMenu(Control)
*/
public Menu getMenu(Control parent) {
return fillMenu(new Menu(parent));
}

/**
* @see org.eclipse.jface.action.IMenuCreator#getMenu(Menu)
*/
public Menu getMenu(Menu parent) {
return fillMenu(new Menu(parent));
}

void launchNewModelWizard(ModelType type, String modelClass, Properties props) {
final IWorkbenchWindow iww = UiPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
boolean successful = false;
try {

;
NewModelWizard wizard = new NewModelWizard(new NewModelWizardInput(modelClass, type, null), props);

String viewId = ProductCustomizerMgr.getInstance().getProductCharacteristics().getPrimaryNavigationViewId();
ISelection theSelection = iww.getSelectionService().getSelection(viewId);

wizard.init(iww.getWorkbench(), (IStructuredSelection)theSelection);
WizardDialog dialog = new WizardDialog(iww.getShell(), wizard);
wizard.updateForProperties();

String openProjectStatus = DesignerPropertiesUtil.getProjectStatus(props);
if( openProjectStatus == null || !IPropertiesContext.NO_OPEN_PROJECT.equalsIgnoreCase(openProjectStatus) ){
int result = dialog.open();
if (result == Window.OK) {
successful = true;
}
} else {
return;
}
} catch (Exception e) {
UiConstants.Util.log(IStatus.ERROR, e, e.getMessage());
MessageDialog.openError(iww.getShell(), "New Model Error", e.getMessage());
} finally {
notifyResult(successful);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
package org.teiid.designer.ui.explorer;

import java.util.ArrayList;
import java.util.Collection;
import java.util.EventObject;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
Expand All @@ -35,6 +37,7 @@
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuCreator;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
Expand Down Expand Up @@ -65,6 +68,7 @@
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
Expand Down Expand Up @@ -100,6 +104,9 @@
import org.eclipse.ui.part.PluginTransfer;
import org.eclipse.ui.part.ResourceTransfer;
import org.eclipse.ui.part.ShowInContext;
import org.eclipse.ui.views.framelist.BackAction;
import org.eclipse.ui.views.framelist.ForwardAction;
import org.eclipse.ui.views.framelist.GoIntoAction;
import org.eclipse.ui.views.navigator.NavigatorDropAdapter;
import org.eclipse.ui.views.navigator.ResourceNavigator;
import org.eclipse.ui.views.properties.IPropertySheetPage;
Expand Down Expand Up @@ -519,6 +526,25 @@ public void run() {
UndoActionHandler undoAction = new UndoActionHandler(getSite(), undoContext);
undoAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_UNDO);
getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);

IContributionItem[] items = bars.getToolBarManager().getItems();
Collection<IContributionItem> itemsToRemove = new ArrayList<IContributionItem>();
for( IContributionItem item : items ) {
if( item instanceof ActionContributionItem ) {
if( ((ActionContributionItem)item).getAction() instanceof BackAction) {
itemsToRemove.add(item);
}
if( ((ActionContributionItem)item).getAction() instanceof ForwardAction) {
itemsToRemove.add(item);
}
if( ((ActionContributionItem)item).getAction() instanceof GoIntoAction) {
itemsToRemove.add(item);
}
}
}
for( IContributionItem item : itemsToRemove ) {
bars.getToolBarManager().remove(item);
}
}

/**
Expand Down Expand Up @@ -774,9 +800,12 @@ protected void makeActions() {
getViewSite().getActionBars().getMenuManager().add(new GroupMarker(MENU_START_ID));
getViewSite().getActionBars().getMenuManager().add(new ShowImportsAction());

getViewSite().getActionBars().getToolBarManager().add(new ModelExplorerNewAction());

// Preview Data Action from DQP Ui. If Exists, place in toolbar
IAction previewAction = getPreviewDataAction();
if (previewAction != null) {
getViewSite().getActionBars().getToolBarManager().add(new Separator());
getViewSite().getActionBars().getToolBarManager().add(previewAction);
getViewSite().getActionBars().getToolBarManager().add(new Separator());
}
Expand Down

0 comments on commit 729ab19

Please sign in to comment.