RMB "Deploy Files Open in Editor..." on Database node to deploy plsql files already open in the editor and some FindBugs suggested changes.
1.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/actions/Bundle.properties Thu Jun 07 16:37:59 2012 +0200
1.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/actions/Bundle.properties Mon Jun 11 10:51:08 2012 +0530
1.3 @@ -2,6 +2,7 @@
1.4 # and open the template in the editor.
1.5 LBL_DatabaseNodeName=Database
1.6 CTL_DeployFilesAction=Deploy Files...
1.7 +CTL_DeployFilesOpenInEditorAction=Deploy Files Open in Editor...
1.8 CTL_DeploySelectedCodeAction=Deploy Selection
1.9 LBL_DeployDialogTitle=Select Files to Deploy
1.10 -
1.11 +OpenPlsqlFilesSelectorPanel.lblOpenFiles.text=Files Open In Editor
2.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/actions/DeployFilesAction.java Thu Jun 07 16:37:59 2012 +0200
2.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/actions/DeployFilesAction.java Mon Jun 11 10:51:08 2012 +0530
2.3 @@ -41,32 +41,34 @@
2.4 */
2.5 package org.netbeans.modules.plsql.execution.actions;
2.6
2.7 -import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
2.8 +import java.io.File;
2.9 +import java.io.IOException;
2.10 +import java.util.List;
2.11 +import java.util.Locale;
2.12 +import javax.swing.JFileChooser;
2.13 +import javax.swing.text.Document;
2.14 +import org.netbeans.api.db.explorer.DatabaseConnection;
2.15 +import org.netbeans.api.progress.ProgressHandle;
2.16 +import org.netbeans.api.progress.ProgressHandleFactory;
2.17 +import org.netbeans.api.project.Project;
2.18 import org.netbeans.modules.plsql.execution.PlsqlExecutableBlocksMaker;
2.19 import org.netbeans.modules.plsql.execution.PlsqlFileExecutor;
2.20 import org.netbeans.modules.plsql.utilities.PlsqlExecutorService;
2.21 -import java.io.IOException;
2.22 -import javax.swing.text.Document;
2.23 -import org.netbeans.api.progress.ProgressHandle;
2.24 -import org.netbeans.api.progress.ProgressHandleFactory;
2.25 -import org.netbeans.api.project.Project;
2.26 +import org.netbeans.modules.plsqlsupport.db.DatabaseConnectionManager;
2.27 +import org.openide.DialogDescriptor;
2.28 +import org.openide.DialogDisplayer;
2.29 import org.openide.cookies.EditorCookie;
2.30 +import org.openide.filesystems.FileUtil;
2.31 import org.openide.loaders.DataObject;
2.32 import org.openide.nodes.Node;
2.33 import org.openide.util.Cancellable;
2.34 import org.openide.util.Exceptions;
2.35 import org.openide.util.HelpCtx;
2.36 +import org.openide.util.Lookup;
2.37 import org.openide.util.NbBundle;
2.38 +import org.openide.util.RequestProcessor;
2.39 import org.openide.util.Task;
2.40 import org.openide.util.actions.CookieAction;
2.41 -import java.io.File;
2.42 -import java.util.List;
2.43 -import java.util.Locale;
2.44 -import javax.swing.JFileChooser;
2.45 -import org.netbeans.api.db.explorer.DatabaseConnection;
2.46 -import org.openide.filesystems.FileUtil;
2.47 -import org.openide.util.Lookup;
2.48 -import org.openide.util.RequestProcessor;
2.49 import org.openide.windows.IOProvider;
2.50 import org.openide.windows.InputOutput;
2.51 import org.openide.windows.OutputEvent;
2.52 @@ -76,209 +78,259 @@
2.53 *
2.54 * @author csamlk
2.55 */
2.56 -public class DeployFilesAction extends CookieAction {
2.57 +public abstract class DeployFilesAction extends CookieAction {
2.58
2.59 - private static final PlsqlExecutorService executorService = Lookup.getDefault().lookup(PlsqlExecutorService.class);
2.60 + private static final PlsqlExecutorService executorService = Lookup.getDefault().lookup(PlsqlExecutorService.class);
2.61 private static final RequestProcessor RP = new RequestProcessor(DeployFilesAction.class);
2.62 - private Project project;
2.63 - //private DatabaseConnection connection;
2.64 - private Node[] activatedNodes;
2.65 - private static File lastLocation = null;
2.66 + private Project project;
2.67 + private Node[] activatedNodes;
2.68
2.69 - @Override
2.70 - protected int mode() {
2.71 - return CookieAction.MODE_EXACTLY_ONE;
2.72 - }
2.73 + @Override
2.74 + protected int mode() {
2.75 + return CookieAction.MODE_EXACTLY_ONE;
2.76 + }
2.77
2.78 - @Override
2.79 - protected Class<?>[] cookieClasses() {
2.80 - return new Class[]{Project.class};
2.81 - }
2.82 + @Override
2.83 + protected Class<?>[] cookieClasses() {
2.84 + return new Class[]{Project.class};
2.85 + }
2.86
2.87 - @Override
2.88 - protected void performAction(Node[] arg0) {
2.89 - final JFileChooser fc = new JFileChooser();
2.90 - fc.setMultiSelectionEnabled(true);
2.91 - fc.setCurrentDirectory(lastLocation);
2.92 - fc.setDialogTitle(NbBundle.getMessage(DeployFilesAction.class, "LBL_DeployDialogTitle"));
2.93 - fc.setApproveButtonText("OK");
2.94 - File[] files = null;
2.95 - int returnVal = fc.showOpenDialog(null);
2.96 + protected abstract File[] getFilesToDeploy();
2.97
2.98 - if (returnVal == JFileChooser.APPROVE_OPTION) {
2.99 - files = fc.getSelectedFiles();
2.100 - lastLocation = fc.getCurrentDirectory();
2.101 - }
2.102 + @Override
2.103 + protected boolean asynchronous() {
2.104 + return false;
2.105 + }
2.106
2.107 - if (files != null) {
2.108 - try {
2.109 - execute(files);
2.110 - } catch (IOException ex) {
2.111 - Exceptions.printStackTrace(ex);
2.112 - }
2.113 - }
2.114 - }
2.115 + @Override
2.116 + protected void performAction(Node[] arg0) {
2.117 + File[] files = getFilesToDeploy();
2.118 + if (files != null && files.length > 0) {
2.119 + try {
2.120 + execute(files);
2.121 + } catch (IOException ex) {
2.122 + Exceptions.printStackTrace(ex);
2.123 + }
2.124 + }
2.125 + }
2.126
2.127 - @Override
2.128 - public String getName() {
2.129 - return NbBundle.getMessage(DeployFilesAction.class, "CTL_DeployFilesAction");
2.130 - }
2.131 + @Override
2.132 + public abstract String getName();
2.133
2.134 - @Override
2.135 - public HelpCtx getHelpCtx() {
2.136 - return HelpCtx.DEFAULT_HELP;
2.137 - }
2.138 + @Override
2.139 + public HelpCtx getHelpCtx() {
2.140 + return HelpCtx.DEFAULT_HELP;
2.141 + }
2.142
2.143 - @Override
2.144 - protected boolean enable(Node[] activatedNodes) {
2.145 - this.activatedNodes = activatedNodes;
2.146 - if (!super.enable(activatedNodes)) {
2.147 - return false;
2.148 - }
2.149 + @Override
2.150 + protected boolean enable(Node[] activatedNodes) {
2.151 + this.activatedNodes = activatedNodes;
2.152 + if (!super.enable(activatedNodes)) {
2.153 + return false;
2.154 + }
2.155
2.156 - Project p = activatedNodes[0].getLookup().lookup(Project.class);
2.157 + Project p = activatedNodes[0].getLookup().lookup(Project.class);
2.158
2.159 - return DatabaseConnectionManager.getInstance(p).isOnline();
2.160 - }
2.161 + return DatabaseConnectionManager.getInstance(p).isOnline();
2.162 + }
2.163
2.164 - static void execute(DatabaseConnection connection, DatabaseConnectionManager connectionProvider, File[] files, boolean isTemporyFile) throws IOException {
2.165 - if (connection == null || connection.getJDBCConnection() == null) {
2.166 - return;
2.167 - }
2.168 - RP.post(new MultipleDbFileExecutionHandler(connection, connectionProvider, files, isTemporyFile));
2.169 - }
2.170 + static void execute(DatabaseConnection connection, DatabaseConnectionManager connectionProvider, File[] files, boolean isTemporyFile) throws IOException {
2.171 + if (connection == null || connection.getJDBCConnection() == null) {
2.172 + return;
2.173 + }
2.174 + RP.post(new MultipleDbFileExecutionHandler(connection, connectionProvider, files, isTemporyFile));
2.175 + }
2.176
2.177 - private void execute(File[] files) throws IOException {
2.178 - DatabaseConnectionManager connectionProvider = null;
2.179 - project = activatedNodes[0].getLookup().lookup(Project.class);
2.180 + private void execute(File[] files) throws IOException {
2.181 + DatabaseConnectionManager connectionProvider = null;
2.182 + project = activatedNodes[0].getLookup().lookup(Project.class);
2.183
2.184 - connectionProvider = DatabaseConnectionManager.getInstance(project);
2.185 - RP.post(new MultipleDbFileExecutionHandler(connectionProvider, files));
2.186 - }
2.187 + connectionProvider = DatabaseConnectionManager.getInstance(project);
2.188 + RP.post(new MultipleDbFileExecutionHandler(connectionProvider, files));
2.189 + }
2.190
2.191 - private static class DeploymentError implements OutputListener {
2.192 + private static class DeploymentError implements OutputListener {
2.193
2.194 - private InputOutput errorTab;
2.195 + private InputOutput errorTab;
2.196
2.197 - public DeploymentError(InputOutput errorTab) {
2.198 - this.errorTab = errorTab;
2.199 - }
2.200 + public DeploymentError(InputOutput errorTab) {
2.201 + this.errorTab = errorTab;
2.202 + }
2.203
2.204 - @Override
2.205 - public void outputLineSelected(OutputEvent arg0) {
2.206 - //do nothing
2.207 - }
2.208 + @Override
2.209 + public void outputLineSelected(OutputEvent arg0) {
2.210 + //do nothing
2.211 + }
2.212
2.213 - @Override
2.214 - public void outputLineAction(OutputEvent arg0) {
2.215 - if (errorTab != null && !errorTab.isClosed()) {
2.216 - errorTab.select();
2.217 - }
2.218 - }
2.219 + @Override
2.220 + public void outputLineAction(OutputEvent arg0) {
2.221 + if (errorTab != null && !errorTab.isClosed()) {
2.222 + errorTab.select();
2.223 + }
2.224 + }
2.225
2.226 - @Override
2.227 - public void outputLineCleared(OutputEvent arg0) {
2.228 - //do nothing
2.229 - }
2.230 - }
2.231 + @Override
2.232 + public void outputLineCleared(OutputEvent arg0) {
2.233 + //do nothing
2.234 + }
2.235 + }
2.236
2.237 - private static class MultipleDbFileExecutionHandler implements Runnable, Cancellable {
2.238 + private static class MultipleDbFileExecutionHandler implements Runnable, Cancellable {
2.239
2.240 - private PlsqlFileExecutor executor;
2.241 - private boolean cancelDeployment = false;
2.242 - private final DatabaseConnectionManager connectionProvider;
2.243 - private DatabaseConnection connection = null;
2.244 - private final File[] files;
2.245 - private boolean isTemporyFile = false;
2.246 + private PlsqlFileExecutor executor;
2.247 + private boolean cancelDeployment = false;
2.248 + private final DatabaseConnectionManager connectionProvider;
2.249 + private DatabaseConnection connection = null;
2.250 + private final File[] files;
2.251 + private boolean isTemporyFile = false;
2.252
2.253 - public MultipleDbFileExecutionHandler(DatabaseConnectionManager connectionProvider, File[] files) {
2.254 - this.connectionProvider = connectionProvider;
2.255 - this.connection = null;
2.256 - this.files = files;
2.257 - }
2.258 + public MultipleDbFileExecutionHandler(DatabaseConnectionManager connectionProvider, File[] files) {
2.259 + this.connectionProvider = connectionProvider;
2.260 + this.connection = null;
2.261 + this.files = files;
2.262 + }
2.263
2.264 - public MultipleDbFileExecutionHandler(DatabaseConnection connection, DatabaseConnectionManager connectionProvider, File[] files, boolean isTemporyFile) {
2.265 - this.connectionProvider = connectionProvider;
2.266 - this.connection = connection;
2.267 - this.files = files;
2.268 - this.isTemporyFile = isTemporyFile;
2.269 - }
2.270 + public MultipleDbFileExecutionHandler(DatabaseConnection connection, DatabaseConnectionManager connectionProvider, File[] files, boolean isTemporyFile) {
2.271 + this.connectionProvider = connectionProvider;
2.272 + this.connection = connection;
2.273 + this.files = files;
2.274 + this.isTemporyFile = isTemporyFile;
2.275 + }
2.276
2.277 - @Override
2.278 - public void run() {
2.279 - List<String> executionOrder = executorService.getExecutionOrder();
2.280 - ProgressHandle handle = ProgressHandleFactory.createHandle("Deploying to database...", (Cancellable) this);
2.281 - cancelDeployment = false;
2.282 - //check if we're deploying to the "main" database. If so get a connection from the cache instead of using the "main" connection.
2.283 - if (connectionProvider != null && (connection == null || connection == connectionProvider.getTemplateConnection())) {
2.284 - connection = connectionProvider.getPooledDatabaseConnection(false);
2.285 - }
2.286 - try {
2.287 - handle.start();
2.288 - int count = 0;
2.289 - InputOutput io = IOProvider.getDefault().getIO("Deployment summary", false);
2.290 - io.getOut().reset();
2.291 - if (isTemporyFile) {
2.292 - io.getOut().println("Deploying to database");
2.293 - } else {
2.294 - io.getOut().println("Deploying database files");
2.295 + @Override
2.296 + public void run() {
2.297 + List<String> executionOrder = executorService.getExecutionOrder();
2.298 + ProgressHandle handle = ProgressHandleFactory.createHandle("Deploying to database...", (Cancellable) this);
2.299 + cancelDeployment = false;
2.300 + //check if we're deploying to the "main" database. If so get a connection from the cache instead of using the "main" connection.
2.301 + if (connectionProvider != null && (connection == null || connection == connectionProvider.getTemplateConnection())) {
2.302 + connection = connectionProvider.getPooledDatabaseConnection(false);
2.303 }
2.304 - executor = new PlsqlFileExecutor(connectionProvider, connection);
2.305 - for (int typeIndex = 0; !cancelDeployment && typeIndex < executionOrder.size(); typeIndex++) {
2.306 - for (int i = 0; !cancelDeployment && i < files.length; i++) {
2.307 - String fileName = files[i].getAbsolutePath();
2.308 - DataObject obj = DataObject.find(FileUtil.toFileObject(files[i]));
2.309 - if (obj != null) {
2.310 - if (fileName.toLowerCase(Locale.ENGLISH).endsWith(executionOrder.get(typeIndex))) {
2.311 - //Load the editor cookier and allow parsing
2.312 - EditorCookie ec = obj.getCookie(EditorCookie.class);
2.313 - Task task = ec.prepareDocument();
2.314 - task.waitFinished();
2.315 - Document doc = ec.getDocument();
2.316 - PlsqlExecutableBlocksMaker blockMaker = new PlsqlExecutableBlocksMaker(doc);
2.317 - final List exeBlocks = blockMaker.makeExceutableObjects();
2.318 - if (isTemporyFile) {
2.319 - io.getOut().print("> Deploying...");
2.320 - } else {
2.321 - io.getOut().print("> Deploying " + fileName + "...");
2.322 + try {
2.323 + handle.start();
2.324 + int count = 0;
2.325 + InputOutput io = IOProvider.getDefault().getIO("Deployment summary", false);
2.326 + io.getOut().reset();
2.327 + if (isTemporyFile) {
2.328 + io.getOut().println("Deploying to database");
2.329 + } else {
2.330 + io.getOut().println("Deploying database files");
2.331 + }
2.332 + executor = new PlsqlFileExecutor(connectionProvider, connection);
2.333 + for (int typeIndex = 0; !cancelDeployment && typeIndex < executionOrder.size(); typeIndex++) {
2.334 + for (int i = 0; !cancelDeployment && i < files.length; i++) {
2.335 + String fileName = files[i].getAbsolutePath();
2.336 + DataObject obj = DataObject.find(FileUtil.toFileObject(files[i]));
2.337 + if (obj != null) {
2.338 + if (fileName.toLowerCase(Locale.ENGLISH).endsWith(executionOrder.get(typeIndex))) {
2.339 + //Load the editor cookier and allow parsing
2.340 + EditorCookie ec = obj.getCookie(EditorCookie.class);
2.341 + Task task = ec.prepareDocument();
2.342 + task.waitFinished();
2.343 + Document doc = ec.getDocument();
2.344 + PlsqlExecutableBlocksMaker blockMaker = new PlsqlExecutableBlocksMaker(doc);
2.345 + final List exeBlocks = blockMaker.makeExceutableObjects();
2.346 + if (isTemporyFile) {
2.347 + io.getOut().print("> Deploying...");
2.348 + } else {
2.349 + io.getOut().print("> Deploying " + fileName + "...");
2.350 + }
2.351 + handle.setDisplayName("Deploying files to database (" + (++count) + ")");
2.352 + InputOutput errorTab = executor.executePLSQL(exeBlocks, doc, true, true);
2.353 + if (errorTab == null) {
2.354 + io.getOut().println("Ok");
2.355 + } else {
2.356 + io.getOut().println("Failed");
2.357 + try {
2.358 + io.getErr().println("!!!Error deploying file " + fileName, new DeploymentError(errorTab));
2.359 + } catch (IOException ex) {
2.360 + Exceptions.printStackTrace(ex);
2.361 + }
2.362 + cancelDeployment = true;
2.363 + }
2.364 + }
2.365 }
2.366 - handle.setDisplayName("Deploying files to database (" + (++count) + ")");
2.367 - InputOutput errorTab = executor.executePLSQL(exeBlocks, doc, true, true);
2.368 - if (errorTab == null) {
2.369 - io.getOut().println("Ok");
2.370 - } else {
2.371 - io.getOut().println("Failed");
2.372 - try {
2.373 - io.getErr().println("!!!Error deploying file " + fileName, new DeploymentError(errorTab));
2.374 - } catch (IOException ex) {
2.375 - Exceptions.printStackTrace(ex);
2.376 - }
2.377 - cancelDeployment = true;
2.378 - }
2.379 - }
2.380 - }
2.381 - }
2.382 + }
2.383 + }
2.384 + io.getOut().close();
2.385 + io.getErr().close();
2.386 + io.select();
2.387 + } catch (IOException ex) {
2.388 + Exceptions.printStackTrace(ex);
2.389 + } finally {
2.390 + if (connectionProvider != null) {
2.391 + connectionProvider.releaseDatabaseConnection(connection);
2.392 + }
2.393 + handle.finish();
2.394 }
2.395 - io.getOut().close();
2.396 - io.getErr().close();
2.397 - io.select();
2.398 - } catch (IOException ex) {
2.399 - Exceptions.printStackTrace(ex);
2.400 - } finally {
2.401 - if (connectionProvider != null) {
2.402 - connectionProvider.releaseDatabaseConnection(connection);
2.403 + }
2.404 +
2.405 + @Override
2.406 + public boolean cancel() {
2.407 + if (executor != null) {
2.408 + executor.cancel();
2.409 + cancelDeployment = true;
2.410 }
2.411 - handle.finish();
2.412 - }
2.413 - }
2.414 + return true;
2.415 + }
2.416 + }
2.417
2.418 - @Override
2.419 - public boolean cancel() {
2.420 - if (executor != null) {
2.421 - executor.cancel();
2.422 - cancelDeployment = true;
2.423 - }
2.424 - return true;
2.425 - }
2.426 - }
2.427 + /*
2.428 + * Displays a file chooser dialog which can be used to browse and select arbitrary
2.429 + * files from disk to be deployed to the database.
2.430 + */
2.431 +
2.432 + public static class GenericDeployFilesAction extends DeployFilesAction {
2.433 +
2.434 + private static File lastLocation = null;
2.435 +
2.436 + @Override
2.437 + protected final File[] getFilesToDeploy() {
2.438 + final JFileChooser fc = new JFileChooser();
2.439 + fc.setMultiSelectionEnabled(true);
2.440 + fc.setCurrentDirectory(lastLocation);
2.441 + fc.setDialogTitle(NbBundle.getMessage(DeployFilesAction.class, "LBL_DeployDialogTitle"));
2.442 + fc.setApproveButtonText("OK");
2.443 + int returnVal = fc.showOpenDialog(null);
2.444 + if (returnVal == JFileChooser.APPROVE_OPTION) {
2.445 + File[] files = fc.getSelectedFiles();
2.446 + lastLocation = fc.getCurrentDirectory();
2.447 + if (files != null) {
2.448 + return files;
2.449 + }
2.450 + }
2.451 + return new File[0];
2.452 + }
2.453 +
2.454 + @Override
2.455 + public String getName() {
2.456 + return NbBundle.getMessage(DeployFilesAction.class, "CTL_DeployFilesAction");
2.457 + }
2.458 + }
2.459 +
2.460 + /*
2.461 + * Displays a dialog listing files currently open in the editor which makes it
2.462 + * easy to select and deploy files to the database that are being worked on.
2.463 + */
2.464 + public static class DeployFilesOpenInEditorAction extends DeployFilesAction {
2.465 +
2.466 + @Override
2.467 + protected final File[] getFilesToDeploy() {
2.468 + OpenPlsqlFilesSelectorPanel editorSelector = new OpenPlsqlFilesSelectorPanel();
2.469 + DialogDescriptor openFilesDialog = new DialogDescriptor(editorSelector, NbBundle.getMessage(DeployFilesOpenInEditorAction.class, "LBL_DeployDialogTitle"));
2.470 + DialogDisplayer.getDefault().notify(openFilesDialog);
2.471 + if (openFilesDialog.getValue().equals(DialogDescriptor.OK_OPTION)) {
2.472 + List<File> filesToDeploy = editorSelector.getOpenFiles();
2.473 + if (!filesToDeploy.isEmpty()) {
2.474 + return filesToDeploy.toArray(new File[filesToDeploy.size()]);
2.475 + }
2.476 + }
2.477 + return new File[0];
2.478 + }
2.479 +
2.480 + @Override
2.481 + public String getName() {
2.482 + return NbBundle.getMessage(DeployFilesAction.class, "CTL_DeployFilesOpenInEditorAction");
2.483 + }
2.484 + }
2.485 }
3.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/actions/DeploySelectedCodeAction.java Thu Jun 07 16:37:59 2012 +0200
3.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/actions/DeploySelectedCodeAction.java Mon Jun 11 10:51:08 2012 +0530
3.3 @@ -209,16 +209,25 @@
3.4 Exceptions.printStackTrace(ex);
3.5 }
3.6 File tmpFile = null;
3.7 + FileWriter writer = null;
3.8 try {
3.9 tmpFile = File.createTempFile(TEMP_SQL_FILE_PREFIX, ".sql",
3.10 FileUtil.toFile(project.getLookup().lookup(CacheDirectoryProvider.class).getCacheDirectory()));
3.11 tmpFile.deleteOnExit();
3.12 - FileWriter writer = new FileWriter(tmpFile);
3.13 + writer = new FileWriter(tmpFile);
3.14 writer.write(output);
3.15 - writer.close();
3.16 +
3.17 } catch (IOException ex) {
3.18 Exceptions.printStackTrace(ex);
3.19 }
3.20 + finally{
3.21 + if (writer!=null)
3.22 + try {
3.23 + writer.close();
3.24 + } catch (IOException ignore) {
3.25 + // Exceptions.printStackTrace(ex);
3.26 + }
3.27 + }
3.28 File[] files = {tmpFile};
3.29 try {
3.30 DeployFilesAction.execute(connection, connectionProvider, files, true);
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/actions/OpenPlsqlFilesSelectorPanel.form Mon Jun 11 10:51:08 2012 +0530
4.3 @@ -0,0 +1,54 @@
4.4 +<?xml version="1.0" encoding="UTF-8" ?>
4.5 +
4.6 +<Form version="1.5" maxVersion="1.6" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4.7 + <AuxValues>
4.8 + <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
4.9 + <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
4.10 + <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
4.11 + <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
4.12 + <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
4.13 + <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
4.14 + <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
4.15 + <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
4.16 + <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
4.17 + </AuxValues>
4.18 +
4.19 + <Layout>
4.20 + <DimensionLayout dim="0">
4.21 + <Group type="103" groupAlignment="0" attributes="0">
4.22 + <Group type="102" alignment="0" attributes="0">
4.23 + <EmptySpace max="-2" attributes="0"/>
4.24 + <Group type="103" groupAlignment="0" attributes="0">
4.25 + <Component id="jPanel1" alignment="0" pref="237" max="32767" attributes="0"/>
4.26 + <Component id="lblOpenFiles" alignment="0" min="-2" max="-2" attributes="0"/>
4.27 + </Group>
4.28 + <EmptySpace max="-2" attributes="0"/>
4.29 + </Group>
4.30 + </Group>
4.31 + </DimensionLayout>
4.32 + <DimensionLayout dim="1">
4.33 + <Group type="103" groupAlignment="0" attributes="0">
4.34 + <Group type="102" alignment="0" attributes="0">
4.35 + <EmptySpace max="-2" attributes="0"/>
4.36 + <Component id="lblOpenFiles" min="-2" max="-2" attributes="0"/>
4.37 + <EmptySpace max="-2" attributes="0"/>
4.38 + <Component id="jPanel1" min="-2" pref="179" max="-2" attributes="0"/>
4.39 + <EmptySpace max="32767" attributes="0"/>
4.40 + </Group>
4.41 + </Group>
4.42 + </DimensionLayout>
4.43 + </Layout>
4.44 + <SubComponents>
4.45 + <Component class="javax.swing.JLabel" name="lblOpenFiles">
4.46 + <Properties>
4.47 + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
4.48 + <ResourceString bundle="org/netbeans/modules/plsql/execution/actions/Bundle.properties" key="OpenPlsqlFilesSelectorPanel.lblOpenFiles.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
4.49 + </Property>
4.50 + </Properties>
4.51 + </Component>
4.52 + <Container class="javax.swing.JPanel" name="jPanel1">
4.53 +
4.54 + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
4.55 + </Container>
4.56 + </SubComponents>
4.57 +</Form>
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/actions/OpenPlsqlFilesSelectorPanel.java Mon Jun 11 10:51:08 2012 +0530
5.3 @@ -0,0 +1,229 @@
5.4 +/*
5.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5.6 + *
5.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5.8 + *
5.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
5.10 + * Other names may be trademarks of their respective owners.
5.11 + *
5.12 + * The contents of this file are subject to the terms of either the GNU
5.13 + * General Public License Version 2 only ("GPL") or the Common
5.14 + * Development and Distribution License("CDDL") (collectively, the
5.15 + * "License"). You may not use this file except in compliance with the
5.16 + * License. You can obtain a copy of the License at
5.17 + * http://www.netbeans.org/cddl-gplv2.html
5.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
5.19 + * specific language governing permissions and limitations under the
5.20 + * License. When distributing the software, include this License Header
5.21 + * Notice in each file and include the License file at
5.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
5.23 + * particular file as subject to the "Classpath" exception as provided
5.24 + * by Oracle in the GPL Version 2 section of the License file that
5.25 + * accompanied this code. If applicable, add the following below the
5.26 + * License Header, with the fields enclosed by brackets [] replaced by
5.27 + * your own identifying information:
5.28 + * "Portions Copyrighted [year] [name of copyright owner]"
5.29 + *
5.30 + * If you wish your version of this file to be governed by only the CDDL
5.31 + * or only the GPL Version 2, indicate your decision by adding
5.32 + * "[Contributor] elects to include this software in this distribution
5.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
5.34 + * single choice of license, a recipient has the option to distribute
5.35 + * your version of this file under either the CDDL, the GPL Version 2 or
5.36 + * to extend the choice of license to its licensees as provided above.
5.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
5.38 + * Version 2 license, then the option applies only if the new code is
5.39 + * made subject to such option by the copyright holder.
5.40 + *
5.41 + * Contributor(s):
5.42 + *
5.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
5.44 + */
5.45 +package org.netbeans.modules.plsql.execution.actions;
5.46 +
5.47 +import java.awt.Component;
5.48 +import java.awt.event.MouseEvent;
5.49 +import java.io.File;
5.50 +import java.util.*;
5.51 +import javax.swing.*;
5.52 +import javax.swing.event.ListSelectionEvent;
5.53 +import javax.swing.event.ListSelectionListener;
5.54 +import org.netbeans.modules.plsql.filetype.PlsqlDataLoader;
5.55 +import org.openide.filesystems.FileObject;
5.56 +import org.openide.filesystems.FileUtil;
5.57 +import org.openide.loaders.DataObject;
5.58 +import org.openide.util.Lookup;
5.59 +import org.openide.windows.Mode;
5.60 +import org.openide.windows.TopComponent;
5.61 +import org.openide.windows.WindowManager;
5.62 +
5.63 +/**
5.64 + *
5.65 + * @author riralk
5.66 + * based on org.netbeans.modules.diff.EditorBufferSelectorPanel by Maros Sandor *
5.67 + */
5.68 +class OpenPlsqlFilesSelectorPanel extends JPanel implements ListSelectionListener {
5.69 +
5.70 + private JList elementsList;
5.71 + private List<File> openFiles = new ArrayList<File>();
5.72 +
5.73 + public OpenPlsqlFilesSelectorPanel() {
5.74 + initComponents();
5.75 + initEditorDocuments();
5.76 + }
5.77 +
5.78 + private void initEditorDocuments() {
5.79 + elementsList = new JList() {
5.80 + @Override
5.81 + public String getToolTipText(MouseEvent event) {
5.82 + int index = locationToIndex(event.getPoint());
5.83 + if (index != -1) {
5.84 + PlsqlFileListElement element = (PlsqlFileListElement) elementsList.getModel().getElementAt(index);
5.85 + return element.fileObject.getPath();
5.86 + }
5.87 + return null;
5.88 + }
5.89 + };
5.90 +
5.91 + List<PlsqlFileListElement> elements = new ArrayList<PlsqlFileListElement>();
5.92 +
5.93 + WindowManager wm = WindowManager.getDefault();
5.94 + Set<? extends Mode> modes = wm.getModes();
5.95 + for (Mode mode : modes) {
5.96 + if (wm.isEditorMode(mode)) {
5.97 + TopComponent[] tcs = mode.getTopComponents();
5.98 + for (TopComponent tc : tcs) {
5.99 + Lookup lukap = tc.getLookup();
5.100 + FileObject fo = lukap.lookup(FileObject.class);
5.101 + if (fo == null) {
5.102 + DataObject dobj = lukap.lookup(DataObject.class);
5.103 + if (dobj != null) {
5.104 + fo = dobj.getPrimaryFile();
5.105 + }
5.106 + }
5.107 + if (fo != null && fo.getMIMEType().equals(PlsqlDataLoader.REQUIRED_MIME) && !fo.getExt().equals("tdb")) {
5.108 + if (tc.getHtmlDisplayName() != null) {
5.109 + elements.add(new PlsqlFileListElement(fo, tc.getHtmlDisplayName(), true));
5.110 + } else {
5.111 + elements.add(new PlsqlFileListElement(fo, tc.getName(), false));
5.112 + }
5.113 + }
5.114 + }
5.115 + }
5.116 + }
5.117 +
5.118 + elementsList.setListData(elements.toArray(new PlsqlFileListElement[elements.size()]));
5.119 + elementsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
5.120 + elementsList.addListSelectionListener(this);
5.121 + elementsList.setCellRenderer(new DefaultListCellRenderer() {
5.122 + @Override
5.123 + public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
5.124 + if (isSelected && value instanceof PlsqlFileListElement && ((PlsqlFileListElement) value).isHtml()) {
5.125 + value = stripHtml(((PlsqlFileListElement) value).toString());
5.126 + }
5.127 + return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
5.128 + }
5.129 +
5.130 + private String stripHtml (String htmlText) {
5.131 + if (null == htmlText) {
5.132 + return null;
5.133 + }
5.134 + String res = htmlText.replaceAll("<[^>]*>", ""); // NOI18N // NOI18N
5.135 + res = res.replaceAll(" ", " "); // NOI18N // NOI18N
5.136 + res = res.trim();
5.137 + return res;
5.138 + }
5.139 + });
5.140 +
5.141 + JScrollPane sp = new JScrollPane(elementsList);
5.142 + jPanel1.add(sp);
5.143 + }
5.144 +
5.145 + @Override
5.146 + public void valueChanged(ListSelectionEvent e) {
5.147 + if (e.getValueIsAdjusting() == false) {
5.148 + Object[] elements = elementsList.getSelectedValues();
5.149 + //reinitialize list
5.150 + openFiles = new ArrayList<File>();
5.151 + if (elements != null && elements.length > 0) {
5.152 + for (int i = 0; i < elements.length; i++) {
5.153 + PlsqlFileListElement el = (PlsqlFileListElement) elements[i];
5.154 + openFiles.add(FileUtil.normalizeFile(FileUtil.toFile(el.fileObject)));
5.155 + }
5.156 + }
5.157 + }
5.158 + }
5.159 +
5.160 + /** This method is called from within the constructor to
5.161 + * initialize the form.
5.162 + * WARNING: Do NOT modify this code. The content of this method is
5.163 + * always regenerated by the Form Editor.
5.164 + */
5.165 + @SuppressWarnings("unchecked")
5.166 + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
5.167 + private void initComponents() {
5.168 +
5.169 + lblOpenFiles = new javax.swing.JLabel();
5.170 + jPanel1 = new javax.swing.JPanel();
5.171 +
5.172 + org.openide.awt.Mnemonics.setLocalizedText(lblOpenFiles, org.openide.util.NbBundle.getMessage(OpenPlsqlFilesSelectorPanel.class, "OpenPlsqlFilesSelectorPanel.lblOpenFiles.text")); // NOI18N
5.173 +
5.174 + jPanel1.setLayout(new java.awt.BorderLayout());
5.175 +
5.176 + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
5.177 + this.setLayout(layout);
5.178 + layout.setHorizontalGroup(
5.179 + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
5.180 + .add(layout.createSequentialGroup()
5.181 + .addContainerGap()
5.182 + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
5.183 + .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE)
5.184 + .add(lblOpenFiles))
5.185 + .addContainerGap())
5.186 + );
5.187 + layout.setVerticalGroup(
5.188 + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
5.189 + .add(layout.createSequentialGroup()
5.190 + .addContainerGap()
5.191 + .add(lblOpenFiles)
5.192 + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
5.193 + .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 179, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
5.194 + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
5.195 + );
5.196 + }// </editor-fold>//GEN-END:initComponents
5.197 +
5.198 +
5.199 + // Variables declaration - do not modify//GEN-BEGIN:variables
5.200 + private javax.swing.JPanel jPanel1;
5.201 + private javax.swing.JLabel lblOpenFiles;
5.202 + // End of variables declaration//GEN-END:variables
5.203 +
5.204 + /**
5.205 + * @return the openFileSet
5.206 + */
5.207 + public List<File> getOpenFiles() {
5.208 + return Collections.unmodifiableList(openFiles);
5.209 + }
5.210 +
5.211 +
5.212 + private static class PlsqlFileListElement {
5.213 + FileObject fileObject;
5.214 + String displayName;
5.215 + private final boolean html;
5.216 +
5.217 + PlsqlFileListElement(FileObject tc, String displayName, boolean isHtml) {
5.218 + this.fileObject = tc;
5.219 + this.displayName = displayName;
5.220 + this.html = isHtml;
5.221 + }
5.222 +
5.223 + @Override
5.224 + public String toString() {
5.225 + return displayName;
5.226 + }
5.227 +
5.228 + public boolean isHtml () {
5.229 + return html;
5.230 + }
5.231 + }
5.232 +}
6.1 --- a/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/layer.xml Thu Jun 07 16:37:59 2012 +0200
6.2 +++ b/PLSQL/Execution/src/org/netbeans/modules/plsql/execution/layer.xml Mon Jun 11 10:51:08 2012 +0530
6.3 @@ -4,9 +4,12 @@
6.4 <folder name="Databases">
6.5 <folder name="Nodes">
6.6 <folder name="Oracle">
6.7 - <file name="org-netbeans-modules-plsql-execution-actions-DeployFilesAction.instance">
6.8 + <file name="org-netbeans-modules-plsql-execution-actions-DeployFilesAction$GenericDeployFilesAction.instance">
6.9 <attr name="position" intvalue="110"/>
6.10 </file>
6.11 + <file name="org-netbeans-modules-plsql-execution-actions-DeployFilesAction$DeployFilesOpenInEditorAction.instance">
6.12 + <attr name="position" intvalue="120"/>
6.13 + </file>
6.14 </folder>
6.15 </folder>
6.16 </folder>