]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.image.ui/src/org/simantics/image/ui/modelBrowser/handlers/ImportImageHandler.java
d95498cbc4148c83fd32b5101d418aed7aba1f5f
[simantics/platform.git] / bundles / org.simantics.image.ui / src / org / simantics / image / ui / modelBrowser / handlers / ImportImageHandler.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.image.ui.modelBrowser.handlers;
13
14 import java.io.File;
15 import java.util.Collection;
16
17 import org.eclipse.core.commands.AbstractHandler;
18 import org.eclipse.core.commands.ExecutionEvent;
19 import org.eclipse.core.commands.ExecutionException;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.ui.handlers.HandlerUtil;
23 import org.simantics.db.Resource;
24 import org.simantics.image.ui.CreateImages;
25 import org.simantics.image.ui.ImportImagesActionFactory;
26 import org.simantics.image.ui.modelBrowser.ImagesNode;
27 import org.simantics.ui.SimanticsUI;
28 import org.simantics.utils.ui.AdaptionUtils;
29
30 /**
31  * @author J-P Laine
32  */
33 public class ImportImageHandler extends AbstractHandler {
34
35     @Override
36     public Object execute(ExecutionEvent event) throws ExecutionException {
37         final Shell shell = HandlerUtil.getActiveShell(event);
38
39         ISelection selection = HandlerUtil.getCurrentSelection(event);
40         ImagesNode images = AdaptionUtils.adaptToSingle(selection, ImagesNode.class);
41         if (images == null)
42             return null;
43         final Resource container = images.data;
44
45         Collection<File> files = ImportImagesActionFactory.requestImportedImages(shell);
46         if (files.isEmpty())
47             return null;
48
49         SimanticsUI.getSession().asyncRequest( new CreateImages(container, files) );
50
51         return null;
52     }
53
54 }