-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
15 changed files
with
618 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
...elational.ui/src/org/teiid/designer/relational/ui/actions/CreateRelationalViewAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.