View | Details | Raw Unified | Return to bug 52281
Collapse All | Expand All

(-)src/core/org/apache/jmeter/gui/MainFrame.java (-1 / +5 lines)
Lines 153-159 Link Here
153
153
154
        GuiPackage.getInstance().setMainFrame(this);
154
        GuiPackage.getInstance().setMainFrame(this);
155
        init();
155
        init();
156
156
        initTransferHandler();
157
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
157
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
158
    }
158
    }
159
159
Lines 406-411 Link Here
406
        setIconImage(JMeterUtils.getImage("jmeter.jpg").getImage());// $NON-NLS-1$
406
        setIconImage(JMeterUtils.getImage("jmeter.jpg").getImage());// $NON-NLS-1$
407
    }
407
    }
408
408
409
	public void initTransferHandler() {
410
    	this.setTransferHandler(new TopLevelTransferHandler());
411
    }
412
    
409
    public void setExtendedFrameTitle(String fname) {
413
    public void setExtendedFrameTitle(String fname) {
410
        // file New operation may set to null, so just return app name
414
        // file New operation may set to null, so just return app name
411
        if (fname == null) {
415
        if (fname == null) {
(-)src/core/org/apache/jmeter/gui/TopLevelTransferHandler.java (+52 lines)
Line 0 Link Here
1
package org.apache.jmeter.gui;
2
3
import java.awt.datatransfer.DataFlavor;
4
import java.awt.datatransfer.UnsupportedFlavorException;
5
import java.awt.event.ActionEvent;
6
import java.io.File;
7
import java.io.IOException;
8
import java.util.List;
9
10
import javax.swing.TransferHandler;
11
12
import org.apache.jmeter.gui.action.ActionNames;
13
import org.apache.jmeter.gui.action.LoadDraggedFile;
14
import org.apache.jorphan.logging.LoggingManager;
15
import org.apache.log.Logger;
16
17
@SuppressWarnings("serial")
18
final class TopLevelTransferHandler extends TransferHandler {
19
	private static final Logger log = LoggingManager.getLoggerForClass();
20
	
21
	@Override
22
	public boolean canImport(TransferHandler.TransferSupport support) {
23
		if(!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
24
			return false;
25
		}
26
		return true;
27
	}
28
29
	@SuppressWarnings("unchecked")
30
	@Override
31
	public boolean importData(TransferSupport support) {
32
		if(!canImport(support)) {
33
			return false;
34
		}
35
		try {
36
			List<File> files = (List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
37
			if(files.isEmpty()) {
38
				return false;
39
			}
40
41
			ActionEvent fakeEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, ActionNames.OPEN);
42
			LoadDraggedFile.loadProject(fakeEvent, files.get(0));
43
		} catch (IOException e) {
44
			log.error("Importing data from DnD caused ", e);
45
			return false;
46
		} catch (UnsupportedFlavorException e) {
47
			log.error("Importing data from DnD caused ", e);
48
			return false;
49
		}
50
		return super.importData(support);
51
	}
52
}
(-)src/core/org/apache/jmeter/gui/action/LoadDraggedFile.java (+35 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
19
package org.apache.jmeter.gui.action;
20
21
import java.awt.event.ActionEvent;
22
import java.io.File;
23
24
/**
25
 * Handles the loading of a file from a Drag and Drop action.
26
 */
27
public class LoadDraggedFile {
28
29
    public static void loadProject(ActionEvent e, File f) {
30
    	if(!Close.performAction(e)) {
31
    		return;
32
    	}
33
    	Load.loadProjectFile(e, f, false);
34
    }
35
}

Return to bug 52281