Skip to content

Commit

Permalink
TEIIDDES-1559
Browse files Browse the repository at this point in the history
Modified New Base Table... wizard to place location, name, and NIS on top of tabs
Created a New View... wizard using the table wizard with mods to titles, txt and disablement of unsupported keys and constraints.
  • Loading branch information
blafond committed Jan 10, 2013
1 parent 0083a3a commit 056dd99
Show file tree
Hide file tree
Showing 15 changed files with 618 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ public Object run( final UnitOfWork uow ) {
for( Object obj : rootClasses ) {
String className = ((MetamodelRootClass)obj).getEClass().getName();
if( !className.equalsIgnoreCase("BaseTable") && //$NON-NLS-1$
!className.equalsIgnoreCase("Procedure") ) { //$NON-NLS-1$
!className.equalsIgnoreCase("Procedure") && //$NON-NLS-1$
!className.equalsIgnoreCase("View") ) { //$NON-NLS-1$
filteredClasses.add(obj);
}
}
Expand Down Expand Up @@ -3642,7 +3643,8 @@ private Collection getRootDescriptors( final Resource rsrc ) {
for( Object obj : rootClasses ) {
String className = ((MetamodelRootClass)obj).getEClass().getName();
if( !className.equalsIgnoreCase("BaseTable") && //$NON-NLS-1$
!className.equalsIgnoreCase("Procedure")) { //$NON-NLS-1$
!className.equalsIgnoreCase("Procedure") && //$NON-NLS-1$
!className.equalsIgnoreCase("View") ) { //$NON-NLS-1$
filteredClasses.add(obj);
}
}
Expand Down
4 changes: 3 additions & 1 deletion plugins/org.teiid.designer.relational.ui/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ setModelResourceExtendedPropertyDialog.tooltip = Add, edit and delete custom ext
newChildRelationalTableAction=Table...
newSiblingRelationalTableAction=Table...
newChildRelationalProcedureAction=Procedure...
newSiblingRelationalProcedureAction=Procedure...
newSiblingRelationalProcedureAction=Procedure...
newChildRelationalViewAction=View...
newSiblingRelationalViewAction=View...
17 changes: 17 additions & 0 deletions plugins/org.teiid.designer.relational.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,21 @@
name="org.teiid.designer.relational.ui.actions.CreateRelationalProcedureAction">
</class>
</extension>
<extension
id="newChildRelationalViewAction"
name="%newChildRelationalViewAction"
point="org.teiid.designer.ui.newChildAction">
<class
name="org.teiid.designer.relational.ui.actions.CreateRelationalViewAction">
</class>
</extension>

<extension
id="newSiblingRelationalViewAction"
name="%newSiblingRelationalViewAction"
point="org.teiid.designer.ui.newSiblingAction">
<class
name="org.teiid.designer.relational.ui.actions.CreateRelationalViewAction">
</class>
</extension>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,33 @@ public class Messages extends NLS {
public static String editLabel;
public static String fkNameLabel;
public static String descriptionLabel;
//public static String xxxxx;
//public static String xxxxx;
//public static String xxxxx;
public static String nativeQueryLabel;
public static String sqlLabel;

public static String baseTableActionText;
public static String createRelationalTableTitle;
public static String createRelationalTableInitialMessage;
public static String createRelationalTableExceptionMessage;
public static String createRelationalTableHelpText;


public static String viewActionText;
public static String createRelationalViewTitle;
public static String createRelationalViewInitialMessage;
public static String createRelationalViewExceptionMessage;
public static String createRelationalViewHelpText;

public static String createRelationalProcedureActionText;
public static String createRelationalProcedureTitle;
public static String createRelationalProcedureInitialMessage;
public static String createRelationalProcedureExceptionMessage;
public static String createRelationalProcedureHelpText;

public static String nativeQueryHelpText;
public static String nativeQueryNotSupportedForViews;
public static String foreignKeysNotSupportedForViews;
public static String primaryKeysNotSupportedForViews;
public static String uniqueConstraintsNotSupportedForViews;

public static String modelFileLabel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@
*/
public class CreateRelationalTableAction extends Action implements INewChildAction, INewSiblingAction {
private IFile selectedModel;
/**
*
*/
public static final String TITLE = Messages.baseTableActionText;

private Collection<String> datatypes;

/**
*
*/
public CreateRelationalTableAction() {
super(TITLE);
setImageDescriptor(UiPlugin.getDefault().getImageDescriptor( UiConstants.Images.NEW_TABLE_ICON));
Expand Down Expand Up @@ -107,6 +113,10 @@ public boolean canCreateSibling(EObject parent) {
return false;
}

/**
* @param selection the current selection
* @return true if applicable to the selection, else false
*/
public boolean isApplicable(ISelection selection) {
boolean result = false;
if (!SelectionUtilities.isMultiSelection(selection)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.teiid.designer.relational.ui.actions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.teiid.designer.core.ModelerCore;
import org.teiid.designer.core.workspace.ModelResource;
import org.teiid.designer.core.workspace.ModelWorkspaceException;
import org.teiid.designer.relational.model.RelationalModel;
import org.teiid.designer.relational.model.RelationalModelFactory;
import org.teiid.designer.relational.model.RelationalTable;
import org.teiid.designer.relational.model.RelationalView;
import org.teiid.designer.relational.ui.Messages;
import org.teiid.designer.relational.ui.UiConstants;
import org.teiid.designer.relational.ui.UiPlugin;
import org.teiid.designer.relational.ui.edit.EditRelationalObjectDialog;
import org.teiid.designer.type.IDataTypeManagerService;
import org.teiid.designer.ui.actions.INewChildAction;
import org.teiid.designer.ui.actions.INewSiblingAction;
import org.teiid.designer.ui.common.eventsupport.SelectionUtilities;
import org.teiid.designer.ui.editors.ModelEditor;
import org.teiid.designer.ui.editors.ModelEditorManager;
import org.teiid.designer.ui.viewsupport.ModelIdentifier;
import org.teiid.designer.ui.viewsupport.ModelUtilities;

/**
*
*/
public class CreateRelationalViewAction extends Action implements INewChildAction, INewSiblingAction {
private IFile selectedModel;

/**
*
*/
public static final String TITLE = Messages.viewActionText;

private Collection<String> datatypes;

/**
*
*/
public CreateRelationalViewAction() {
super(TITLE);
setImageDescriptor(UiPlugin.getDefault().getImageDescriptor( UiConstants.Images.NEW_TABLE_ICON));

IDataTypeManagerService service = ModelerCore.getTeiidDataTypeManagerService();
Set<String> unsortedDatatypes = service.getAllDataTypeNames();
datatypes = new ArrayList<String>();

String[] sortedStrings = unsortedDatatypes.toArray(new String[unsortedDatatypes.size()]);
Arrays.sort(sortedStrings);
for( String dType : sortedStrings ) {
datatypes.add(dType);
}
}

/* (non-Javadoc)
* @See org.teiid.designer.ui.actions.INewChildAction#canCreateChild(org.eclipse.emf.ecore.EObject)
*/
@Override
public boolean canCreateChild(EObject parent) {
return false;
}

/* (non-Javadoc)
* @See org.teiid.designer.ui.actions.INewChildAction#canCreateChild(org.eclipse.core.resources.IFile)
*/
@Override
public boolean canCreateChild(IFile modelFile) {
return isApplicable(new StructuredSelection(modelFile));
}

/* (non-Javadoc)
* @See org.teiid.designer.ui.actions.INewSiblingAction#canCreateChild(org.eclipse.emf.ecore.EObject)
*/
@Override
public boolean canCreateSibling(EObject parent) {
//Convert eObject selection to IFile
ModelResource mr = ModelUtilities.getModelResourceForModelObject(parent);
if( mr != null ) {
IFile modelFile = null;

try {
modelFile = (IFile)mr.getCorrespondingResource();
} catch (ModelWorkspaceException ex) {
UiConstants.Util.log(ex);
}
if( modelFile != null ) {
return isApplicable(new StructuredSelection(modelFile));
}
}

return false;
}

/**
* @param selection the current selection
* @return true if applicable to the selection, else false
*/
public boolean isApplicable(ISelection selection) {
boolean result = false;
if (!SelectionUtilities.isMultiSelection(selection)) {
Object obj = SelectionUtilities.getSelectedObject(selection);
if (obj instanceof IResource) {
IResource iRes = (IResource) obj;
if (ModelIdentifier.isRelationalSourceModel(iRes)
|| ModelIdentifier.isRelationshipModel(iRes)) {
this.selectedModel = (IFile) obj;
result = true;
}
}
}

return result;
}

@Override
public void run() {
if( selectedModel != null ) {
ModelResource mr = ModelUtilities.getModelResource(selectedModel);
final Shell shell = UiPlugin.getDefault().getCurrentWorkbenchWindow().getShell();

RelationalView table = new RelationalView();
table.setSupportsUpdate(true);

// Hand the table off to the generic edit dialog
EditRelationalObjectDialog dialog = new EditRelationalObjectDialog(shell, table, selectedModel);

dialog.open();

if (dialog.getReturnCode() == Window.OK) {
createTableInTxn(mr, table);
}
}

}

private void createTableInTxn(ModelResource modelResource, RelationalView view) {
boolean requiredStart = ModelerCore.startTxn(true, true, Messages.createRelationalViewTitle, this);
boolean succeeded = false;
try {
ModelEditor editor = ModelEditorManager.getModelEditorForFile((IFile)modelResource.getCorrespondingResource(), true);
if (editor != null) {
boolean isDirty = editor.isDirty();

RelationalModelFactory factory = new RelationalModelFactory();

RelationalModel relModel = new RelationalModel("dummy"); //$NON-NLS-1$
relModel.addChild(view);

factory.build(modelResource, relModel, new NullProgressMonitor());
//factory.buildObject(table, modelResource, new NullProgressMonitor());

if (!isDirty && editor.isDirty()) {
editor.doSave(new NullProgressMonitor());
}
succeeded = true;
}
} catch (Exception e) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.createRelationalViewExceptionMessage, e.getMessage());
IStatus status = new Status(IStatus.ERROR, UiConstants.PLUGIN_ID, Messages.createRelationalViewExceptionMessage, e);
UiConstants.Util.log(status);

return;
} finally {
// if we started the txn, commit it.
if (requiredStart) {
if (succeeded) {
ModelerCore.commitTxn();
} else {
ModelerCore.rollbackTxn();
}
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,11 @@ protected void setStatus(IStatus status) {
public final RelationalReference getRelationalReference() {
return this.relationalObject;
}

/**
* @return the model file
*/
public final IFile getModelFile() {
return this.modelFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.teiid.designer.relational.model.RelationalProcedure;
import org.teiid.designer.relational.model.RelationalReference;
import org.teiid.designer.relational.model.RelationalTable;
import org.teiid.designer.relational.model.RelationalView;
import org.teiid.designer.relational.ui.Messages;

/**
Expand Down Expand Up @@ -47,7 +48,9 @@ public static RelationalEditorPanel getEditorPanel( IDialogStatusListener status
* @return the initial edit dialog message
*/
public static String getInitialMessage(RelationalReference relationalObject) {
if( relationalObject instanceof RelationalTable ) {
if( relationalObject instanceof RelationalView ) {
return Messages.createRelationalViewInitialMessage;
} else if( relationalObject instanceof RelationalTable ) {
return Messages.createRelationalTableInitialMessage;
} else if( relationalObject instanceof RelationalProcedure ) {
return Messages.createRelationalProcedureInitialMessage;
Expand All @@ -61,12 +64,30 @@ public static String getInitialMessage(RelationalReference relationalObject) {
* @return the initial edit dialog message
*/
public static String getDialogTitle(RelationalReference relationalObject) {
if( relationalObject instanceof RelationalTable ) {
if( relationalObject instanceof RelationalView ) {
return Messages.createRelationalViewTitle;
} else if( relationalObject instanceof RelationalTable ) {
return Messages.createRelationalTableTitle;
} else if( relationalObject instanceof RelationalProcedure ) {
return Messages.createRelationalProcedureTitle;
}

return NLS.bind(Messages.unsupportedObjectType, relationalObject.getClass().toString());
}

/**
* @param relationalObject the object to edit
* @return the initial edit dialog message
*/
public static String getHelpText(RelationalReference relationalObject) {
if( relationalObject instanceof RelationalView ) {
return Messages.createRelationalViewHelpText;
} else if( relationalObject instanceof RelationalTable ) {
return Messages.createRelationalTableHelpText;
} else if( relationalObject instanceof RelationalProcedure ) {
return Messages.createRelationalProcedureHelpText;
}

return NLS.bind(Messages.unsupportedObjectType, relationalObject.getClass().toString());
}
}

0 comments on commit 056dd99

Please sign in to comment.