Changeset 75 in default for v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.standalone/src/de
- Timestamp:
- 06/18/14 16:58:39 (10 years ago)
- Location:
- v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.standalone/src/de/ugoe/cs/swe/bnftools/ebnf/standalone
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.standalone/src/de/ugoe/cs/swe/bnftools/ebnf/standalone/EBNFEditedResourceProvider.java
r74 r75 17 17 @Override 18 18 public XtextResource createResource() { 19 return (XtextResource) rsp.get().createResource(URI.createURI("test. ebnf"));19 return (XtextResource) rsp.get().createResource(URI.createURI("test.bnf")); 20 20 } 21 21 -
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.standalone/src/de/ugoe/cs/swe/bnftools/ebnf/standalone/View.java
r74 r75 1 1 package de.ugoe.cs.swe.bnftools.ebnf.standalone; 2 2 3 import java.io.File; 4 import java.io.IOException; 5 6 import org.apache.commons.io.FileUtils; 7 import org.eclipse.emf.common.util.URI; 3 8 import org.eclipse.emf.ecore.resource.Resource; 9 import org.eclipse.emf.ecore.resource.ResourceSet; 10 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; 11 import org.eclipse.jface.text.IDocument; 12 import org.eclipse.jface.text.ITextInputListener; 4 13 import org.eclipse.jface.viewers.IStructuredContentProvider; 5 14 import org.eclipse.jface.viewers.ITableLabelProvider; … … 10 19 import org.eclipse.swt.custom.SashForm; 11 20 import org.eclipse.swt.graphics.Image; 21 import org.eclipse.swt.layout.FillLayout; 12 22 import org.eclipse.swt.widgets.Composite; 13 23 import org.eclipse.ui.ISharedImages; 14 24 import org.eclipse.ui.PlatformUI; 15 25 import org.eclipse.ui.part.ViewPart; 26 import org.eclipse.xtext.resource.XtextResource; 16 27 import org.eclipse.xtext.ui.editor.XtextSourceViewer; 17 28 import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditor; 29 import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorFactory; 18 30 import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorModelAccess; 31 import org.eclipse.xtext.ui.editor.embedded.IEditedResourceProvider; 32 import org.eclipse.xtext.ui.editor.model.XtextDocument; 19 33 34 import com.google.inject.Inject; 35 import com.google.inject.Injector; 36 37 import de.ugoe.cs.swe.bnftools.EbnfStandaloneSetup; 38 import de.ugoe.cs.swe.bnftools.ui.internal.EbnfActivator; 39 40 @SuppressWarnings("restriction") 20 41 public class View extends ViewPart { 42 private static final String FILE = "/Users/philip-iii/Dev/workspaces/bnf-v2/de.ugoe.cs.swe.bnftools.ebnf.standalone/somefile.bnf"; 43 21 44 public static final String ID = "de.ugoe.cs.swe.bnftools.ebnf.standalone.view"; 22 45 46 //NEW 47 @Inject EBNFEditedResourceProvider editedResourceProvider; 48 @Inject EmbeddedEditorFactory factory; 49 50 23 51 private TableViewer viewer; 24 52 private EmbeddedEditor handle; 25 53 private SashForm sashForm; 26 54 private EmbeddedEditorModelAccess partialEditor; 27 private Resource resource;28 55 private XtextSourceViewer viewer2; 29 56 … … 51 78 } 52 79 80 //NEW 81 private void createEditor() { 82 IEditedResourceProvider resourceProvider = new IEditedResourceProvider() { 83 84 @Override 85 public XtextResource createResource() { 86 try { 87 EbnfStandaloneSetup.doSetup(); 88 ResourceSet resourceSet = new ResourceSetImpl(); 89 Resource resource = resourceSet.createResource(URI.createURI(FILE)); 90 return (XtextResource) resource; 91 } catch (Exception e) { 92 return null; 93 } 94 } 95 }; 96 97 //or change to current activator... 98 EbnfActivator activator = EbnfActivator.getInstance(); 99 Injector injector = activator 100 .getInjector(EbnfActivator.DE_UGOE_CS_SWE_BNFTOOLS_EBNF); 101 EmbeddedEditorFactory factory = injector.getInstance(EmbeddedEditorFactory.class); 102 handle = factory.newEditor(resourceProvider).withParent( 103 sashForm); 104 105 106 // keep the partialEditor as instance var to read / write the edited text 107 partialEditor = handle.createPartialEditor(true); 108 viewer2 = handle.getViewer(); 109 final File f = new File(FILE); 110 try { 111 String string = FileUtils.readFileToString(f); 112 viewer2.getDocument().set(string); 113 } catch (IOException e1) { 114 e1.printStackTrace(); 115 } 116 viewer2.addTextInputListener(new ITextInputListener() { 117 118 @Override 119 public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { 120 System.out.println("-->save"); 121 XtextDocument d = (XtextDocument) oldInput; 122 System.out.println(oldInput.get()); 123 System.out.println(f.getAbsolutePath()); 124 try { 125 FileUtils.writeStringToFile(f, oldInput.get()); 126 } catch (IOException e) { 127 e.printStackTrace(); 128 } 129 } 130 131 @Override 132 public void inputDocumentAboutToBeChanged(IDocument oldInput, 133 IDocument newInput) { 134 } 135 }); 136 } 137 138 53 139 class ViewLabelProvider extends LabelProvider implements 54 140 ITableLabelProvider { … … 72 158 */ 73 159 public void createPartControl(Composite parent) { 74 viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL 160 sashForm = new SashForm(parent, SWT.HORIZONTAL); 161 sashForm.setLayout(new FillLayout()); 162 createEditor(); 163 164 viewer = new TableViewer(sashForm, SWT.MULTI | SWT.H_SCROLL 75 165 | SWT.V_SCROLL); 76 166 viewer.setContentProvider(new ViewContentProvider());
Note: See TracChangeset
for help on using the changeset viewer.