You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2012/01/15 16:05:31 UTC
svn commit: r1231684 - in /jmeter/trunk:
src/core/org/apache/jmeter/gui/MainFrame.java
src/core/org/apache/jmeter/gui/TopLevelTransferHandler.java
src/core/org/apache/jmeter/gui/action/LoadDraggedFile.java xdocs/changes.xml
Author: pmouawad
Date: Sun Jan 15 15:05:30 2012
New Revision: 1231684
URL: http://svn.apache.org/viewvc?rev=1231684&view=rev
Log:
Bug 52281 - Support for file Drag and Drop
Added:
jmeter/trunk/src/core/org/apache/jmeter/gui/TopLevelTransferHandler.java (with props)
jmeter/trunk/src/core/org/apache/jmeter/gui/action/LoadDraggedFile.java (with props)
Modified:
jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java
jmeter/trunk/xdocs/changes.xml
Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java?rev=1231684&r1=1231683&r2=1231684&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java Sun Jan 15 15:05:30 2012
@@ -153,7 +153,7 @@ public class MainFrame extends JFrame im
GuiPackage.getInstance().setMainFrame(this);
init();
-
+ initTransferHandler();
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
}
@@ -406,6 +406,13 @@ public class MainFrame extends JFrame im
setIconImage(JMeterUtils.getImage("jmeter.jpg").getImage());// $NON-NLS-1$
}
+ /**
+ * Support for Test Plan Dnd
+ */
+ public void initTransferHandler() {
+ this.setTransferHandler(new TopLevelTransferHandler());
+ }
+
public void setExtendedFrameTitle(String fname) {
// file New operation may set to null, so just return app name
if (fname == null) {
Added: jmeter/trunk/src/core/org/apache/jmeter/gui/TopLevelTransferHandler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/TopLevelTransferHandler.java?rev=1231684&view=auto
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/TopLevelTransferHandler.java (added)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/TopLevelTransferHandler.java Sun Jan 15 15:05:30 2012
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.gui;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.event.ActionEvent;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import javax.swing.TransferHandler;
+
+import org.apache.jmeter.gui.action.ActionNames;
+import org.apache.jmeter.gui.action.LoadDraggedFile;
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.log.Logger;
+
+/**
+ * Transfer Handler implementation that provides DnD support of Test Plans
+ */
+@SuppressWarnings("serial")
+final class TopLevelTransferHandler extends TransferHandler {
+ private static final Logger log = LoggingManager.getLoggerForClass();
+
+ /**
+ *
+ */
+ @Override
+ public boolean canImport(TransferHandler.TransferSupport support) {
+ if(!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ *
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public boolean importData(TransferSupport support) {
+ if(!canImport(support)) {
+ return false;
+ }
+ try {
+ List<File> files = (List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
+ if(files.isEmpty()) {
+ return false;
+ }
+
+ File file = files.get(0);
+ if(!file.getName().endsWith(".jmx")) {
+ log.warn("Importing file:" + file.getName()+ "from DnD failed because file extension does not end with .jmx");
+ return false;
+ }
+
+ ActionEvent fakeEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, ActionNames.OPEN);
+ LoadDraggedFile.loadProject(fakeEvent, file);
+ } catch (IOException e) {
+ log.error("Importing data from DnD caused ", e);
+ return false;
+ } catch (UnsupportedFlavorException e) {
+ log.error("Importing data from DnD caused ", e);
+ return false;
+ }
+ return super.importData(support);
+ }
+}
\ No newline at end of file
Propchange: jmeter/trunk/src/core/org/apache/jmeter/gui/TopLevelTransferHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jmeter/trunk/src/core/org/apache/jmeter/gui/action/LoadDraggedFile.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/LoadDraggedFile.java?rev=1231684&view=auto
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/LoadDraggedFile.java (added)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/LoadDraggedFile.java Sun Jan 15 15:05:30 2012
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.gui.action;
+
+import java.awt.event.ActionEvent;
+import java.io.File;
+
+/**
+ * Handles the loading of a file from a Drag and Drop action.
+ */
+public class LoadDraggedFile {
+
+ /**
+ * Loads dragged file asking before for save if current open file is dirty.
+ * @param e {@link ActionEvent}
+ * @param file File to Load
+ */
+ public static void loadProject(ActionEvent e, File file) {
+ if(!Close.performAction(e)) {
+ return;
+ }
+ Load.loadProjectFile(e, file, false);
+ }
+}
Propchange: jmeter/trunk/src/core/org/apache/jmeter/gui/action/LoadDraggedFile.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1231684&r1=1231683&r2=1231684&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sun Jan 15 15:05:30 2012
@@ -259,6 +259,7 @@ Loads any additional properties found in
<li>Bug 29352 - Use external store to hold samples during distributed testing, Added DiskStore remote sample sender: like Hold, but saves samples to disk until end of test.</li>
<li>Bug 52333 - Reduce overhead in calculating SampleResult#nanoTimeOffset</li>
<li>Bug 52346 - Shutdown detects if there are any non-daemon threads left which prevent JVM exit.</li>
+<li>Bug 52281 - Support for file Drag and Drop</li>
</ul>
<h2>Non-functional changes</h2>
Re: svn commit: r1231684 - in /jmeter/trunk: src/core/org/apache/jmeter/gui/MainFrame.java
src/core/org/apache/jmeter/gui/TopLevelTransferHandler.java
src/core/org/apache/jmeter/gui/action/LoadDraggedFile.java xdocs/changes.xml
Posted by Philippe Mouawad <ph...@gmail.com>.
Sorry, I will fix it in the evening.
Thanks for note.
On Sun, Jan 15, 2012 at 4:20 PM, Milamber <mi...@apache.org> wrote:
>
>
> Le 15/01/2012 15:05, pmouawad@apache.org a ecrit :
> > + public boolean canImport(TransferHandler.TransferSupport support) {
> >
>
> It is a Java 6 Class.
> JMeter support (currently) Java 5 (compile and/or run)
>
>
> http://docs.oracle.com/javase/6/docs/api/javax/swing/TransferHandler.TransferSupport.html
>
> Milamber
>
--
Cordialement.
Philippe Mouawad.
Re: svn commit: r1231684 - in /jmeter/trunk: src/core/org/apache/jmeter/gui/MainFrame.java
src/core/org/apache/jmeter/gui/TopLevelTransferHandler.java src/core/org/apache/jmeter/gui/action/LoadDraggedFile.java
xdocs/changes.xml
Posted by Milamber <mi...@apache.org>.
Le 15/01/2012 15:05, pmouawad@apache.org a ecrit :
> + public boolean canImport(TransferHandler.TransferSupport support) {
>
It is a Java 6 Class.
JMeter support (currently) Java 5 (compile and/or run)
http://docs.oracle.com/javase/6/docs/api/javax/swing/TransferHandler.TransferSupport.html
Milamber