Skip to content

Commit

Permalink
Merge pull request #72 from mdrillin/TEIIDDES-1288
Browse files Browse the repository at this point in the history
TEIIDDES-1288
  • Loading branch information
blafond committed Jan 7, 2013
2 parents c7c0b42 + 4a61b58 commit a63c26f
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 8 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.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package org.teiid.datatools.connectivity.ui;

import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
Expand Down Expand Up @@ -69,6 +70,41 @@ public static Activator getDefault() {
return plugin;
}

/**
* Retrieves the image descriptor associated with the specified key from the {@link org.eclipse.jface.resource.ImageRegistry
* image registry}, creating the descriptor and registering it if it doesn't already exist. A null key will cause the
* descriptor for the "No image" image to be returned.
*
* @param key The key associated with the image descriptor to retrieve. This must be in the form of the path to the image file
* relative to this plug-in's folder; may be null.
* @return The image descriptor associated with the specified key.
* @since 4.0
*/
public final ImageDescriptor getImageDescriptor( final String key ) {
final ImageRegistry registry = getImageRegistry();
final ImageDescriptor descriptor = registry.getDescriptor(key);
if (descriptor != null) {
return descriptor;
}
return createImageDescriptor(key);
}

/**
* @since 4.0
*/
private ImageDescriptor createImageDescriptor( final String key ) {
try {
final URL url = new URL(getBundle().getEntry("/").toString() + key); //$NON-NLS-1$
final ImageDescriptor descriptor = ImageDescriptor.createFromURL(url);
final ImageRegistry registry = getImageRegistry();
registry.put(key, descriptor);
return descriptor;
} catch (final MalformedURLException err) {
plugin.log(err);
return null;
}
}

