]> gerrit.simantics Code Review - simantics/platform.git/blob
1c9198015031e17a5fe4fe52f85afaadc2d03dec
[simantics/platform.git] /
1 package org.simantics.modeling.ui.scl.imports;
2
3 import java.util.ArrayList;
4
5 import org.eclipse.jface.dialogs.Dialog;
6 import org.eclipse.swt.widgets.Shell;
7 import org.simantics.scl.compiler.commands.CommandSessionImportEntry;
8 import org.simantics.scl.ui.imports.ImportModulesAction;
9
10 public class OntologyImportModulesAction extends ImportModulesAction {
11     
12     public static final OntologyImportModulesAction INSTANCE = new OntologyImportModulesAction();
13             
14     public OntologyImportModulesAction() {
15         super("Add ontology", 10.0);
16     }
17
18     @Override
19     public boolean editImports(Shell shell, ArrayList<CommandSessionImportEntry> imports) {
20         ModuleSelectionDialog dialog = new ModuleSelectionDialog(shell, OntologiesQuery.INSTANCE);
21         if(dialog.open() == Dialog.OK) {
22             for(Object r : dialog.getResult()) {
23                 String uri = (String)r;
24                 new CommandSessionImportEntry(uri, getDefaultLocalName(uri), true).addTo(imports);
25             }
26             return true;
27         }
28         else
29             return false;
30     }
31     
32     public String getDefaultLocalName(String ontologyUri) {
33         if(ontologyUri.contains("/Layer0-"))
34             return "L0";
35         if(ontologyUri.contains("/Structural-"))
36             return "STR";
37         if(ontologyUri.contains("/Modeling-"))
38             return "MOD";
39         return "";
40     }
41
42 }