diff --git a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/AlignFormSectionFactory.java b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/AlignFormSectionFactory.java index 2d8e7fb65b3aefa9c0ecb6e77bdc372eb1d00f86..dea47e42ff35967a1804ef3d7d430757ee5f2487 100644 --- a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/AlignFormSectionFactory.java +++ b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/AlignFormSectionFactory.java @@ -46,6 +46,7 @@ public class AlignFormSectionFactory { SWT.WRAP ); section.setText( sectionTitle ); section.setDescription( sectionDescription ); + toolkit.createCompositeSeparator( section ); section.setLayout( AlignFormLayoutFactory.createClearTableWrapLayout( false, 1 ) ); TableWrapData data = new TableWrapData( TableWrapData.FILL_GRAB ); @@ -67,7 +68,7 @@ public class AlignFormSectionFactory { ExpandableComposite.TWISTIE | SWT.WRAP ); section.setText(sectionTitle); - + Composite client = toolkit.createComposite( section ); section.setClient( client ); diff --git a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/AlignView.java b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/AlignView.java index ba597b000f3fd3153eba57c6b38a31336cb54333..2dc5aec0ab46c88805afd56ba40403b454b9958b 100755 --- a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/AlignView.java +++ b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/AlignView.java @@ -26,10 +26,15 @@ import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.GridLayout; +import java.awt.Point; import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.io.StringWriter; import java.net.URI; import java.util.HashMap; import java.util.Hashtable; +import java.util.Properties; import java.util.Set; import java.util.Vector; @@ -50,6 +55,7 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.browser.Browser; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.RowLayout; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.ScrolledForm; import org.eclipse.ui.forms.widgets.ScrolledFormText; @@ -64,10 +70,21 @@ import org.eclipse.jface.dialogs.MessageDialog; //import org.eclipse.jface.dialogs.MessageDialog; import org.semanticweb.kaon2.api.OntologyManager; import org.semanticweb.owl.align.Alignment; +import org.semanticweb.owl.align.AlignmentVisitor; +import com.ontoprise.config.IConfig; import com.ontoprise.ontostudio.datamodel.DatamodelPlugin; +import com.ontoprise.ontostudio.datamodel.DatamodelTypes; +import com.ontoprise.ontostudio.datamodel.exception.ControlException; +import com.ontoprise.ontostudio.gui.commands.project.CreateProject; +import com.ontoprise.ontostudio.io.ImportExportControl; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; +import fr.inrialpes.exmo.align.impl.URIAlignment; +import fr.inrialpes.exmo.align.impl.renderer.HTMLRendererVisitor; +import fr.inrialpes.exmo.align.impl.renderer.OWLAxiomsRendererVisitor; import fr.inrialpes.exmo.align.onto.owlapi10.OWLAPIOntologyFactory; +import fr.inrialpes.exmo.align.parser.AlignmentParser; import fr.inrialpes.exmo.align.plugin.neontk.AlignFormLayoutFactory; import fr.inrialpes.exmo.align.plugin.neontk.AlignFormSectionFactory; import fr.inrialpes.exmo.align.plugin.neontk.OnlineAlign; @@ -87,7 +104,7 @@ public class AlignView extends ViewPart private Button cancelButton, discardButton, resButton, onto1Refresh, onto2Refresh, localImportButton, serverImportButton, uploadButton, localTrimButton, serverTrimButton, connButton, goButton, offlineButton, onlineButton; - private Button storeButton, matchButton, findButton, findAllButton, fetchButton; + private Button storeButton, matchButton, findButton, findAllButton;// fetchButton; //private String selectedProject = null; //private Section ontoSelectSection; //private Section alignViewSection; @@ -95,9 +112,11 @@ public class AlignView extends ViewPart private String selectedOnto1, selectedOnto2, selectedLocalAlign, selectedServerAlign; private String[] ontoList = new String[0]; private String[] methodList = new String[0]; - public HashMap<String,String> ontoByProj = new HashMap<String,String>(0); - //String selectedLocalAlign = null; - //String selectedAlign = null; + public HashMap<String,String> ontoByProj = new HashMap<String,String>(0); + + private Composite htmlClient = null; + private Browser htmlBrowser = null; + private FormToolkit formToolkit = null; public static Hashtable<String,Alignment> alignmentTable = new Hashtable<String,Alignment>(); static String [] forUniqueness = new String[0]; @@ -115,7 +134,7 @@ public class AlignView extends ViewPart String selectedMethod = "fr.inrialpes.exmo.align.impl.method.NameEqAlignment"; String wserver = "http://kameleon.ijs.si/ontolight/ontolight.asmx"; - String wsmethod=""; + String wsmethod= ""; String alignProject = "AlignmentProject"; @@ -128,7 +147,8 @@ public class AlignView extends ViewPart @Override public void createPartControl(final Composite parent) { - FormToolkit formToolkit = new FormToolkit(Display.getCurrent()); + //FormToolkit formToolkit = new FormToolkit(Display.getCurrent()); + formToolkit = new FormToolkit(Display.getCurrent()); ScrolledForm scrolledForm = formToolkit.createScrolledForm(parent); Composite body = scrolledForm.getBody(); body.setLayout(AlignFormLayoutFactory.createFormTableWrapLayout(false,1)); @@ -165,7 +185,7 @@ public class AlignView extends ViewPart String sectionTitle = "Input"; Composite client ; - int columns = 6; + int columns = 5; int textWidth = 600; int textHeight = 20; GridData gd = new GridData(); @@ -192,12 +212,12 @@ public class AlignView extends ViewPart Label dummy1 = new Label(client, SWT.NONE); Label dummy2 = new Label(client, SWT.NONE); Label dummy3 = new Label(client, SWT.NONE); - Label dummy4 = new Label(client, SWT.NONE); + //Label dummy4 = new Label(client, SWT.NONE); // Choose ontology 1 Label onto1 = new Label(client, SWT.NONE); onto1.setText("Ontology 1 "); - ontoBox1 = new Combo(client, SWT.DROP_DOWN | SWT.READ_ONLY ); + ontoBox1 = new Combo(client, SWT.DROP_DOWN ); ontoBox1.setLayoutData( gd ); ontoBox1.setEnabled(true); ontoBox1.addSelectionListener(this); @@ -208,14 +228,15 @@ public class AlignView extends ViewPart onto1Refresh.setEnabled(true); Label dummy5 = new Label(client, SWT.NONE); Label dummy6 = new Label(client, SWT.NONE); - Label dummy7 = new Label(client, SWT.NONE); + //Label dummy7 = new Label(client, SWT.NONE); //Choose ontology 2 Label onto2 = new Label(client, SWT.NONE); onto2.setText("Ontology 2 "); - ontoBox2 = new Combo(client, SWT.DROP_DOWN | SWT.READ_ONLY ); + ontoBox2 = new Combo(client, SWT.DROP_DOWN ); ontoBox2.setLayoutData(gd); ontoBox2.setEnabled(true); + ontoBox2.addSelectionListener(this); onto2Refresh = new Button(client, SWT.PUSH); onto2Refresh.setText("Refresh"); @@ -224,7 +245,7 @@ public class AlignView extends ViewPart onto2Refresh.setEnabled(true); Label dummy8 = new Label(client, SWT.NONE); Label dummy9 = new Label(client, SWT.NONE); - Label dummy10 = new Label(client, SWT.NONE); + //Label dummy10 = new Label(client, SWT.NONE); //methods Label methodLabel = new Label(client, SWT.NONE); @@ -243,7 +264,7 @@ public class AlignView extends ViewPart Label dummy11 = new Label(client, SWT.NONE); Label dummy12 = new Label(client, SWT.NONE); - Label dummy13 = new Label(client, SWT.NONE); + //Label dummy13 = new Label(client, SWT.NONE); //server alignment list Label serverAlignLabel = new Label(client, SWT.NONE ); @@ -277,11 +298,11 @@ public class AlignView extends ViewPart storeButton.setEnabled(false); //fetch - fetchButton = new Button(client, SWT.PUSH); - fetchButton.setText("Fetch"); - fetchButton.setSize(buttonWidth, buttonHeight); - fetchButton.addSelectionListener(this); - fetchButton.setEnabled(false); + //fetchButton = new Button(client, SWT.PUSH); + //fetchButton.setText("Fetch"); + //fetchButton.setSize(buttonWidth, buttonHeight); + //fetchButton.addSelectionListener(this); + //fetchButton.setEnabled(false); //local alignment list Label localAlignLabel = new Label(client, SWT.NONE ); @@ -313,14 +334,14 @@ public class AlignView extends ViewPart uploadButton.addSelectionListener(this); uploadButton.setEnabled(false); - Label dummy14 = new Label(client, SWT.NONE); + //Label dummy14 = new Label(client, SWT.NONE); Label dummy15 = new Label(client, SWT.NONE); Label dummy16 = new Label(client, SWT.NONE); Label dummy17 = new Label(client, SWT.NONE); Label dummy18 = new Label(client, SWT.NONE); Label dummy19 = new Label(client, SWT.NONE); - Label dummy20 = new Label(client, SWT.NONE); + //Label dummy20 = new Label(client, SWT.NONE); Label dummy21 = new Label(client, SWT.NONE); @@ -334,7 +355,7 @@ public class AlignView extends ViewPart Label dummy22 = new Label(client, SWT.NONE); Label dummy23 = new Label(client, SWT.NONE); Label dummy24 = new Label(client, SWT.NONE); - Label dummy25 = new Label(client, SWT.NONE); + //Label dummy25 = new Label(client, SWT.NONE); Label dummy26 = new Label(client, SWT.NONE); //find all @@ -350,34 +371,32 @@ public class AlignView extends ViewPart private void createAlignmentPart(final Composite parent, final FormToolkit toolkit){ + String sectionTitle = "View Alignment"; - - //int columns = 1; - //int textWidth = 800; - //int textHeight = 20; - //FillLayout fl = new FillLayout(); - //Composite client = new ScrolledFormText( parent, true ); - //fl.widthHint = textWidth; - //fl.heightHint = textHeight; - //String tx = "<html><body>This is Unicode HTML content from memory</body></html>"; - Composite client = AlignFormSectionFactory.createHtmlSection( - toolkit, parent, sectionTitle); - //client = AlignFormSectionFactory.createGridExpandableSection( - //toolkit, parent, sectionTitle, columns, true); - //alignViewSection = AlignFormSectionFactory.getGridExpendableSection(); - //alignViewSection = AlignFormSectionFactory.getSimpleSection(); - //alignViewSection.setExpanded( true ); - - //Composite client = new ScrolledFormText( parent, true ); - - client.setLayout(new FillLayout()); - client.setSize(960, 720); - client.setLocation(0, 0); - - Browser browser = new Browser(client, SWT.BORDER); - browser.setText("<html><body>This is Unicode HTML content from memory</body></html>"); - - toolkit.paintBordersFor(client); + //Composite client = AlignFormSectionFactory.createHtmlSection( + // toolkit, parent, sectionTitle); + htmlClient = AlignFormSectionFactory.createHtmlSection( + toolkit, parent, sectionTitle); + + htmlClient.setSize(450, 100); + + FillLayout fillLayout = new FillLayout(SWT.VERTICAL); + + htmlClient.setLayout( fillLayout ); + + htmlClient.setLocation(0, 0); + + + htmlBrowser = new Browser(htmlClient, SWT.BORDER ); + + toolkit.paintBordersFor(htmlClient); + } + + public void viewHTMLAlign(String html, final FormToolkit toolkit) { + htmlBrowser.setText(""); + toolkit.paintBordersFor(htmlClient); + htmlBrowser.setText(html); + toolkit.paintBordersFor(htmlClient); } public void handleEvent(Event e) { @@ -389,6 +408,7 @@ public class AlignView extends ViewPart //this.onlineButton.setExpanded(true); OnlineDialog onDialog = new OnlineDialog( getSite().getShell() ); onDialog.setInput("aserv.inrialpes.fr"); + onDialog.setMessage("URL for alignment server:"); onDialog.open(); if ( !(onDialog.getInput() == null) && !onDialog.getInput().equals("")) { online = true; @@ -401,74 +421,132 @@ public class AlignView extends ViewPart "Impossible connection!"); return; } - if(localAlignBox.getItems()==null || localAlignBox.getItems().length ==0) { - setButtons( 3 ); //no localList, no server list - + onlineButton.setEnabled( false ); + offlineButton.setEnabled( true ); + findButton.setEnabled(true); + findAllButton.setEnabled(true); + serverAlignBox.removeAll(); + serverAlignBox.setEnabled( false ); + serverImportButton.setEnabled( false ); + serverTrimButton.setEnabled( false ); + storeButton.setEnabled( false ); + //fetchButton.setEnabled( false ); + + if(localAlignBox.getItems().length == 0) { + localAlignBox.setEnabled( false ); + localImportButton.setEnabled( false ); + localTrimButton.setEnabled( false ); + uploadButton.setEnabled( false ); + selectedLocalAlign = null; + //setButtons( 3 ); //no localList, no server list } else { - setButtons( 6 ); //with localList, no server list + localAlignBox.setEnabled( true ); + localImportButton.setEnabled( true ); + localTrimButton.setEnabled( true ); + uploadButton.setEnabled( true ); + } selectedOnto1 = null; selectedOnto2 = null; selectedServerAlign = null; - selectedLocalAlign = null; methods.removeAll(); selectedMethod = list[0]; methods.setItems( list ); methods.select(0); methods.redraw(); + ontoByProj = this.refreshOntoList( online ); } } else if ( e.getSource().equals( this.offlineButton ) ) { offlineInit( false ); + } else if (e.getSource() == ontoBox1) { + int index = ontoBox1.getSelectionIndex(); + selectedOnto1 = ontoBox1.getItem(index); + + } else if (e.getSource() == ontoBox2) { + int index = ontoBox2.getSelectionIndex(); + selectedOnto2 = ontoBox2.getItem(index); + + } else if (e.getSource() == methods) { + int index = methods.getSelectionIndex(); + selectedMethod = methods.getItem(index); } else if (e.getSource() == onto1Refresh) { ontoByProj = this.refreshOntoList( online ); } else if (e.getSource() == onto2Refresh) { ontoByProj = this.refreshOntoList( online ); + + } else if (e.getSource() == serverAlignBox) { + int index = serverAlignBox.getSelectionIndex(); + selectedServerAlign = serverAlignBox.getItem(index); + + } else if (e.getSource() == localAlignBox) { + int index = localAlignBox.getSelectionIndex(); + selectedLocalAlign = localAlignBox.getItem(index); + + //processing ontology matching } else if (e.getSource() == matchButton) { + selectedOnto1 = ontoBox1.getText(); + selectedOnto2 = ontoBox2.getText(); + if (selectedOnto1 == null || selectedOnto2 == null ) { MessageDialog.openError(this.getSite().getShell(), "Error message", - "Choose two ontologies from lists! "); + "Choose two ontologies from the lists! "); return; } if( online ) { if (!selectedOnto1.startsWith("http://") || !selectedOnto2.startsWith("http://") ) { - MessageDialog.openError(this.getSite().getShell(), "Error message", "URLs for ontologies are required."); + MessageDialog.openError(this.getSite().getShell(), "Error message", "Ontology URLs are required."); return; } - if( selectedMethod.equals("fr.inrialpes.exmo.align.service.WSAlignment")) { - + if( selectedMethod.equals("fr.inrialpes.exmo.align.service.WSAlignment") ) { WSDialog pa = new WSDialog( getSite().getShell() ); - if( pa.getServerInput() == null || pa.getServerInput().equals("")) { - MessageDialog.openError(this.getSite().getShell(), "Error message", "No server!"); + pa.setServerInput("http://kameleon.ijs.si/ontolight/ontolight.asmx"); + pa.open(); + + if( pa.getServerInput().equals("")) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "No available server!"); return; } else { wserver = pa.getServerInput(); wsmethod = pa.getMethodInput(); String alignId = onlineAlign.getAlignIdMonoThread( selectedMethod, wserver, wsmethod, selectedOnto1, selectedOnto2 ); - String[] list = new String[1]; - list[0] = alignId; - selectedServerAlign = alignId; - serverAlignBox.removeAll(); - serverAlignBox.setItems(list); + if( alignId == null || alignId .equals("")) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "Alignment is not produced."); + return; + } + + serverAlignBox.add(alignId, 0); + selectedServerAlign = alignId; + serverImportButton.setEnabled( true ); + serverTrimButton.setEnabled( true ); + storeButton.setEnabled( true ); serverAlignBox.select(0); serverAlignBox.redraw(); } } else { - //resetActionButtons( false ); + String alignId = onlineAlign.getAlignIdMonoThread( selectedMethod, wserver, wsmethod, selectedOnto1, selectedOnto2 ); + if( alignId == null || alignId .equals("")) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "Alignment is not produced."); + return; + } //onAlign.getAlignId( matchMethod, wserver, wsmethod, selectedOnto1, selectedOnto2 ); - String[] list = new String[1]; - list[0] = alignId; - selectedServerAlign = list[0]; - serverAlignBox.removeAll(); + + serverAlignBox.add(alignId, 0); + selectedServerAlign = alignId; + serverAlignBox.setEnabled( true ); + serverImportButton.setEnabled( true ); + serverTrimButton.setEnabled( true ); + storeButton.setEnabled( true ); + //fetchButton.setEnabled( true ); + serverAlignBox.select(0); serverAlignBox.redraw(); - } //String answer = onAlign.getAlignId( matchMethod, selectedOnto1, selectedOnto2 ); @@ -489,19 +567,286 @@ public class AlignView extends ViewPart String resId = offlineAlign.matchAndExportAlign( selectedMethod, ontoByProj.get(selectedOnto1), selectedOnto1, ontoByProj.get(selectedOnto2), selectedOnto2); - localAlignBox.removeAll(); - String[] list = new String[1]; + //localAlignBox.removeAll(); - //File f1 = new File(resId); - list[0] = resId;//"file:" + f1.getAbsolutePath(); - - localAlignBox.setItems(list); - selectedLocalAlign = list[0]; + localAlignBox.setEnabled( true ); + localImportButton.setEnabled( true ); + localTrimButton.setEnabled( true ); + + localAlignBox.add(resId, 0); + selectedLocalAlign = resId; localAlignBox.select(0); localAlignBox.redraw(); - } //offline - } else if (e.getSource() == localImportButton) {//matchButton + //processing alignment fetching + } else if (e.getSource() == storeButton) { + if(selectedServerAlign == null) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "Choose an alignment ID from the list!"); + return; + } + + String sto = onlineAlign.storeAlign(selectedServerAlign); + + if(sto == null || sto.equals("") ) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "Alignment cannot be stored!"); + return; + } else { + MessageDialog.openConfirm(this.getSite().getShell(), "Confirmation", "Alignment: "+ selectedServerAlign + "\n is stored!"); + } + + } else if (e.getSource() == serverTrimButton) { + + if(selectedServerAlign == null) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "Choose an alignment ID from the list!"); + return; + } + + OnlineDialog trimDialog = new OnlineDialog( getSite().getShell() ); + trimDialog.setInput("0.5"); + trimDialog.setMessage("Threshold:"); + trimDialog.open(); + String thres = trimDialog.getInput(); + if ( trimDialog.getInput() == null) return; + if ( trimDialog.getInput().equals("")) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "Invalid threshold!"); + return; + } + + String at = onlineAlign.trimAlign(selectedServerAlign, thres); + if(at == null) return; + if(at.equals("")) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "No alignment is obtained!"); + return; + } + + serverAlignBox.add( at, 0 ); + selectedServerAlign = at; + serverAlignBox.select(0); + serverAlignBox.redraw(); + + } else if (e.getSource() == localTrimButton) { + if(selectedLocalAlign == null) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "Choose an alignment ID from the list!"); + return; + } + + OnlineDialog trimDialog = new OnlineDialog( getSite().getShell() ); + trimDialog.setInput("0.5"); + trimDialog.setMessage("Threshold:"); + trimDialog.open(); + String thres = trimDialog.getInput(); + if ( trimDialog.getInput() == null) return; + if ( trimDialog.getInput().equals("")) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "Invalid threshold!"); + return; + } + + String resId = offlineAlign.trimAndExportAlign( new Double(thres), selectedLocalAlign ); + + localAlignBox.add( resId, 0 ); + selectedLocalAlign = resId; + localAlignBox.select(0); + localAlignBox.redraw(); + + } else if (e.getSource() == serverImportButton) { + + if(selectedServerAlign == null) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "Choose an alignment ID from the list!"); + return; + } + + onlineAlign.getRDFAlignmentMonoThread( selectedServerAlign ); + + String inputName = null; + + FileWriter out = null; + + //export to local List + + String rdfalignStr = onlineAlign.getRDFAlignmentParsed( );// selectedAlign , alignImportButton, alignStoreButton, + //serverAlignTrimButton, allAlignButton, alignFindButton, mapButton ); + + String alignKey = alignFolder.getAbsolutePath() + File.separator + getNewAlignId(); + + localAlignBox.add(alignKey, 0); + selectedLocalAlign = alignKey; + localAlignBox.select(0); + localAlignBox.redraw(); + + String rdfPath = alignKey + ".rdf"; + + URIAlignment align = null; + String owlalignStr = null; + + try { + + File rdfFile = new File( rdfPath ); + + out = new FileWriter( rdfFile ); + out.write( rdfalignStr ); + out.flush(); + out.close(); + + File file = new File(rdfPath); + + AlignmentParser ap = new AlignmentParser(0); + ap.setEmbedded( true ); + align = (URIAlignment)ap.parse(file.toURI().toString()); + + AlignView.alignmentTable.put( alignKey , (Alignment)align ); + + StringWriter htmlMessage = new StringWriter(); + AlignmentVisitor htmlV = new HTMLRendererVisitor( new PrintWriter ( htmlMessage ) ); + + align.render( htmlV ); + + if(htmlMessage.toString()==null || htmlMessage.toString().equals("")) { + viewHTMLAlign( "", formToolkit ); + } else { + viewHTMLAlign( htmlMessage.toString(), formToolkit ); + } + //get align from server, then export it as owl onto + StringWriter owlMessage = new StringWriter(); + AlignmentVisitor owlV = new OWLAxiomsRendererVisitor( new PrintWriter ( owlMessage ) ); + ObjectAlignment al = ObjectAlignment.toObjectAlignment( (URIAlignment)align ); + //BasicAlignment al = (BasicAlignment)align; + al.render( owlV ); + + owlalignStr = owlMessage.toString(); + + } + catch ( Exception ex ) { ex.printStackTrace();}; + + + if(owlalignStr==null) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "OWL alignment cannot be imported."); + return; + } + + try { + + OnlineDialog localImportDialog = new OnlineDialog( getSite().getShell() ); + localImportDialog.setInput("AlignmentProject"); + localImportDialog.setMessage("Enter a project name:"); + localImportDialog.open(); + inputName = localImportDialog.getInput(); + + if (inputName==null || inputName.equals("")) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "Project name is not valid!"); + return; + } + + String[] projects = DatamodelPlugin.getDefault().getOntologyProjects(); + if(projects!=null) { + boolean found = false; + + for(int i=0; i < projects.length; i++) { + + if(projects[i].equals(inputName)) { + found = true;break; + } + } + + if(!found) { + + Properties proper = new Properties(); + proper.put(IConfig.ONTOLOGY_LANGUAGE.toString(), IConfig.OntologyLanguage.OWL.toString()); + new CreateProject( inputName, DatamodelTypes.RAM, proper ).run(); + } + } + + String owlPath = ontoFolder.getAbsolutePath() + File.separator + getNewAlignId() + ".owl"; + File owlFile = new File( owlPath ); + if (owlFile.exists()) owlFile.delete(); + + out = new FileWriter( owlFile ); + out.write( owlalignStr ); + out.flush(); + out.close(); + + try { + ImportExportControl ieControl = new ImportExportControl(); + URI uris[] = new URI[1]; + uris[0] = new File( owlPath).toURI(); + String[] importedModules = ieControl.importFileSystem(inputName, uris, null); + + //ieControl.addOntologies2Project(importedModules, inputName); + } catch ( ControlException ex ) { } + + } + catch ( Exception ex ) { ex.printStackTrace();} + + } else if (e.getSource() == localImportButton) { + if(selectedLocalAlign == null) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "Choose an alignment ID from list!"); + return; + } + + File fn = new File(selectedLocalAlign + ".owl"); + + + StringWriter htmlMessage = new StringWriter(); + AlignmentVisitor htmlV = new HTMLRendererVisitor( new PrintWriter ( htmlMessage ) ); + + try { + AlignView.alignmentTable.get(selectedLocalAlign).render( htmlV ); + + viewHTMLAlign( htmlMessage.toString(), formToolkit ); + + String inputName=null; + OnlineDialog localImportDialog = new OnlineDialog( getSite().getShell() ); + localImportDialog.setInput("AlignmentProject"); + localImportDialog.setMessage("Enter a project name:"); + localImportDialog.open(); + inputName = localImportDialog.getInput(); + + if (inputName==null || inputName.equals("")) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "Project name is not valid!"); + return; + } + + String[] projects = DatamodelPlugin.getDefault().getOntologyProjects(); + + if(projects!=null) { + boolean found = false; + + for(int i=0; i < projects.length; i++) { + if(projects[i].equals(inputName)) { + found = true;break; + } + } + + if(!found) { + Properties proper = new Properties(); + proper.put(IConfig.ONTOLOGY_LANGUAGE.toString(), IConfig.OntologyLanguage.OWL.toString()); + new CreateProject( inputName, DatamodelTypes.RAM, proper ).run(); + + } + + ImportExportControl ieControl = new ImportExportControl(); + URI uris[] = new URI[1]; + uris[0] = new File(fn.getAbsolutePath()).toURI(); + ieControl.importFileSystem(inputName, uris, null); + + } + } + catch ( Exception ex ) { ex.printStackTrace();}; + + } else if (e.getSource() == uploadButton) { + if(selectedLocalAlign == null) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "Choose an alignment ID from the list!"); + return; + } + String uploadedId = null; + try { + uploadedId = onlineAlign.uploadAlign(selectedLocalAlign + ".rdf"); + if(uploadedId == null) { + MessageDialog.openError(this.getSite().getShell(), "Error message", "Alignment cannot be uploaded!"); + return; + } + + MessageDialog.openConfirm(this.getSite().getShell(), "Confirmation", "Alignment is uploaded with ID: \n" + uploadedId); + } catch ( Exception ex ) { ex.printStackTrace();} } else if ( e.getSource().equals( this.findAllButton ) ) { @@ -522,7 +867,7 @@ public class AlignView extends ViewPart serverAlignBox.redraw(); offList = offlineAlign.getAllAlign( ); - if( offList != null && offList.length > 0 ) { + if( offList.length > 0 ) { //localAlignBox.setEnabled( true ); localAlignBox.removeAll(); localAlignBox.setItems( offList ); @@ -530,24 +875,28 @@ public class AlignView extends ViewPart localAlignBox.select(0); localAlignBox.redraw(); } + } + + if(onList.length > 0 ) { + serverAlignBox.setEnabled( true ); + serverImportButton.setEnabled( true ); + serverTrimButton.setEnabled( true ); + storeButton.setEnabled( true ); + //fetchButton.setEnabled( true ); } - - if( onList.length > 0 && (offList.length > 0) ) { - setButtons( 7 ); - } - else if( onList.length == 0 && offList.length > 0 ) - setButtons( 6 ); - else if( onList.length == 0 && offList.length == 0 ) - setButtons( 3 ); - else if( onList.length >0 && offList.length == 0 ) { - //System.out.println("OK "); - setButtons( 8 ); + if(offList.length > 0 ) { + uploadButton.setEnabled( true ); + localAlignBox.setEnabled( true ); + localImportButton.setEnabled( true ); + localTrimButton.setEnabled( true ); } } else if ( e.getSource().equals( this.findButton ) ) { String[] onList = null; + selectedOnto1 = ontoBox1.getText(); + selectedOnto2 = ontoBox2.getText(); if(online) { if(selectedOnto1 == null || selectedOnto1.equals("") || selectedOnto2 == null || selectedOnto2.equals("")) { - MessageDialog.openError(this.getSite().getShell(), "Error message", "Please choose ontologies."); + MessageDialog.openError(this.getSite().getShell(), "Error message", "Choose two ontologies from the lists!"); return; } onList = onlineAlign.findAlignForOntos( selectedOnto1, selectedOnto2); @@ -555,16 +904,50 @@ public class AlignView extends ViewPart MessageDialog.openError(this.getSite().getShell(), "Error message", "No available alignment."); return; } - serverAlignBox.setEnabled( true ); serverAlignBox.removeAll(); - serverAlignBox.setItems(onList); - selectedServerAlign = onList[0]; - serverAlignBox.select(0); + + if(onList.length > 0) { + serverAlignBox.setEnabled( true ); + serverAlignBox.setItems(onList); + selectedServerAlign = onList[0]; + serverImportButton.setEnabled( true ); + serverTrimButton.setEnabled( true ); + storeButton.setEnabled( true ); + //fetchButton.setEnabled( true ); + serverAlignBox.select(0); + } else { + selectedServerAlign = null; + serverAlignBox.setEnabled( false ); + serverImportButton.setEnabled( false ); + serverTrimButton.setEnabled( false ); + storeButton.setEnabled( false ); + //fetchButton.setEnabled( false ); + } serverAlignBox.redraw(); } } } + public static int getNewAlignId() { + + boolean found = false; + alignId++; + while(!found) { + + boolean sw = false; + for(int i=0;i< forUniqueness.length; i++) + if(forUniqueness[i].equals((new Integer(alignId)).toString())) { + alignId++; + sw = true; + break; + } + + if( !sw ) found = true; + + } + + return alignId; + } void offlineInit(boolean init) { online = false; @@ -594,10 +977,11 @@ public class AlignView extends ViewPart selectedMethod = methodList[0]; methods.removeAll(); methods.setItems( methodList ); + methods.setEnabled(true); methods.select(0); methods.redraw(); - System.out.println( "alignFolder=" + alignFolder ); + //System.out.println( "alignFolder=" + alignFolder ); offlineAlign = new OfflineAlign( alignFolder, ontoFolder ); @@ -609,28 +993,19 @@ public class AlignView extends ViewPart String[] list = offlineAlign.getAllAlign(); localAlignBox.removeAll(); - if(list != null && list.length > 0) { + if( list.length > 0) { + forUniqueness = new String[list.length]; for(int i=0; i< list.length; i++){ - System.out.println( "filename=" + list[i] ); + //System.out.println( "filename=" + list[i] ); File f = new File(list[i]); forUniqueness[i] = f.getName(); } localAlignBox.setItems( list ); selectedLocalAlign = list[0]; - setButtons( 1 ); + localAlignBox.select(0); - } else { - setButtons( 0 ); - } - } - - void setButtons( int status ) { - switch (status) { - case 0 : // activate offline no localList - onlineButton.setEnabled( true ); - offlineButton.setEnabled( false ); findButton.setEnabled(false); findAllButton.setEnabled(false); @@ -638,17 +1013,16 @@ public class AlignView extends ViewPart serverImportButton.setEnabled( false ); serverTrimButton.setEnabled( false ); storeButton.setEnabled( false ); - fetchButton.setEnabled( false ); + //fetchButton.setEnabled( false ); uploadButton.setEnabled( false ); - localAlignBox.setEnabled( false ); - localImportButton.setEnabled( false ); - localTrimButton.setEnabled( false ); - break; + localAlignBox.setEnabled( true ); + localImportButton.setEnabled( true ); + localTrimButton.setEnabled( true ); - case 1 : // activate offline with localList - onlineButton.setEnabled( true ); - offlineButton.setEnabled( false ); + } else { + //setButtons( 0 ); + selectedLocalAlign = null; findButton.setEnabled(false); findAllButton.setEnabled(false); @@ -656,149 +1030,28 @@ public class AlignView extends ViewPart serverImportButton.setEnabled( false ); serverTrimButton.setEnabled( false ); storeButton.setEnabled( false ); - fetchButton.setEnabled( false ); + //fetchButton.setEnabled( false ); uploadButton.setEnabled( false ); - localAlignBox.setEnabled( true ); - localImportButton.setEnabled( true ); - localTrimButton.setEnabled( true ); - break; - - case 2 : // activate online no list - onlineButton.setEnabled( false ); - offlineButton.setEnabled( true ); - findButton.setEnabled(true); - findAllButton.setEnabled(true); - - serverAlignBox.setEnabled( false ); - serverImportButton.setEnabled( false ); - serverTrimButton.setEnabled( false ); - storeButton.setEnabled( false ); - fetchButton.setEnabled( false ); - uploadButton.setEnabled( false ); - - - localAlignBox.setEnabled( false ); - localImportButton.setEnabled( false ); - localTrimButton.setEnabled( false ); - break; - - case 3 : // activate online no localList (no server List) - onlineButton.setEnabled( false ); - offlineButton.setEnabled( true ); - findButton.setEnabled(true); - findAllButton.setEnabled(true); - - serverAlignBox.setEnabled( false ); - serverImportButton.setEnabled( false ); - serverTrimButton.setEnabled( false ); - storeButton.setEnabled( false ); - fetchButton.setEnabled( false ); - uploadButton.setEnabled( false ); - - - localAlignBox.setEnabled( false ); - localImportButton.setEnabled( false ); - localTrimButton.setEnabled( false ); - break; - - case 4 : // activate online align. not available - onlineButton.setEnabled( false ); - offlineButton.setEnabled( true ); - findButton.setEnabled(true); - findAllButton.setEnabled(true); - - serverAlignBox.setEnabled( true ); - serverImportButton.setEnabled( true ); - serverTrimButton.setEnabled( false ); - storeButton.setEnabled( false ); - fetchButton.setEnabled( true ); - uploadButton.setEnabled( true ); - - - localAlignBox.setEnabled( true ); - localImportButton.setEnabled( true ); - localTrimButton.setEnabled( true ); - break; - - case 5 : // activate online align available - onlineButton.setEnabled( false ); - offlineButton.setEnabled( true ); - findButton.setEnabled(true); - findAllButton.setEnabled(true); - - serverAlignBox.setEnabled( true ); - serverImportButton.setEnabled( true ); - serverTrimButton.setEnabled( true ); - storeButton.setEnabled( true ); - fetchButton.setEnabled( true ); - uploadButton.setEnabled( true ); - - - localAlignBox.setEnabled( true ); - localImportButton.setEnabled( true ); - localTrimButton.setEnabled( true ); - break; - - case 6 : // activate online with localList (no serverList) - onlineButton.setEnabled( false ); - offlineButton.setEnabled( true ); - findButton.setEnabled( true ); - findAllButton.setEnabled( true ); - - serverAlignBox.setEnabled( false ); - serverImportButton.setEnabled( false ); - serverTrimButton.setEnabled( false ); - storeButton.setEnabled( false ); - fetchButton.setEnabled( false ); - uploadButton.setEnabled( true ); - - localAlignBox.setEnabled( true ); - localImportButton.setEnabled( true ); - localTrimButton.setEnabled( true ); - break; - - case 7 : // activate online with both Lists - onlineButton.setEnabled( false ); - offlineButton.setEnabled( true ); - findButton.setEnabled( true ); - findAllButton.setEnabled( true ); - - serverAlignBox.setEnabled( true ); - serverImportButton.setEnabled( false ); - serverTrimButton.setEnabled( false ); - storeButton.setEnabled( false ); - fetchButton.setEnabled( true ); - uploadButton.setEnabled( true ); - - localAlignBox.setEnabled( true ); - localImportButton.setEnabled( true ); - localTrimButton.setEnabled( true ); - break; - - case 8 : // activate online with server list but no local list - onlineButton.setEnabled( false ); - offlineButton.setEnabled( true ); - findButton.setEnabled( true ); - findAllButton.setEnabled( true ); - - serverAlignBox.setEnabled( true ); - serverImportButton.setEnabled( false ); - serverTrimButton.setEnabled( false ); - storeButton.setEnabled( false ); - fetchButton.setEnabled( true ); - uploadButton.setEnabled( true ); - - localAlignBox.setEnabled( false ); - localImportButton.setEnabled( false ); - localTrimButton.setEnabled( false ); - break; - default: - break; + localAlignBox.setEnabled( false ); + localImportButton.setEnabled( false ); + localTrimButton.setEnabled( false ); } + ontoBox1.setEnabled(true); + ontoBox1.redraw(); + onto1Refresh.setEnabled(true); + //onto1Refresh.redraw(); + ontoBox2.setEnabled(true); + ontoBox2.redraw(); + onto2Refresh.setEnabled(true); + onlineButton.setEnabled( true ); + offlineButton.setEnabled( false ); + //onto2Refresh.redraw(); + localAlignBox.redraw(); + ontoByProj = this.refreshOntoList( online ); + } - - + private HashMap<String,String> refreshOntoList(boolean online) { HashMap<String,String> vec = new HashMap<String,String>(); OWLAPIOntologyFactory fact = new OWLAPIOntologyFactory(); diff --git a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OfflineAlign.java b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OfflineAlign.java index ffce916415be7783d3b7e9430019b156dda94a45..28ac1b23f7c6f9c1a26538a2a90ee1d1020d81b7 100755 --- a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OfflineAlign.java +++ b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OfflineAlign.java @@ -66,8 +66,8 @@ public class OfflineAlign { //export ontologies ImportExportControl ieControl = new ImportExportControl(); - //Integer name1 = new Integer(SWTInterface.alignId++); - //Integer name2 = new Integer(SWTInterface.alignId++); + //Integer name1 = new Integer(AlignView.alignId++); + //Integer name2 = new Integer(AlignView.alignId++); File f1 = new File( selectedNeOnOnto1.replace("file:","") ); File f2 = new File( selectedNeOnOnto2.replace("file:","") ); @@ -81,7 +81,7 @@ public class OfflineAlign { AlignmentProcess A1 = null; //String htmlString = null; //Vector corrList = new Vector(); - Integer name = new Integer(SWTInterface.getNewAlignId()); + Integer name = new Integer(AlignView.getNewAlignId()); try { @@ -99,8 +99,8 @@ public class OfflineAlign { A1.align((Alignment)null,p); - //SWTInterface.alignObjects.clear(); - SWTInterface.alignmentTable.put( alignFolder.getAbsolutePath() + File.separator + name.toString(), (Alignment)A1 ); + //AlignView.alignObjects.clear(); + AlignView.alignmentTable.put( alignFolder.getAbsolutePath() + File.separator + name.toString(), (Alignment)A1 ); //for saving locally @@ -130,9 +130,9 @@ public class OfflineAlign { String trimAndExportAlign (Double thres, String id) { - Integer name = new Integer(SWTInterface.getNewAlignId()); + Integer name = new Integer(AlignView.getNewAlignId()); - Alignment A1 = SWTInterface.alignmentTable.get( id ); + Alignment A1 = AlignView.alignmentTable.get( id ); //BasicAlignment clonedA1 = (BasicAlignment)((BasicAlignment)A1).clone(); BasicAlignment clonedA1 = null; @@ -155,7 +155,7 @@ public class OfflineAlign { rdfF.close(); clonedA1.cut(thres); - SWTInterface.alignmentTable.put( alignFolder.getAbsolutePath() + File.separator + name.toString(), clonedA1 ); + AlignView.alignmentTable.put( alignFolder.getAbsolutePath() + File.separator + name.toString(), clonedA1 ); File owlFile = new File( ontoFolder.getAbsolutePath() + File.separator + name.toString()+ ".owl"); if (owlFile.exists()) owlFile.delete(); @@ -176,10 +176,10 @@ public class OfflineAlign { public String[] getAllAlign() { - if (SWTInterface.alignmentTable.keys() == null) return null; + if (AlignView.alignmentTable.keys() == null) return null; Vector<String> v = new Vector<String>(); - for (Enumeration e = SWTInterface.alignmentTable.keys() ; e.hasMoreElements() ;) { + for (Enumeration e = AlignView.alignmentTable.keys() ; e.hasMoreElements() ;) { v.add((String)e.nextElement()); } @@ -206,7 +206,7 @@ public class OfflineAlign { String key = v.get(i).replace(".rdf", ""); //System.out.println("Path ="+ alignFolder.getAbsolutePath() + File.separator + v.get(i) ); - SWTInterface.alignmentTable.put( alignFolder.getAbsolutePath() + File.separator + key , + AlignView.alignmentTable.put( alignFolder.getAbsolutePath() + File.separator + key , parser.parse(alignFolder.getAbsolutePath() + File.separator + v.get(i)) ); } diff --git a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OnlineAlign.java b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OnlineAlign.java index 33acc43387dfccb20ff78ebb381ac39fa99b4b72..323be34cdd6c101e3aad3734304841ceb058c134 100755 --- a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OnlineAlign.java +++ b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OnlineAlign.java @@ -179,7 +179,7 @@ public class OnlineAlign { // Send message //System.out.println("Trim Message="+ message); - answer = sendMessage( message, params ); + answer = sendMessageMonoThread( message, params ); //System.out.println("Trim Align="+ answer); } @@ -224,7 +224,7 @@ public class OnlineAlign { //System.out.println("Message (methods) :"+ message); // Send message - answer = sendMessage( message, params ); + answer = sendMessageMonoThread( message, params ); } catch ( Exception ex ) { ex.printStackTrace(); }; //if(! connected ) return null; @@ -266,7 +266,7 @@ public class OnlineAlign { //System.out.println("Message :"+ message); // Send message - answer = sendMessage( message, params ); + answer = sendMessageMonoThread( message, params ); //System.out.println("answer find=" + answer); } catch ( Exception ex ) { ex.printStackTrace(); }; @@ -311,7 +311,7 @@ public class OnlineAlign { //System.out.println("Message :"+ message); // Send message - answer = sendMessage( message, params ); + answer = sendMessageMonoThread( message, params ); //System.out.println("Answer get All :"+ answer); } catch ( Exception ex ) { ex.printStackTrace(); }; @@ -409,7 +409,7 @@ public class OnlineAlign { // Send message //answer = sendMessage( message, params ); - sendMessage( message, params ); + sendMessageMonoThread( message, params ); //System.out.println("SOAP Match align=" + answer ); @@ -482,7 +482,7 @@ public class OnlineAlign { //System.out.println("Message :" + message); // Send message - answer = sendMessage( message, params ); + answer = sendMessageMonoThread( message, params ); //if(! connected ) return null; } catch ( Exception ex ) { ex.printStackTrace(); }; @@ -554,7 +554,7 @@ public class OnlineAlign { //answer = sendMessage( message, params ); //the result is put in "globalAnswer" - sendMessage( message, params ); + sendMessageMonoThread( message, params ); //if(! connected ) return null; } catch ( Exception ex ) { ex.printStackTrace(); }; @@ -638,7 +638,7 @@ public class OnlineAlign { //System.out.println("Message :"+ message); // Send message - answer = sendMessage( message, params ); + answer = sendMessageMonoThread( message, params ); } catch ( Exception ex ) { ex.printStackTrace() ;}; @@ -901,30 +901,7 @@ public class OnlineAlign { out.close( ); if( param.getParameter("command").equals("retrieve") ) { - /* - try { - - AlignmentParser parser = new AlignmentParser( 0 ); - parser.initAlignment( null ); - parser.setEmbedded( true ); - BasicAlignment clonedA1 = (BasicAlignment) parser.parse( httpConn.getInputStream() ); - - StringWriter sw = new StringWriter(); - AlignmentVisitor rdfV = new RDFRendererVisitor( new PrintWriter ( sw ) ); - clonedA1.render( rdfV ); - answer = sw.toString(); - - - } catch (SAXException saxex) { - throw new AlignmentException( "Malformed XML/SOAP result ("+saxex.getMessage()+")", saxex ); - } catch (IOException ioex) { - throw new AlignmentException( "XML/SOAP parsing error", ioex ); - } catch (javax.xml.parsers.ParserConfigurationException pcex) { - throw new AlignmentException( "XML/SOAP parsing error", pcex ); - } - - System.out.println("RDF=" + answer ); - */ + InputStreamReader isr = new InputStreamReader(httpConn.getInputStream()); BufferedReader in = new BufferedReader(isr); @@ -962,224 +939,7 @@ public class OnlineAlign { return answer; } - public String sendMessage( String message, Parameters param ) { - // Create the connection - - byte[] b = message.getBytes(); - - String answer = ""; - - // Create HTTP Request - try { - - URLConnection connection = SOAPUrl.openConnection(); - HttpURLConnection httpConn = (HttpURLConnection) connection; - globalConn = httpConn; - - globalConn.setRequestProperty( "Content-Length", - String.valueOf( b.length ) ); - globalConn.setRequestProperty("Content-Type","text/xml; charset=utf-8"); - globalConn.setRequestProperty("SOAPAction",SOAPAction); - globalConn.setRequestMethod( "POST" ); - globalConn.setDoOutput(true); - globalConn.setDoInput(true); - - // Send the request through the connection - OutputStream out = globalConn.getOutputStream(); - - out.write( b ); - out.close(); - - if( param.getParameter("command").equals("match") ) { - - globalAnswer = ""; - - - Thread th = new Thread() { - - public void run() { - ProgressMonitor pm = null; - - try { - - //JOptionPane.showMessageDialog(null, "Matching ontologies may be long.","Warning",2); - - InputStreamReader isr = new InputStreamReader( globalConn.getInputStream() ); - BufferedReader in = new BufferedReader(isr); - String line; - - //String alignRes = ""; - StringBuffer strBuff = new StringBuffer(); - while ((line = in.readLine()) != null) { - //alignRes += line + "\n"; - strBuff.append(line + "\n"); - } - - //String alignId = getAlignIdParsed( alignRes ); - String alignId = getAlignIdParsed( strBuff.toString() ); - if(alignId == null || alignId.equals("")) { - JOptionPane.showMessageDialog(null, "Alignment is not produced.","Warning",2); - SWTInterface.set3Buttons(); - return; - } - - SWTInterface.resetAlignList( alignId ); - globalConn.disconnect(); - - URLConnection connection2 = SOAPUrl.openConnection(); - globalConn2 = (HttpURLConnection) connection2; - - //To fetch alignment from alignId - Parameters params = new BasicParameters(); - params = new BasicParameters(); - params.setParameter( "host", HOST ); - params.setParameter( "command","retrieve"); - params.setParameter( "arg1", alignId); - params.setParameter( "arg2", "fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor"); - //SOAPAction is updated - String message = createMessage( params ); - byte[] bb = message.getBytes(); - - globalConn2.setRequestProperty( "Content-Length", - String.valueOf( bb.length ) ); - globalConn2.setRequestProperty("Content-Type","text/xml; charset=utf-8"); - globalConn2.setRequestProperty("SOAPAction",SOAPAction); - globalConn2.setRequestMethod( "POST" ); - globalConn2.setDoOutput(true); - globalConn2.setDoInput(true); - - // Send the request through the connection - OutputStream out2 = globalConn2.getOutputStream(); - - out2.write( bb ); - out2.close(); - - int maxSize = 5000000; - //ProgressMonitor pm2 = null; - String mess = "Fetching alignment from server..."; - - ProgressMonitorInputStream pin = new ProgressMonitorInputStream( null, mess, globalConn2.getInputStream() ); - pm = pin.getProgressMonitor(); - pm.setMaximum( maxSize ); - pm.setMillisToPopup( 1 ); - pm.setMillisToDecideToPopup( 2 ); - - InputStreamReader isr2 = new InputStreamReader(pin); - BufferedReader in2 = new BufferedReader(isr2); - - //String line; - int co = 0; - StringBuffer strBuff2 = new StringBuffer(); - while ((line = in2.readLine()) != null) { - strBuff2.append( line + "\n"); - //globalAnswer += line + "\n"; - co += line.length(); - pm.setNote(co + " bytes read."); - if( co >= maxSize -10000 ) { - maxSize = co + line.length() + maxSize; - pm.setMaximum( maxSize ); - pm.setProgress( co ); - } - } - globalAnswer = strBuff2.toString(); - - SWTInterface.resetActionButtons( true ); - - pm.setProgress( maxSize - 1 ); - pin.close(); - } catch (Exception e) { - - if( pm.isCanceled()) { - SWTInterface.set3Buttons(); - } - e.printStackTrace(); - } - } - }; - - th.start(); - - } else if( param.getParameter("command").equals("retrieve") ) { //|| param.getParameter("command").equals("match")) { - - globalAnswer = ""; - Thread th = new Thread() { - - public void run() { - ProgressMonitor pm = null; - try { - - String mess = "Fetching alignment from server,"; - int maxSize = 5000000; // size in byte - - ProgressMonitorInputStream pin = new ProgressMonitorInputStream( null, mess, globalConn.getInputStream() ); - - pm = pin.getProgressMonitor(); - pm.setMaximum( maxSize ); - pm.setMillisToPopup( 1 ); - pm.setMillisToDecideToPopup( 2 ); - - InputStreamReader isr = new InputStreamReader(pin); - BufferedReader in = new BufferedReader(isr); - - String line; - int co = 0; - StringBuffer strBuff3 = new StringBuffer(); - - while ((line = in.readLine()) != null) { - //globalAnswer += line + "\n"; - strBuff3.append( line + "\n" ); - co += line.length(); - pm.setNote(co + " bytes read."); - if( co >= maxSize -10000 ) { - maxSize = co + line.length() + maxSize; - pm.setMaximum( maxSize ); - pm.setProgress( co ); - } - } - globalAnswer = strBuff3.toString(); - SWTInterface.resetActionButtons( true ); - - pm.setProgress( maxSize - 1 ); - pin.close(); - } catch (Exception e) { - - if( pm.isCanceled() ) { - SWTInterface.set3Buttons( ); - } - e.printStackTrace(); - } - } - }; - - th.start(); - - } else { - - InputStreamReader isr = new InputStreamReader( httpConn.getInputStream() ); - BufferedReader in = new BufferedReader( isr ); - String line; - StringBuffer strBuff4 = new StringBuffer(); - while ((line = in.readLine()) != null) { - strBuff4.append( line + "\n" ); - //answer += line + "\n"; - } - answer = strBuff4.toString(); - in.close(); - } - //System.out.println("answer= " + answer); - - if(httpConn.HTTP_REQ_TOO_LONG == httpConn.getResponseCode()) System.err.println("Request too long"); - - //if(httpConn.HTTP_OK == httpConn.getResponseCode()) System.out.println("Request OK"); - - } catch (Exception ex) { - connected= false; ex.printStackTrace() ; return null; - } - - connected = true; - - return answer; - } + public String sendFile( String message, Parameters param ) { // Create the connection diff --git a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OnlineDialog.java b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OnlineDialog.java index 565593594d3ba42857d920bb9e30e9157e3535c3..123df2ab0881b5c6ede8c8a4a5c4012eb8c48ee8 100644 --- a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OnlineDialog.java +++ b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OnlineDialog.java @@ -47,8 +47,7 @@ public class OnlineDialog extends Dialog { public OnlineDialog(Shell parent, int style) { // Let users override the default styles super(parent, style); - setText("Alignment Server"); - setMessage("Please enter server URL:"); + setText("Input"); } public String getMessage() { @@ -100,7 +99,7 @@ public class OnlineDialog extends Dialog { // Display the input box final Text text = new Text(shell, SWT.BORDER); - text.setText("aserv.inrialpes.fr"); + text.setText(input); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; text.setLayoutData(data); diff --git a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/SWTInterface.java b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/SWTInterface.java deleted file mode 100644 index fe57d131e21bc294c31dfac17b9785cefc11d1df..0000000000000000000000000000000000000000 --- a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/SWTInterface.java +++ /dev/null @@ -1,1596 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) INRIA, 2007-2008 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -package fr.inrialpes.exmo.align.plugin.neontk; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileWriter; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.io.InputStream; -import java.io.FileInputStream; -import java.net.MalformedURLException; -import java.net.URI; -import java.awt.Component; -import java.awt.BorderLayout; -import java.awt.FlowLayout; -import java.awt.GridLayout; -import java.awt.Point; -import java.awt.event.ActionListener; -import java.awt.Frame; - -import java.awt.event.ItemListener; -import java.awt.event.ItemEvent; -import java.awt.event.ActionEvent; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Insets; -import java.awt.Toolkit; -import java.util.Properties; -import java.util.Set; -import java.util.Vector; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.HashMap; - -import javax.swing.JLabel; -import javax.swing.JComboBox; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JPanel; -import javax.swing.JFrame; -import javax.swing.JSplitPane; -import javax.swing.JComponent; -import javax.swing.JTextField; -import javax.swing.ProgressMonitor; -import javax.swing.ProgressMonitorInputStream; -//import javax.swing.JFileChooser; -import javax.swing.JTextArea; -import javax.swing.JButton; -import javax.swing.JOptionPane; -import java.awt.event.MouseAdapter; -//import javax.swing.SwingConstants; -import javax.swing.JScrollPane; -import javax.swing.BorderFactory; -import javax.swing.JDialog; -import javax.swing.JEditorPane; -import javax.swing.Timer; -import javax.swing.SwingUtilities; -import org.eclipse.swt.SWT; - -import java.net.HttpURLConnection; - -//import java.net.URL; -import java.net.URLConnection; - - - -//import org.semanticweb.owl.align.AlignmentProcess; -import org.semanticweb.owl.align.Alignment; -//import org.semanticweb.owl.align.AlignmentProcess; -import org.semanticweb.owl.align.AlignmentVisitor; -//import org.semanticweb.owl.align.Parameters; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -//import org.eclipse.core.resources.ResourcesPlugin; -//import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.runtime.IPath; -//import org.eclipse.core.resources.IProject; -//import org.semanticweb.kaon2.api.Ontology; -//import org.semanticweb.kaon2.api.KAON2Connection; -import org.semanticweb.kaon2.api.OntologyManager; -//import org.semanticweb.kaon2.api.KAON2Exception; -//import org.semanticweb.kaon2.api.formatting.OntologyFileFormat; -import com.ontoprise.config.IConfig; -import com.ontoprise.ontostudio.datamodel.DatamodelPlugin; -import com.ontoprise.ontostudio.datamodel.DatamodelTypes; -//import com.ontoprise.ontostudio.gui.navigator.module.ModuleTreeElement; -import com.ontoprise.ontostudio.io.ImportExportControl; -//import com.ontoprise.ontostudio.gui.commands.CreateProject; -import com.ontoprise.ontostudio.gui.commands.project.CreateProject; -import com.ontoprise.ontostudio.datamodel.exception.ControlException; -//import com.ontoprise.ontostudio.gui.navigator.project.ProjectControl; -//import org.semanticweb.kaon2.api.formatting.OntologyFileFormat; -//import org.eclipse.core.runtime.IProgressMonitor; -//import com.ontoprise.ontostudio.owl.datamodel.*; -//import fr.inrialpes.exmo.align.onto.OntologyCache; -import fr.inrialpes.exmo.align.onto.OntologyFactory; -import fr.inrialpes.exmo.align.parser.AlignmentParser; -import fr.inrialpes.exmo.align.onto.owlapi10.OWLAPIOntologyFactory; - -import org.semanticweb.owl.align.Cell; -//import fr.inrialpes.exmo.align.impl.Ontology; -import fr.inrialpes.exmo.align.impl.BasicCell; -//import org.semanticweb.owl.align.Relation; - -import fr.inrialpes.exmo.align.impl.BasicAlignment; -//import fr.inrialpes.exmo.align.impl.BasicParameters; -import fr.inrialpes.exmo.align.impl.ObjectAlignment; -import fr.inrialpes.exmo.align.impl.URIAlignment; -//import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor; -import fr.inrialpes.exmo.align.impl.renderer.HTMLRendererVisitor; -import fr.inrialpes.exmo.align.impl.renderer.OWLAxiomsRendererVisitor; - -public class SWTInterface extends JPanel { - - private static final long serialVersionUID = 330; - - private static JSplitPane _mainSplitter = new JSplitPane (JSplitPane.VERTICAL_SPLIT); - - - JLabel hostName, portName, serverName, methodName;//, alignProjLabel; - - //JComboBox hostList, portList; - - String selectedHost = null; - String selectedPort = null; - String selectedOnto1 = null; - String selectedOnto2 = null; - - String selectedLocalAlign = null; - static String selectedAlign = null; - - public static Hashtable<String,Alignment> alignmentTable = new Hashtable<String,Alignment>(); - static String [] forUniqueness = new String[0]; - static int alignId = 0; - - JComponent phrases; - - JTextField fileName1, fileName2, hostField, portField, serverField, methodField; - SWTInterface frame; - - JEditorPane htmlView; - - JButton cancelButton, discardButton, resButton, ontoRefresh, - localAlignImportButton, alignUploadButton, - localAlignTrimButton, connButton, goButton, offlineButton, onlineButton; - - static JButton alignStoreButton, alignImportButton, serverAlignTrimButton, mapButton, alignFindButton, allAlignButton, fetchButton; - - JDialog connDialog, matchDialog; - //JPanel pane2; - Component result = null; - JComboBox strategy, renderer, localAlignBox, ontoBox1, ontoBox2; - - - static JComboBox alignBox; - JLabel strat, render, ontoLabel1, ontoLabel2, alignLabel, localAlignLabel; - - //lists obtained from from server - public String [] methodList = new String[0]; - - //lists obtained from Neontk - public String [] ontoList = new String[0]; - public HashMap<String,String> onto_proj = new HashMap<String,String>(0); - //public String [] NeOnOntoList = new String[0]; - public static String [] alignIdList = new String[0]; - public String [] localAlignIdList = new String[0]; - - public Vector corrList = new Vector(); - public String [] aservArgs = null; - public String [] aservArgRetrieve = null; - public String [] aservArgAlign = null; - public String [] files = new String[2]; - int ind=0, rend=0, count=0; - - boolean online = false; - //boolean chosenPort = false; - String defaultHost = "aserv.inrialpes.fr"; - //String defaultPort = "8089"; - String defaultPort = "80"; - String matchMethod = "fr.inrialpes.exmo.align.impl.method.NameEqAlignment"; - String wserver = "http://kameleon.ijs.si/ontolight/ontolight.asmx"; - String wsmethod=""; - //rethink - - String alignProject = "AlignmentProject"; - - public OnlineAlign onAlign = null; - public OfflineAlign offAlign = null; - public File ontoFolder = null; - public File alignFolder = null; - public static File basicFolder = null; - - - public void offlineInit(boolean init){ - //OntologyFactory.setDefaultFactory("fr.inrialpes.exmo.align.onto.owlapi2.OWLAPI2OntologyFactory"); - online = false; - offAlign = new OfflineAlign( alignFolder, ontoFolder ); - - ontoBox1.setEnabled(true); - ontoBox2.setEnabled(true); - ontoRefresh.setEnabled(true); - strategy.setEnabled(true); - - mapButton.setEnabled(true); - - localAlignBox.setEnabled(true); - - onlineButton.setEnabled(true); - - localAlignImportButton.setEnabled(true); - allAlignButton.setEnabled(true); - - //threshold.setEnabled(true); - localAlignTrimButton.setEnabled(true); - serverAlignTrimButton.setEnabled(false); - - alignFindButton.setEnabled(false); - - alignImportButton.setEnabled(false); - //fetchButton.setEnabled(false); - alignUploadButton.setEnabled(false); - - alignBox.setEnabled(false); - - alignStoreButton.setEnabled(false); - - offlineButton.setEnabled(false); - - strategy.removeAllItems(); - alignBox.removeAllItems(); - localAlignBox.removeAllItems(); - ontoBox1.removeAllItems(); - ontoBox2.removeAllItems(); - - ontoList = new String[0]; - onto_proj = new HashMap<String,String>(0); - //NeOnOntoList = new String[0]; - alignIdList = new String[0]; - //localAlignIdList = new String[0]; - - selectedOnto1 = null; - selectedOnto2 = null; - selectedAlign = null; - //selectedNeOnOnto1 = null; - //selectedNeOnOnto2 = null; - - //methodList = new String[9]; - methodList = new String[8]; - methodList[0] = "fr.inrialpes.exmo.align.impl.method.NameEqAlignment"; - strategy.addItem(methodList[0]); - methodList[1] = "fr.inrialpes.exmo.align.impl.method.StringDistAlignment"; - strategy.addItem(methodList[1]); - methodList[2] = "fr.inrialpes.exmo.align.impl.method.SMOANameAlignment"; - strategy.addItem(methodList[2]); - methodList[3] = "fr.inrialpes.exmo.align.impl.method.SubsDistNameAlignment"; - strategy.addItem(methodList[3]); - methodList[4] = "fr.inrialpes.exmo.align.impl.method.StrucSubsDistAlignment"; - strategy.addItem(methodList[4]); - methodList[5] = "fr.inrialpes.exmo.align.impl.method.NameAndPropertyAlignment"; - strategy.addItem(methodList[5]); - methodList[6] = "fr.inrialpes.exmo.align.impl.method.ClassStructAlignment"; - strategy.addItem(methodList[6]); - methodList[7] = "fr.inrialpes.exmo.align.impl.method.EditDistNameAlignment"; - strategy.addItem(methodList[7]); - //methodList[8] = "fr.inrialpes.exmo.align.ling.JWNLAlignment"; - //strategy.addItem(methodList[8]); - - if(init) offAlign.getAllAlignFromFiles(); - - String[] list = offAlign.getAllAlign(); - if(list!=null) { - localAlignIdList = new String[list.length]; - localAlignBox.removeAllItems(); - - forUniqueness = new String[list.length]; - - for(int i=0; i< list.length; i++){ - localAlignIdList[i]= list[i]; - localAlignBox.addItem(list[i]); - File f = new File(list[i]); - forUniqueness[i] = f.getName(); - } - - if(localAlignIdList.length > 0) { - selectedLocalAlign = localAlignIdList[0]; - } - } - } - - public static int getNewAlignId() { - - boolean found = false; - alignId++; - while(!found) { - - boolean sw = false; - for(int i=0;i< forUniqueness.length; i++) - if(forUniqueness[i].equals((new Integer(alignId)).toString())) { - alignId++; - sw = true; - break; - } - - if( !sw ) found = true; - - } - - return alignId; - } - - public static void resetAlignList(String alignId) { - - alignIdList = new String[1]; - alignIdList[0] = alignId; - selectedAlign = alignIdList[0]; - if(alignBox.getItemCount() > 0) alignBox.removeAllItems(); - alignBox.addItem(selectedAlign); - - } - - public static void resetActionButtons( boolean flag ) { - - alignImportButton.setEnabled( flag ); - alignStoreButton.setEnabled( flag ); - serverAlignTrimButton.setEnabled( flag ); - //mapButton.setEnabled( flag ); - //alignFindButton.setEnabled( flag ); - //allAlignButton.setEnabled( flag ); - - } - - public static void set3Buttons( ) { - mapButton.setEnabled( true ); - alignFindButton.setEnabled( true ); - allAlignButton.setEnabled( true ); - } - - public static void setFetchButton( boolean flag) { - fetchButton.setEnabled( flag ); - //alignFindButton.setEnabled( flag ); - //allAlignButton.setEnabled( flag ); - alignImportButton.setEnabled( !flag ); - alignStoreButton.setEnabled( !flag ); - serverAlignTrimButton.setEnabled( !flag ); - } - - - - public void initialize() { - - //selectedHost = "aserv.inrialpes.fr"; - //selectedPort = "8089"; - - IWorkspaceRoot root = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot(); - IPath location = root.getLocation(); - String path = location.toOSString(); - - htmlView = new JEditorPane(); - htmlView.setEditable(false); - htmlView.setContentType("text/html"); - htmlView.setBackground( this.getBackground() ); - htmlView.setBounds( 0, 0, 500, 500 ); - - //ontoFolder = new File(path + location.SEPARATOR + "onto"); - ontoFolder = new File(path + location.SEPARATOR + "align"); - - if (!ontoFolder.exists()) ontoFolder.mkdir(); - basicFolder = new File(path + location.SEPARATOR ); - alignFolder = new File(path + location.SEPARATOR + "align"); - if (!alignFolder.exists()) alignFolder.mkdir(); - - //System.out.println("alignFolder=" + alignFolder.getAbsolutePath()); - - offlineButton = new JButton("Offline",null); - offlineButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == offlineButton) { - offlineInit(false); - } - }; - }); - - onlineButton = new JButton("Online",null); - onlineButton.addActionListener(new ActionListener(){ - @SuppressWarnings("deprecation") - public void actionPerformed(ActionEvent e) { - if (e.getSource() == onlineButton) { - online = true; - - JOptionPane pane = new JOptionPane(); - connDialog = pane.createDialog(null, "Input for connection"); - connDialog.setSize(new Dimension(300,120)); - - Container cont = connDialog.getContentPane(); - Component[] comps = cont.getComponents(); - for(int i=0;i< comps.length ;i++) { cont.remove(comps[i]);} - - cont.add(connButton); - cont.add(cancelButton); - - JPanel jPane = new JPanel (new GridLayout (3, 2, 20, 10)); - - jPane.add(hostName); jPane.add(hostField); - jPane.add(portName); jPane.add(portField); - jPane.add(connButton); - jPane.add(cancelButton); - - connDialog.setContentPane(jPane); - connDialog.setVisible(true); - ontoBox1.removeAllItems(); - ontoBox2.removeAllItems(); - } - - }; - }); - - selectedHost = defaultHost; - hostName = new JLabel( "Host name" ); - hostField = new JTextField( defaultHost, 15 ); - hostField.setEnabled(true); - hostField.setEditable( true ); - - selectedPort = defaultPort; - portName = new JLabel( "Port" ); - portField = new JTextField( defaultPort, 4 ); - portField.setEnabled(true); - portField.setEditable( true ); - - serverName = new JLabel( "wserver" ); - serverField = new JTextField( wserver , 50 ); - serverField.setEnabled(true); - serverField.setEditable( true ); - - methodName = new JLabel( "wsmethod" ); - methodField = new JTextField( "", 50 ); - methodField.setEnabled(true); - methodField.setEditable( true ); - - connButton = new JButton("Connect",null); - connButton.setEnabled(true); - - connButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == connButton) { - - // for connecting to server - - selectedHost = hostField.getText(); - selectedPort = portField.getText(); - //parentComponent = getParent(); - onAlign = new OnlineAlign(selectedPort, selectedHost ); - - String list[] = onAlign.getMethods(); - if(list == null || list.length ==0) { - JOptionPane.showMessageDialog(null, "Impossible connection!","Warning",2); - return; - } - - methodList = new String[list.length]; - strategy.removeAllItems(); - - for(int i=0; i< list.length; i++){ - - methodList[i]= list[i]; - strategy.addItem(list[i]); - } - - - ontoBox1.setEnabled(true); - ontoBox2.setEnabled(true); - strategy.setEnabled(true); - ontoRefresh.setEnabled(true); - mapButton.setEnabled(true); - - alignBox.setEnabled(true); - localAlignBox.setEnabled(true); - - alignImportButton.setEnabled(false); - alignStoreButton.setEnabled(false); - serverAlignTrimButton.setEnabled(false); - //fetchButton.setEnabled(true); - - localAlignImportButton.setEnabled(true); - alignUploadButton.setEnabled(true); - alignFindButton.setEnabled(true); - allAlignButton.setEnabled(true); - - offlineButton.setEnabled(true); - onlineButton.setEnabled(false); - - localAlignTrimButton.setEnabled(true); - - ontoRefresh.setEnabled(true); - - mapButton.setEnabled(true); - strategy.setEnabled(true); - - online = true; - - connDialog.dispose(); - - } - - }; - }); - - - cancelButton = new JButton("Cancel",null); - cancelButton.setEnabled(true); - cancelButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == cancelButton) { - //System.out.println("Cancel"); - connDialog.dispose(); - - } - }; - }); - - discardButton = new JButton("Discard",null); - discardButton.setEnabled(true); - discardButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == discardButton) { - //System.out.println("Cancel"); - matchDialog.dispose(); - - } - }; - }); - - alignLabel = new JLabel("Server alignments"); - alignBox = new JComboBox(alignIdList); - alignBox.setEnabled(false); - alignBox = new JComboBox(alignIdList); - alignBox.setEnabled(false); - - alignBox.setMaximumRowCount(20); - alignBox.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent event) - { - int id = 0; - if (event.getStateChange()==ItemEvent.SELECTED) - id = alignBox.getSelectedIndex(); - - selectedAlign = alignIdList[id]; - - //System.out.println("Align selected =" + selectedAlign); - } - }); - - localAlignLabel = new JLabel("Local alignments "); - localAlignBox = new JComboBox(localAlignIdList); - localAlignBox.setEnabled(false); - localAlignBox = new JComboBox(localAlignIdList); - localAlignBox.setEnabled(false); - - localAlignBox.setMaximumRowCount(20); - localAlignBox.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent event) - { - int id = 0; - if (event.getStateChange()==ItemEvent.SELECTED) - id = localAlignBox.getSelectedIndex(); - - selectedLocalAlign = localAlignIdList[id]; - } - }); - - localAlignImportButton = new JButton("Import",null); - localAlignImportButton.setEnabled(false); - localAlignImportButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == localAlignImportButton) { - if(selectedLocalAlign == null) { - JOptionPane.showMessageDialog(null, "Choose an alignment ID from list!","Warning",2); - return; - } - - File fn = new File(selectedLocalAlign + ".owl"); - //if (fn.exists()) fn.delete(); - //System.out.println("Filename off to export :"+ fn.getAbsolutePath()); - - StringWriter htmlMessage = new StringWriter(); - AlignmentVisitor htmlV = new HTMLRendererVisitor( new PrintWriter ( htmlMessage ) ); - - try { - SWTInterface.alignmentTable.get(selectedLocalAlign).render( htmlV ); - - htmlView.setText( htmlMessage.toString() ); - - htmlView.setLocation( new Point( 0, 0 ) ); - - htmlView.setVisible(true); - - String inputName=null; - - inputName = JOptionPane.showInputDialog(null, "Enter a project name", "AlignmentProject"); - - if (inputName==null || inputName.equals("")) return; - - String[] projects = DatamodelPlugin.getDefault().getOntologyProjects(); - if(projects!=null) { - boolean found = false; - - for(int i=0; i < projects.length; i++) { - - if(projects[i].equals(inputName)) { - found = true;break; - } - } - - if(!found) { - Properties proper = new Properties(); - proper.put(IConfig.ONTOLOGY_LANGUAGE.toString(), IConfig.OntologyLanguage.OWL.toString()); - new CreateProject( inputName, DatamodelTypes.RAM, proper ).run(); - - } - - ImportExportControl ieControl = new ImportExportControl(); - URI uris[] = new URI[1]; - uris[0] = new File(fn.getAbsolutePath()).toURI(); - ieControl.importFileSystem(inputName, uris, null); - //ieControl.addOntologies2Project(importedModules, inputName); - } - } - catch ( Exception ex ) { ex.printStackTrace();}; - - }//choose an align - - - } - }); - - alignUploadButton = new JButton("Upload",null); - alignUploadButton.setEnabled(false); - alignUploadButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == alignUploadButton) { - if(selectedLocalAlign == null) - JOptionPane.showMessageDialog(null, "Choose an alignment ID from list!","Warning",2); - else { - - //File fn = new File( selectedLocalAlign + ".rdf" ); - //System.out.println("file name off to export :"+ fn.getName()); - - try { - String uploaded = onAlign.uploadAlign(selectedLocalAlign + ".rdf"); - - localAlignIdList = new String[1]; - localAlignIdList[0] = selectedLocalAlign; - localAlignBox.removeAllItems(); - localAlignBox.addItem(selectedLocalAlign); - - JOptionPane.showMessageDialog(null, "Uploaded alignment : "+ uploaded,"Warning",2); - - } catch ( Exception ex ) { ex.printStackTrace();} - } - } - } - }); - - fetchButton = new JButton("Fetch",null); - fetchButton.setEnabled(false); - fetchButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - - resetActionButtons( false ); - - if (e.getSource() == fetchButton) { - - if(selectedAlign == null) { - JOptionPane.showMessageDialog(null, "Choose an alignment ID from list!","Warning",2); - return; - } - /* - alignIdList = new String[1]; - alignIdList[0] = selectedAlign; - alignBox.removeAllItems(); - alignBox.addItem(selectedAlign); - onAlign.getRDFAlignment( selectedAlign ); - */ - - JOptionPane.showMessageDialog(null, "This operation may take a while.","Warning",2); - alignIdList = new String[1]; - alignIdList[0] = selectedAlign; - alignBox.removeAllItems(); - alignBox.addItem(selectedAlign); - onAlign.getRDFAlignmentMonoThread( selectedAlign ); - setFetchButton( false ); - - } - }; - }); - - alignImportButton = new JButton("Import",null); - alignImportButton.setEnabled(false); - alignImportButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == alignImportButton) { - - if(selectedAlign == null) { - JOptionPane.showMessageDialog(null, "Choose an alignment ID from list!","Warning",2); - return; - } - //the name originated from the server is a URL so slashes are used - //String [] sali = selectedAlign.split("/"); - //String uniqueId = sali[sali.length-2].concat(sali[sali.length-1]); - - String inputName = null; - - FileWriter out = null; - - //export to local List - - String rdfalignStr = onAlign.getRDFAlignmentParsed( );// selectedAlign , alignImportButton, alignStoreButton, - //serverAlignTrimButton, allAlignButton, alignFindButton, mapButton ); - - String alignKey = alignFolder.getAbsolutePath() + File.separator + getNewAlignId(); - - alignIdList = new String[1]; - alignIdList[0] = selectedAlign; - alignBox.removeAllItems(); - alignBox.addItem( alignIdList[0] ); - - String rdfPath = alignKey + ".rdf"; - - URIAlignment align = null; - String owlalignStr = null; - - try { - - File rdfFile = new File( rdfPath ); - - out = new FileWriter( rdfFile ); - out.write( rdfalignStr ); - out.flush(); - out.close(); - - File file = new File(rdfPath); - - AlignmentParser ap = new AlignmentParser(0); - ap.setEmbedded( true ); - align = (URIAlignment)ap.parse(file.toURI().toString()); - - SWTInterface.alignmentTable.put( alignKey , (Alignment)align ); - - String[] list = offAlign.getAllAlign( ); - - if(list != null) { - localAlignIdList = new String[1]; - localAlignBox.removeAllItems(); - - for(int i=0; i< list.length; i++){ - if(list[i].equals(alignKey)) { - localAlignIdList[0]= list[i]; - localAlignBox.addItem(list[i]); - break; - } - } - - if(localAlignIdList.length > 0) { - selectedLocalAlign = localAlignIdList[0]; - } - } - - StringWriter htmlMessage = new StringWriter(); - AlignmentVisitor htmlV = new HTMLRendererVisitor( new PrintWriter ( htmlMessage ) ); - - align.render( htmlV ); - - if(htmlMessage.toString()==null || htmlMessage.toString().equals("")) { - htmlView.setText( "" ); - } else { - - //String htmlText = htmlMessage.toString(); - //if(htmlText.length() > 1000000) - // JOptionPane.showMessageDialog(null, "Too big alignment!","Warning",2); - //htmlView.getEditorKit().createDefaultDocument(); - htmlView.setText( htmlMessage.toString() ); - } - - htmlView.setLocation( new Point( 0, 0 ) ); - - htmlView.setVisible(true); - //get align from server, then export it as owl onto - StringWriter owlMessage = new StringWriter(); - AlignmentVisitor owlV = new OWLAxiomsRendererVisitor( new PrintWriter ( owlMessage ) ); - ObjectAlignment al = ObjectAlignment.toObjectAlignment( (URIAlignment)align ); - //BasicAlignment al = (BasicAlignment)align; - al.render( owlV ); - - owlalignStr = owlMessage.toString(); - - } - catch ( Exception ex ) { ex.printStackTrace();}; - - - if(owlalignStr==null) { - JOptionPane.showMessageDialog(null, "OWL alignment cannot be exported.","Warning",2); - return; - } - - try { - - inputName = JOptionPane.showInputDialog(null, "Enter a project name", "AlignmentProject"); - - if (inputName==null || inputName.equals("")) return; - - String[] projects = DatamodelPlugin.getDefault().getOntologyProjects(); - if(projects!=null) { - boolean found = false; - - for(int i=0; i < projects.length; i++) { - - if(projects[i].equals(inputName)) { - found = true;break; - } - } - - if(!found) { - - Properties proper = new Properties(); - proper.put(IConfig.ONTOLOGY_LANGUAGE.toString(), IConfig.OntologyLanguage.OWL.toString()); - new CreateProject( inputName, DatamodelTypes.RAM, proper ).run(); - } - } - - String owlPath = ontoFolder.getAbsolutePath() + File.separator + getNewAlignId() + ".owl"; - File owlFile = new File( owlPath ); - if (owlFile.exists()) owlFile.delete(); - - out = new FileWriter( owlFile ); - out.write( owlalignStr ); - out.flush(); - out.close(); - - try { - ImportExportControl ieControl = new ImportExportControl(); - URI uris[] = new URI[1]; - uris[0] = new File( owlPath).toURI(); - String[] importedModules = ieControl.importFileSystem(inputName, uris, null); - - //ieControl.addOntologies2Project(importedModules, inputName); - } catch ( ControlException ex ) { } - - } - catch ( Exception ex ) { ex.printStackTrace();} - - } - }; - }); - - allAlignButton = new JButton("Fetch available alignments", null); - allAlignButton.setEnabled(false); - allAlignButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == allAlignButton) { - - // for connecting to server - //onAlign = new OnlineAlign(selectedPort, selectedHost); - String[] list = null; - if(online) { - list = onAlign.getAllAlign(); - if(list == null || list.length==0) { - JOptionPane.showMessageDialog(null, "Impossible connection!","Warning",2); - return; - } - - //String[] list = getResultsFromAnswer( aa , "alid", null ); - - alignIdList = new String[list.length]; - alignBox.removeAllItems(); - - for(int i=0; i< list.length; i++){ - alignIdList[i]= list[i]; - alignBox.addItem(list[i]); - } - - if(alignIdList.length > 0) { - selectedAlign = alignIdList[0]; - } - - String[] list1 = offAlign.getAllAlign( ); - if(list1!=null) { - localAlignIdList = new String[list1.length]; - localAlignBox.removeAllItems(); - - for(int i=0; i< list1.length; i++){ - localAlignIdList[i]= list1[i]; - localAlignBox.addItem(list1[i]); - } - - if(localAlignIdList.length > 0) { - selectedLocalAlign = localAlignIdList[0]; - } - } - - fetchButton.setEnabled(true); - alignImportButton.setEnabled(false); - alignStoreButton.setEnabled(false); - serverAlignTrimButton.setEnabled(false); - - } - else { //offline - list = offAlign.getAllAlign( ); - if(list!=null) { - localAlignIdList = new String[list.length]; - localAlignBox.removeAllItems(); - - for(int i=0; i< list.length; i++){ - localAlignIdList[i]= list[i]; - localAlignBox.addItem(list[i]); - } - - if(localAlignIdList.length > 0) { - selectedLocalAlign = localAlignIdList[0]; - } - } - } - } - }; - }); - - alignFindButton = new JButton("Find an alignment for ontologies", null); - alignFindButton.setEnabled(false); - alignFindButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == alignFindButton) { - - // for connecting to server - //onAlign = new OnlineAlign(selectedPort, selectedHost); - if(selectedOnto1 == null || selectedOnto2 == null ) - JOptionPane.showMessageDialog(null, "Choose two ontologies from lists!","Warning",2); - else { - - String[] list = onAlign.findAlignForOntos(selectedOnto1, selectedOnto2); - if(list == null || list.length==0) - JOptionPane.showMessageDialog(null, "No alignment is found!","Warning",2); - else { - //String[] list = getResultsFromAnswer(ao, "alid", null ); - - alignIdList = new String[list.length]; - alignBox.removeAllItems(); - - for(int i=0; i< list.length; i++){ - alignIdList[i]= list[i]; - alignBox.addItem(list[i]); - } - - if(alignIdList.length > 0) { - selectedAlign = alignIdList[0]; - } - - } - } - fetchButton.setEnabled(true); - alignImportButton.setEnabled(false); - alignStoreButton.setEnabled(false); - serverAlignTrimButton.setEnabled(false); - } - - }; - }); - - serverAlignTrimButton = new JButton("Trim", null); - serverAlignTrimButton.setEnabled(false); - serverAlignTrimButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == serverAlignTrimButton) { - - if(selectedAlign == null ) - JOptionPane.showMessageDialog(null, "Choose an alignment ID from list!","Warning",2); - else { - String thres = null; - - thres = JOptionPane.showInputDialog(null, "Enter a threshold ", "0.5"); - - if (thres==null || thres.equals("")) return; - - String at = onAlign.trimAlign(selectedAlign, thres); - - if(at == null || at.equals("")) - JOptionPane.showMessageDialog(null, "No alignment is obtained!","Warning",2); - else { - - alignIdList = new String[1]; - alignBox.removeAllItems(); - alignIdList[0]= at; - alignBox.addItem(at); - selectedAlign = alignIdList[0]; - setFetchButton( true ); - - } - } - } - }; - }); - - localAlignTrimButton = new JButton("Trim", null); - localAlignTrimButton.setEnabled(false); - localAlignTrimButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == localAlignTrimButton) { - - if(selectedLocalAlign == null ) - JOptionPane.showMessageDialog(null, "Choose an alignment ID from list!","Warning",2); - else { - String thres = JOptionPane.showInputDialog(null, "Enter a threshold ", "0.5"); - - if (thres==null || thres.equals("")) return; - - String resId = offAlign.trimAndExportAlign( new Double(thres), selectedLocalAlign ); - - localAlignBox.removeAllItems(); - localAlignIdList = new String[1]; - - localAlignIdList[0] = resId; - - localAlignBox.addItem( resId ); - - selectedLocalAlign = localAlignIdList[0]; - } - - } - }; - }); - - //store an alignment on server or locally - alignStoreButton = new JButton("Store", null); - alignStoreButton.setEnabled(false); - alignStoreButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == alignStoreButton) { - - //for connecting to server - //onAlign = new OnlineAlign(selectedPort, selectedHost); - if(selectedAlign == null ) - JOptionPane.showMessageDialog(null, "Choose an alignment ID from list!","Warning",2); - else { - - String sto = onAlign.storeAlign(selectedAlign); - - if(sto == null || sto.equals("") ) - JOptionPane.showMessageDialog(null, "Impossible connection!","Warning",2); - else { - alignIdList = new String[1]; - alignBox.removeAllItems(); - - alignIdList[0]= sto; - alignBox.addItem(sto); - - selectedAlign = alignIdList[0]; - JOptionPane.showMessageDialog(null, "Stored alignment : "+ sto ,"Warning",2); - } - - - } - } - - }; - }); - - ontoRefresh = new JButton("Refresh",null); - ontoRefresh.setEnabled(false); - ontoRefresh.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == ontoRefresh) { - onto_proj = refreshOntoList(online); - } - }; - }); - - goButton = new JButton("Accept",null); - goButton.setEnabled( true ); - goButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == goButton) { - wserver = serverField.getText(); - if(wserver.equals("")) - wserver = null; - wsmethod = methodField.getText(); - if(wsmethod.equals("")) - wsmethod = null; - matchDialog.dispose(); - - resetActionButtons( false ); - - //onAlign.getAlignId( matchMethod, wserver, wsmethod, selectedOnto1, selectedOnto2 ); - - String alignId = onAlign.getAlignIdMonoThread( matchMethod, wserver, wsmethod, selectedOnto1, selectedOnto2 ); - //System.out.println("match from sji finished "); - alignIdList = new String[1]; - alignIdList[0] = alignId; - selectedAlign = alignIdList[0]; - alignBox.removeAllItems(); - alignBox.addItem(selectedAlign); - setFetchButton( true ); - - } // getsource - }; - }); - - - mapButton = new JButton("Match",null); - mapButton.setEnabled(false); - mapButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - if (e.getSource() == mapButton) { - if (selectedOnto1 == null || selectedOnto2 == null ) { - JOptionPane.showMessageDialog(null, "Choose two ontologies from lists ","Warning",2); - return; - } - - - if(online) { - if (!selectedOnto1.startsWith("http://") || !selectedOnto2.startsWith("http://") ) { - JOptionPane.showMessageDialog(null, "URLs for ontologies are required. ","Warning",2); - return; - } - if( matchMethod.equals("fr.inrialpes.exmo.align.service.WSAlignment")) { - JOptionPane pa = new JOptionPane(); - matchDialog = pa.createDialog(null, "Parameters for matching"); - matchDialog.setSize(new Dimension(400,120)); - - Container cont = matchDialog.getContentPane(); - Component[] comps = cont.getComponents(); - for(int i=0;i< comps.length ;i++) { cont.remove(comps[i]);} - cont.add(goButton); - cont.add(discardButton); - - JPanel jPane = new JPanel (new GridLayout (3, 2, 20, 10)); - - jPane.add(serverName); jPane.add(serverField); - jPane.add(methodName); jPane.add(methodField); - jPane.add(goButton); - jPane.add(discardButton); - - matchDialog.setContentPane(jPane); - matchDialog.setVisible(true); - } else { - resetActionButtons( false ); - String alignId = onAlign.getAlignIdMonoThread( matchMethod, wserver, wsmethod, selectedOnto1, selectedOnto2 ); - //onAlign.getAlignId( matchMethod, wserver, wsmethod, selectedOnto1, selectedOnto2 ); - alignIdList = new String[1]; - alignIdList[0] = alignId; - selectedAlign = alignIdList[0]; - alignBox.removeAllItems(); - alignBox.addItem(selectedAlign); - setFetchButton( true ); - } - - //String answer = onAlign.getAlignId( matchMethod, selectedOnto1, selectedOnto2 ); - //if(answer==null || answer.equals("")) { - // JOptionPane.showMessageDialog(null, "Alignment is not produced.","Warning",2); - // return; - //} - //alignIdList = new String[1]; - //alignIdList[0] = answer; - //selectedAlign = alignIdList[0]; - //alignBox.removeAllItems(); - //alignBox.addItem(selectedAlign); - //onAlign.getRDFAlignment( selectedAlign, alignImportButton, alignStoreButton, - // serverAlignTrimButton, allAlignButton, alignFindButton, mapButton); - - } - else { //offline - - String resId = offAlign.matchAndExportAlign( matchMethod, onto_proj.get(selectedOnto1), selectedOnto1, onto_proj.get(selectedOnto2), selectedOnto2); - - localAlignBox.removeAllItems(); - localAlignIdList = new String[1]; - - //File f1 = new File(resId); - localAlignIdList[0] = resId;//"file:" + f1.getAbsolutePath(); - - localAlignBox.addItem(localAlignIdList[0]); - - selectedLocalAlign = localAlignIdList[0]; - - //System.out.println("offline matching done. "); - } //else for ""offline" - } // getsource - - }; - }); - - //retrieve all available onto. in Ontology Navigator - - ontoLabel1 = new JLabel("Ontology 1 "); - - ontoBox1 = new JComboBox(ontoList); - ontoBox1.setEditable( true ); - ontoBox1.setEnabled(false); - ontoBox1.setMaximumRowCount(20); - ontoBox1.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent event) { - if (event.getStateChange()==ItemEvent.SELECTED) - selectedOnto1 = (String)ontoBox1.getSelectedItem(); - - } - }); - - ontoLabel2 = new JLabel("Ontology 2 "); - ontoBox2 = new JComboBox(ontoList); - ontoBox2.setEditable( true ); - ontoBox2.setEnabled(false); - ontoBox2.setMaximumRowCount(20); - ontoBox2.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent event) - { - if (event.getStateChange()==ItemEvent.SELECTED) - //id = ontoBox2.getSelectedIndex(); - selectedOnto2 = (String)ontoBox2.getSelectedItem(); - } - }); - - strat= new JLabel("Methods "); - strategy = new JComboBox(methodList); - strategy.setEnabled(false); - strategy.setMaximumRowCount(20); - strategy.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent event) - { - if (event.getStateChange()==ItemEvent.SELECTED) - ind = strategy.getSelectedIndex(); - matchMethod = methodList[ind]; - } - }); - - this.setLayout (new BorderLayout()); - this.add (new JLabel ("Computing and managing ontology alignments"), BorderLayout.NORTH); - - phrases = createPhraseList( ); - phrases.setBorder(BorderFactory.createEmptyBorder (10, 5, 10, 5) ); - - JScrollPane top = new JScrollPane( phrases ); - top.setMaximumSize(top.getPreferredSize()); - _mainSplitter.setTopComponent( top ); - - JScrollPane html = new JScrollPane( htmlView ); - html.setMaximumSize(html.getPreferredSize()); - _mainSplitter.setBottomComponent( html ); - - _mainSplitter.setDividerLocation((int)top.getPreferredSize().getHeight()); - - this.add(_mainSplitter,BorderLayout.CENTER); //Main Window of the Plugin - - //offline is default mode - offlineInit( true ); - - } - -private JPanel createPhraseList ( ) { - JPanel phrasePane = new JPanel (new GridLayout (0, 1, 0, 10)); - - - JPanel minusLabel = new JPanel (new FlowLayout(10)); - JPanel zeroLabel = new JPanel (new FlowLayout(10)); - JPanel oneLabel = new JPanel (new FlowLayout(10)); - JPanel twoLabel = new JPanel (new FlowLayout(10)); - JPanel threeLabel = new JPanel (new FlowLayout(10)); - JPanel fourLabel = new JPanel (new FlowLayout(10)); - JPanel four2Label = new JPanel (new FlowLayout(10)); - JPanel fiveLabel = new JPanel (new FlowLayout(10)); - JPanel sixLabel = new JPanel (new FlowLayout(10)); - JPanel eightLabel = new JPanel (new FlowLayout(10)); - JPanel nineLabel = new JPanel (new FlowLayout(10)); - - minusLabel.add(onlineButton); - minusLabel.add(offlineButton); - - oneLabel.add(ontoLabel1); - oneLabel.add(ontoBox1); - - - twoLabel.add(ontoLabel2); - twoLabel.add(ontoBox2); - - twoLabel.add(ontoRefresh); - - threeLabel.add(strat); - threeLabel.add(strategy); - - threeLabel.add(mapButton); - - fourLabel.add(alignLabel); - fourLabel.add(alignBox); - //fourLabel.add(fetchButton); - fourLabel.add(alignImportButton); - fourLabel.add(serverAlignTrimButton); - fourLabel.add(alignStoreButton); - fourLabel.add(fetchButton); - - four2Label.add(localAlignLabel); - four2Label.add(localAlignBox); - four2Label.add(localAlignImportButton); - four2Label.add(localAlignTrimButton); - four2Label.add(alignUploadButton); - - fiveLabel.add(alignFindButton); - nineLabel.add(allAlignButton); - //label_three.add(resButton); - phrasePane.add(minusLabel); - //phrasePane.add(zeroLabel); - - phrasePane.add(oneLabel); - phrasePane.add(twoLabel); - phrasePane.add(threeLabel); - phrasePane.add(fourLabel); - phrasePane.add(four2Label); - phrasePane.add(nineLabel); - phrasePane.add(fiveLabel); - - return phrasePane; - - } - -//This function fetches all URL ontologies -private HashMap<String,String> refreshOntoList(boolean online) { - HashMap<String,String> vec = new HashMap<String,String>(); - OWLAPIOntologyFactory fact = new OWLAPIOntologyFactory(); - try { - String[] projects = DatamodelPlugin.getDefault().getOntologyProjects(); - if(projects != null) { - for(int i=0; i < projects.length; i++) { - if(projects[i]!=null) { - //URI[] uris= DatamodelPlugin.getDefault().getProjectOntologyFiles(projects[i]); - //Kaon2Connection connection = DatamodelPlugin.getDefault().getKaon2Connection(projects[i]); - //version 15 May - OntologyManager connection = DatamodelPlugin.getDefault().getKaon2Connection(projects[i]); - Set<String> strSet = connection.getAvailableOntologyURIs(); - String[] uris = (String[])strSet.toArray(new String[0]); - if(online) { - for(int k=0; k < uris.length; k++) { - //get only http URL - if(uris[k].startsWith("http://")) - try { - fact.loadOntology(new URI(uris[k])); - vec.put(uris[k],projects[i]); - } catch (Exception ex) { - } - } - } else { - for(int k=0; k < uris.length; k++) { - vec.put(DatamodelPlugin.getDefault().getPhysicalOntologyUri(projects[i], uris[k]).toString(),projects[i]); - } - } - } - } - } - else { - //System.out.printf("No Ontology Project !" ); - return null; - } - } catch ( Exception ex ) { ex.printStackTrace();}; - - ontoBox1.removeAllItems(); - ontoBox2.removeAllItems(); - - String[] keys = (String[]) vec.keySet().toArray(new String[0]); - - ontoList = new String[ keys.length ]; - - for(int j=0; j < keys.length; j++) { - - ontoBox1.addItem(keys[j]); - ontoBox2.addItem(keys[j]); - ontoList[j] = keys[j]; - - if(ontoList.length > 0) { - selectedOnto1 = ontoList[0]; - selectedOnto2 = ontoList[0]; - } - - } - return vec; -} - - public void run() { - - initialize(); - } - - - public static String[] getResultsFromAnswer( String answer, String type , String separator) { - Document doc=null; - String[] names=null; - //File message=null; - //System.out.println( "displaying XML ..." ); - answer = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + answer; - //System.out.println( answer ); - try { - File messageFile = new File(basicFolder.getAbsolutePath() + basicFolder.separator + "messageFile"); - FileWriter out = new FileWriter(messageFile); - out.write( answer ); - out.close(); - - } catch (Exception e) { - //compilerError(Compiler.XML, e.getMessage()); - } - - try { - //System.out.println( "Parsing for getting result: "+ type +" ... "); - doc = parse(new File(basicFolder.getAbsolutePath() + basicFolder.separator + "messageFile")); - - Element e = doc.getDocumentElement(); - - NodeList methods = e.getElementsByTagName(type); - names = new String[methods.getLength()]; - //System.out.println( "length="+ methods.getLength()); - - - for (int i=0; i< methods.getLength(); i++) { - Node method = (Node) methods.item(i); - //String nm = method.getAttribute("NAME"); - Node firstnode = method.getFirstChild(); - String nm = firstnode.getNodeValue(); - //System.out.println( "nm="+nm ); - if(nm!=null) { - if(separator!=null) - names[i]=nm.substring(nm.lastIndexOf(separator)+1,nm.length()); - else - names[i]=nm; - //System.out.println( "name="+names[i] ); - } - } - - - - } catch (Exception e) { - //compilerError(Compiler.XML, e.getMessage()); - //System.out.println("getValue="+e.getMessage()); - } - return names; - //System.out.println( answer ); - } - - public static Vector<String[]> getCorresFromAnswer( Alignment align ) { - - ArrayList<Cell> cells = ((BasicAlignment)align).getArrayElements(); - Vector<String[]> names = new Vector<String[]>(cells.size() + 1 ); - - String[] corr = new String[4]; - corr[0] = "Object1"; - - corr[1] = "Relation"; - corr[2] = "Strength"; - corr[3] = "Object2"; - - names.add(corr); - - for(int i=0; i<cells.size(); i++) { - try { - - corr = new String[4]; - - corr[0] = ((BasicCell)cells.get(i)).getObject1().toString(); - //by default : equivalence - - //corr[1] = cells.get(i).getRelation().toString(); - corr[1] = "="; - corr[2] = (new Double(cells.get(i).getStrength())).toString(); - corr[3] = ((BasicCell)cells.get(i)).getObject2().toString(); - names.add(corr); - - }catch (Exception ex) { ex.printStackTrace(); } - - } - return names; - - } - - public static Vector<String[]> getCorresFromAnswer( String answer, String type ,String separator) { - Document doc=null; - Vector<String[]> names = new Vector<String[]>(); - //File message=null; - //System.out.println( "displaying XML ..." ); - answer = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + answer; - //System.out.println( answer ); - try { - File messageFile = new File(basicFolder.getAbsolutePath() + File.separator + "messageFile"); - FileWriter out = new FileWriter(messageFile); - out.write( answer ); - out.close(); - - } catch (Exception e) { - //compilerError(Compiler.XML, e.getMessage()); - } - - try { - //System.out.println( "parsing ... "); - doc = parse(new File(basicFolder.getAbsolutePath() + File.separator + "messageFile")); - Element e = doc.getDocumentElement(); - NodeList m = e.getElementsByTagName("table"); - Element cor = (Element)m.item(1); - NodeList methods = cor.getElementsByTagName(type); - - //System.out.println( "length lines ="+ methods.getLength()); - - - for (int i=0; i< methods.getLength(); i++) { - Element lns = (Element) methods.item(i); - //String nm = method.getAttribute("NAME"); - NodeList cols = lns.getElementsByTagName("td"); - - //System.out.println( "length cols=" + cols.getLength()); - - String[] tt = (String[]) new String[cols.getLength()]; - - for (int j=0; j< cols.getLength(); j++) { - Node col = (Node) cols.item(j); - //String nm = method.getAttribute("NAME"); - - Node firstnode = col.getFirstChild(); - String nm=null; - - if(firstnode!=null) { - nm = firstnode.getNodeValue(); - - if(nm!=null) { - - if(separator!=null) - if (nm.lastIndexOf(separator) > 0 && nm.lastIndexOf(separator) < nm.length()-1) - tt[j] = nm.substring(nm.lastIndexOf(separator)+1,nm.length()); - else tt[j] = nm; - else - tt[j] = nm; - //System.out.println( "name="+tt[j] ); - } - } - - } - names.add(tt); - } - - } catch (Exception e) { - //compilerError(Compiler.XML, e.getMessage()); - //System.out.println("Error="+e.getMessage() + "xml parser prob."); - } - - - return names; - - } - - private static Document parse(File f) throws Exception { - try { - String uri = f.toURL().toString(); - return parse(uri); - } catch (MalformedURLException ex) { - //compilerError(Compiler.FILE, ex.getMessage()); - } - return null; - } - - private static Document parse(String uri) throws Exception { - org.w3c.dom.Document doc = null; - try { - javax.xml.parsers.DocumentBuilderFactory dbf = - javax.xml.parsers.DocumentBuilderFactory.newInstance(); - dbf.setValidating(false); - javax.xml.parsers.DocumentBuilder builder = dbf.newDocumentBuilder(); - doc = builder.parse(uri); - } catch (Exception e) { - //compilerError(Compiler.XML, e.getMessage()); - } - return doc; - } - -} - - diff --git a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/View.java b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/View.java deleted file mode 100755 index aa3aca238f796efde38cf66224975ceb289369de..0000000000000000000000000000000000000000 --- a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/View.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) INRIA, 2007-2008 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -package fr.inrialpes.exmo.align.plugin.neontk; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.part.ViewPart; -import org.eclipse.swt.awt.SWT_AWT; -import java.awt.BorderLayout; -import javax.swing.JPanel; -import java.awt.Frame; - -public class View extends ViewPart { - - public static final String ID = "fr.inrialpes.exmo.align.plugin.neontk.view"; - - public void setFocus() { - } - - public void createPartControl(Composite parent) { - final Composite composite = new Composite(parent, SWT.EMBEDDED); - final Frame f = SWT_AWT.new_Frame(composite); - - JPanel panel = new JPanel(new BorderLayout()); - f.add(panel); - SWTInterface lo= new SWTInterface(); - lo.run(); - f.add(lo); - } - -} diff --git a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/WSDialog.java b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/WSDialog.java index c6505a89ff81085063ac95e357cb533d7dfbaecb..708bfa1f60d502041951fedd75afc4eb0446ce45 100644 --- a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/WSDialog.java +++ b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/WSDialog.java @@ -104,7 +104,9 @@ public class WSDialog extends Dialog { GridData data = new GridData(); data.horizontalSpan = 6; label.setLayoutData(data); - + + Label serverLabel = new Label(shell, SWT.NONE); + serverLabel.setText("Server: "); // Display the input box for server final Text server = new Text(shell, SWT.BORDER); server.setText("http://kameleon.ijs.si/ontolight/ontolight.asmx"); @@ -112,6 +114,8 @@ public class WSDialog extends Dialog { data.horizontalSpan = 6; server.setLayoutData(data); + Label methodLabel = new Label(shell, SWT.NONE); + methodLabel.setText("Method: "); // Display the input box for method final Text wsmethod = new Text(shell, SWT.BORDER); //text.setText("");