]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ExportSharedLibrary.java
Externalize strings in org.simantics.desktop.ui
[simantics/platform.git] / bundles / org.simantics.desktop.ui / src / org / simantics / desktop / ui / internal / ExportSharedLibrary.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * 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.desktop.ui.internal;
13
14 import java.util.List;
15
16 import org.eclipse.core.commands.AbstractHandler;
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.jface.viewers.IStructuredSelection;
20 import org.eclipse.jface.viewers.StructuredSelection;
21 import org.eclipse.swt.widgets.Display;
22 import org.simantics.Simantics;
23 import org.simantics.browsing.ui.common.AdaptableHintContext;
24 import org.simantics.db.ReadGraph;
25 import org.simantics.db.Resource;
26 import org.simantics.db.common.request.UniqueRead;
27 import org.simantics.db.exception.DatabaseException;
28 import org.simantics.db.layer0.SelectionHints;
29 import org.simantics.modeling.ModelingUtils;
30 import org.simantics.scl.runtime.tuple.Tuple0;
31 import org.simantics.utils.datastructures.hints.IHintContext;
32
33 public class ExportSharedLibrary extends AbstractHandler {
34
35     @Override
36     public Object execute(ExecutionEvent event) throws ExecutionException {
37         
38         try {
39                         Resource lib = Simantics.sync(new UniqueRead<Resource>() {
40
41                                 @Override
42                                 public Resource perform(ReadGraph graph) throws DatabaseException {
43                                         List<Resource> ontologies =  Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE); //$NON-NLS-1$ //$NON-NLS-2$
44                                         if(ontologies.size() == 1) return ontologies.iterator().next();
45                                         return null;
46                                 }
47                                 
48                         });
49                         if(lib == null) return null;
50                         
51             IHintContext context = new AdaptableHintContext(SelectionHints.KEY_MAIN);
52             context.setHint(SelectionHints.KEY_MAIN, lib);
53
54                         IStructuredSelection sel = new StructuredSelection(context);
55                 ModelingUtils.openWizard(Display.getCurrent(), sel, "org.simantics.modeling.ui.sharedOntologyExportWizard"); //$NON-NLS-1$
56                 } catch (DatabaseException e) {
57                         // TODO Auto-generated catch block
58                         e.printStackTrace();
59                 }
60         
61         return null;
62         
63     }
64
65 }