@Override
protected void initializeImageRegistry(ImageRegistry registry) {
Bundle bundle = Platform.getBundle(PLUGIN_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,18 @@ ExecutionPlanView.collapseAllButton.text=Collapse All
ExecutionPlanView.collapseAllButton.tooltip=Collapse All Execution Plan nodes.
ExecutionPlanView.savePlanToFileButton.text=Save Plan...
ExecutionPlanView.savePlanToFileButton.tooltip=Save Execution Plan XML to a file.
ExecutionPlanView.readPlanFromFileButton.text=Import Plan...
ExecutionPlanView.readPlanFromFileButton.tooltip=Import Execution Plan XML from a file.

ExecutionPlanView.savePlanDialog.title=Save Execution Plan XML
ExecutionPlanView.savePlanDialog.defaultFileName=executionPlan.xml
ExecutionPlanView.savePlanDialog.defaultFileExt=xml
ExecutionPlanView.savePlanDialog.saveError=Error saving the Execution Plan File

ExecutionPlanView.importPlanDialog.title=Import Execution Plan XML
ExecutionPlanView.importPlanDialog.defaultFileName=executionPlan.xml
ExecutionPlanView.importPlanDialog.error=Error importing the Execution Plan File

ExecutionPlanView.readPlanFromFile.sql=Unknown: Plan was imported from a file
ExecutionPlanView.readPlanFromFile.description=Plan Description

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.teiid.datatools.views;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.Action;
Expand All @@ -30,8 +31,6 @@
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.help.IWorkbenchHelpSystem;
import org.eclipse.ui.part.ViewPart;
import org.teiid.datatools.connectivity.ui.Activator;
Expand All @@ -46,6 +45,9 @@
public class ExecutionPlanView extends ViewPart {
public static final String VIEW_ID = "views.executionPlanView"; //$NON-NLS-1$

private static final String IMPORT_PLAN_IMG = "icons/import_from_file.gif"; //$NON-NLS-1$
private static final String EXPORT_PLAN_IMG = "icons/export_to_file.gif"; //$NON-NLS-1$

private static final String EXECUTION_PLAN_HELP_ID = "org.teiid.designer.runtime.ui.executionPlanOverview"; //$NON-NLS-1$
private static final String PREFIX = "ExecutionPlanView."; //$NON-NLS-1$

Expand All @@ -57,6 +59,7 @@ public class ExecutionPlanView extends ViewPart {
private String planString;

private IAction saveToFileAction;
private IAction readFromFileAction;

Button expandAll;
Button collapseAll;
Expand Down Expand Up @@ -96,6 +99,8 @@ public void setFocus() {

private void configureToolBar( IToolBarManager toolBarMgr ) {
toolBarMgr.add(this.saveToFileAction);
toolBarMgr.add(this.readFromFileAction);

toolBarMgr.update(true);
}

Expand All @@ -116,7 +121,25 @@ public void run() {
};
this.saveToFileAction.setToolTipText(savePlanToFileActionTooltip);
this.saveToFileAction.setEnabled(false);
this.saveToFileAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
this.saveToFileAction.setImageDescriptor(Activator.getDefault().getImageDescriptor(EXPORT_PLAN_IMG));

String readPlanFromFileActionText = Messages.getString(PREFIX + "readPlanFromFileButton.text"); //$NON-NLS-1$
String readPlanFromFileActionTooltip = Messages.getString(PREFIX + "readPlanFromFileButton.tooltip"); //$NON-NLS-1$

this.readFromFileAction = new Action(readPlanFromFileActionText, SWT.BORDER) {
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
handleReadPlanFromFile();
}
};
this.readFromFileAction.setToolTipText(readPlanFromFileActionTooltip);
this.readFromFileAction.setEnabled(true);
this.readFromFileAction.setImageDescriptor(Activator.getDefault().getImageDescriptor(IMPORT_PLAN_IMG));
}

/*
Expand Down Expand Up @@ -328,7 +351,7 @@ private String getNodeDisplayName( PlanElement element ) {
return displayName;
}

/*
/**
* Save the current Execution Plan xml to a file.
*/
public void handleSavePlanToFile() {
Expand Down Expand Up @@ -370,8 +393,59 @@ public void handleSavePlanToFile() {
}
}
}

/**
* Save the current Execution Plan xml to a file.
*/
public void handleReadPlanFromFile() {
Shell shell = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// Shell shell = UiPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
FileDialog dlg = new FileDialog(shell, SWT.OPEN);
dlg.setFilterExtensions(new String[] {"*.xml", "*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
dlg.setText(Messages.getString(PREFIX + "importPlanDialog.title")); //$NON-NLS-1$
dlg.setFileName(Messages.getString(PREFIX + "importPlanDialog.defaultFileName")); //$NON-NLS-1$
String fileStr = dlg.open();

if (fileStr != null) {
FileReader fr = null;
BufferedReader in = null;
try {
fr = new FileReader(fileStr);
in = new BufferedReader(fr);
String str;
StringBuffer all = new StringBuffer();
while ((str = in.readLine()) != null) {
all.append(str);
}
String planText = all.toString();
String sqlStr = Messages.getString(PREFIX + "readPlanFromFile.sql"); //$NON-NLS-1$
String descriptionStr = Messages.getString(PREFIX + "readPlanFromFile.description"); //$NON-NLS-1$

updateContents(descriptionStr,sqlStr,planText);

/*
} catch (Exception e) {
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
Messages.getString(PREFIX + "importPlanDialog.error"), e); //$NON-NLS-1$
Activator.getDefault().getLog().log(status);
} finally {
try {
if (fr != null) {
fr.close();
}
} catch (java.io.IOException e) {
}
try {
if (in != null) {
in.close();
}
} catch (java.io.IOException e) {
}

}
}
}

/**
* Update the state of the ExecutionPlan panel
* @param description the text description for the panel
* @param sql the SQL to display
Expand All @@ -382,7 +456,11 @@ public void updateContents( String description,
String planStr ) {
this.planString = planStr;
// Update the Object Name Label
panelDescriptionLabel.setText(description);
if(description!=null) {
panelDescriptionLabel.setText(description);
} else {
panelDescriptionLabel.setText(""); //$NON-NLS-1$
}

// Update the SQL String
if (sql != null) {
Expand Down Expand Up @@ -420,7 +498,7 @@ public void updateContents( String description,
/*
* Update the button enabled states.
*/
public void updateButtonEnablements() {
private void updateButtonEnablements() {
if (this.planString != null) {
this.saveToFileAction.setEnabled(true);
this.expandAll.setEnabled(true);
Expand Down

0 comments on commit a63c26f

Please sign in to comment.