Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 493694
Collapse All | Expand All

(-)a/org.eclipse.gef4.dot.ui/src/org/eclipse/gef4/dot/internal/ui/DotGraphView.java (-7 / +56 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2014, 2015 Fabian Steeg (hbz), and others.
2
 * Copyright (c) 2014, 2016 itemis AG and others.
3
 *
3
 *
4
 * All rights reserved. This program and the accompanying materials
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
5
 * are made available under the terms of the Eclipse Public License v1.0
Lines 11-21 Link Here
11
 *     Matthias Wienand (itemis AG) - Refactorings and cleanups
11
 *     Matthias Wienand (itemis AG) - Refactorings and cleanups
12
 *     Alexander Nyßen (itemis AG) - Refactorings and cleanups
12
 *     Alexander Nyßen (itemis AG) - Refactorings and cleanups
13
 *     Tamas Miklossy (itemis AG) - Refactoring of preferences (bug #446639)
13
 *     Tamas Miklossy (itemis AG) - Refactoring of preferences (bug #446639)
14
 *                                - Render embedded dot graphs in native mode (bug #493694)
14
 *
15
 *
15
 *******************************************************************************/
16
 *******************************************************************************/
16
package org.eclipse.gef4.dot.internal.ui;
17
package org.eclipse.gef4.dot.internal.ui;
17
18
19
import java.io.BufferedWriter;
18
import java.io.File;
20
import java.io.File;
21
import java.io.FileWriter;
22
import java.io.IOException;
19
import java.net.MalformedURLException;
23
import java.net.MalformedURLException;
20
import java.util.regex.Matcher;
24
import java.util.regex.Matcher;
21
import java.util.regex.Pattern;
25
import java.util.regex.Pattern;
Lines 113-118 Link Here
113
		 */
117
		 */
114
		public String getDotString() {
118
		public String getDotString() {
115
			return trimNonDotSuffix(trimNonDotPrefix());
119
			return trimNonDotSuffix(trimNonDotPrefix());
120
		}
121
122
		/**
123
		 * @return A temporary file containing the DOT string extracted from the
124
		 *         input, or the {@code NO_DOT} constant, a valid DOT graph
125
		 */
126
		public File getDotTempFile() {
127
			File tempFile = null;
128
			try {
129
				tempFile = File.createTempFile("tempDotExtractorFile", ".dot"); //$NON-NLS-1$ //$NON-NLS-2$
130
			} catch (IOException e) {
131
				System.err
132
						.println("DotExtractor failed to create temp dot file"); //$NON-NLS-1$
133
				e.printStackTrace();
134
			}
135
136
			if (tempFile != null) {
137
				// use try-with-resources to utilize the AutoClosable
138
				// functionality
139
				try (BufferedWriter bw = new BufferedWriter(
140
						new FileWriter(tempFile))) {
141
					bw.write(getDotString());
142
				} catch (IOException e) {
143
					e.printStackTrace();
144
				}
145
			}
146
147
			return tempFile;
116
		}
148
		}
117
149
118
		private String trimNonDotPrefix() {
150
		private String trimNonDotPrefix() {
Lines 330-348 Link Here
330
		}
362
		}
331
363
332
		currentFile = file;
364
		currentFile = file;
333
		if (currentFile.getName().endsWith("." + EXTENSION)) { //$NON-NLS-1$
365
		boolean isEmbeddedDotFile = !currentFile.getName()
334
			currentDot = DotFileUtils.read(currentFile);
366
				.endsWith("." + EXTENSION); //$NON-NLS-1$
367
368
		DotExtractor dotExtractor = null;
369
		if (isEmbeddedDotFile) {
370
			dotExtractor = new DotExtractor(currentFile);
371
			currentDot = dotExtractor.getDotString();
335
		} else {
372
		} else {
336
			currentDot = new DotExtractor(currentFile).getDotString();
373
			currentDot = DotFileUtils.read(currentFile);
337
		}
374
		}
338
375
339
		// if Graphviz 'dot' executable is available, we use it for layout
376
		// if Graphviz 'dot' executable is available, we use it for layout
340
		// (native mode); otherwise we emulate layout with GEF4 Layout
377
		// (native mode); otherwise we emulate layout with GEF4 Layout
341
		// algorithms.
378
		// algorithms.
342
		if (isNativeMode()) {
379
		if (isNativeMode()) {
343
			String[] result = DotExecutableUtils.executeDot(
380
			String[] result;
344
					new File(GraphvizPreferencePage.getDotExecutablePath()),
381
			if (isEmbeddedDotFile) {
345
					file, null, null);
382
				File tempDotFile = dotExtractor.getDotTempFile();
383
				if (tempDotFile == null) {
384
					return false;
385
				}
386
				result = DotExecutableUtils.executeDot(
387
						new File(GraphvizPreferencePage.getDotExecutablePath()),
388
						tempDotFile, null, null);
389
				tempDotFile.delete();
390
			} else {
391
				result = DotExecutableUtils.executeDot(
392
						new File(GraphvizPreferencePage.getDotExecutablePath()),
393
						file, null, null);
394
			}
346
			currentDot = result[0];
395
			currentDot = result[0];
347
		}
396
		}
348
		setGraphAsync(currentDot, currentFile);
397
		setGraphAsync(currentDot, currentFile);

Return to bug 493694