Bug 539040: [LtxR-DocProcessing] Migrate doc processing for Latex+R
documents to new framework (DocMLET)
Change-Id: Id8c4e21d097b495540e043726b8226ca053e9d12
diff --git a/redocs/_build/org.eclipse.statet.redocs.tex.r-feature/feature.xml b/redocs/_build/org.eclipse.statet.redocs.tex.r-feature/feature.xml
index ec46fcd..f1deaa1 100644
--- a/redocs/_build/org.eclipse.statet.redocs.tex.r-feature/feature.xml
+++ b/redocs/_build/org.eclipse.statet.redocs.tex.r-feature/feature.xml
@@ -44,13 +44,6 @@
unpack="false"/>
<plugin
- id="org.eclipse.statet.docmletrg.eclipse.statet.texlipse"
- download-size="0"
- install-size="0"
- version="0.0.0"
- unpack="false"/>
-
- <plugin
id="org.eclipse.statet.redocs.r"
download-size="0"
install-size="0"
diff --git a/redocs/org.eclipse.statet.redocs.tex.r/META-INF/MANIFEST.MF b/redocs/org.eclipse.statet.redocs.tex.r/META-INF/MANIFEST.MF
index d2d774a..c413b16 100644
--- a/redocs/org.eclipse.statet.redocs.tex.r/META-INF/MANIFEST.MF
+++ b/redocs/org.eclipse.statet.redocs.tex.r/META-INF/MANIFEST.MF
@@ -33,10 +33,7 @@
org.eclipse.statet.ecommons.variables.core,
org.eclipse.statet.jcommons.collections;version="4.0.0",
org.eclipse.statet.jcommons.lang;version="4.0.0",
- org.eclipse.statet.r.core.util,
- org.eclipse.texlipse,
- org.eclipse.texlipse.builder,
- org.eclipse.texlipse.viewer
+ org.eclipse.statet.r.core.util
Export-Package: org.eclipse.statet.redocs.tex.r.core,
org.eclipse.statet.redocs.tex.r.core.model,
org.eclipse.statet.redocs.tex.r.core.source,
diff --git a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/Messages.java b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/Messages.java
index 58c3b0f..90a4631 100644
--- a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/Messages.java
+++ b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/Messages.java
@@ -19,63 +19,16 @@
public class Messages extends NLS {
- public static String Weave_label;
- public static String Processing_SweaveTab_label;
- public static String RweaveTab_label;
- public static String RweaveTab_Skip_label;
- public static String RweaveTab_InConsole_label;
- public static String RweaveTab_InConsole_InserVar_label;
- public static String RweaveTab_RCmd_label;
- public static String RweaveTab_RCmd_NewConfig_label;
- public static String RweaveTab_RCmd_NewConfig_error_Creating_message;
- public static String RweaveTab_RCmd_NewConfig_seed;
- public static String RweaveTab_RCmd_error_NoConfigSelected_message;
- public static String Insert_SweaveDirVariable_label;
- public static String Insert_LatexDirVariable_label;
- public static String Insert_LatexFileVariable_label;
- public static String Insert_OutputDirVariable_label;
+ public static String Format_LtxRweave_label;
+ public static String Format_RweaveResult_label;
+
+ public static String Weave_label;
+ public static String WeaveTab_name;
+ public static String WeaveTab_OpenResult_label;
public static String Produce_label;
- public static String Processing_TexTab_label;
- public static String TexTab_label;
- public static String TexTab_OpenTex_label;
- public static String TexTab_OpenTex_OnlyOnErrors_label;
- public static String TexTab_OutputDir_label;
- public static String TexTab_OutputDir_longlabel;
- public static String TexTab_OutputFormat_label;
- public static String TexTab_BuildDisabled_label;
- public static String TexTab_BuildEclipse_label;
- public static String TexTab_BuildRConsole_label;
-
- public static String Processing_PreviewTab_label;
- public static String PreviewTab_label;
- public static String PreviewTab_Disable_label;
- public static String PreviewTab_SystemEditor_label;
- public static String PreviewTab_LaunchConfig_label;
- public static String PreviewTab_LaunchConfig_NewConfig_label;
- public static String PreviewTab_LaunchConfig_NewConfig_seed;
- public static String PreviewTab_LaunchConfig_NewConfig_error_Creating_message;
- public static String PreviewTab_LaunchConfig_error_NoConfigSelected_message;
-
- public static String ProcessingConfig_error_MissingRCmdConfig_message;
- public static String ProcessingConfig_error_MissingViewerConfig_message;
-
- public static String RweaveTexProcessing_info_Canceled_message;
- public static String RweaveTexProcessing_Sweave_InConsole_label;
- public static String RweaveTexProcessing_Sweave_error_ResourceVariable_message;
- public static String RweaveTexProcessing_Sweave_Task_label;
- public static String RweaveTexProcessing_Sweave_Task_info_Canceled_message;
- public static String RweaveTexProcessing_Sweave_RCmd_label;
- public static String RweaveTexProcessing_Sweave_RCmd_error_Found_message;
- public static String RweaveTexProcessing_Tex_label;
- public static String RweaveTexProcessing_Tex_error_BuilderNotConfigured_message;
- public static String RweaveTexProcessing_Tex_error_OutputDir_message;
- public static String RweaveTexProcessing_Tex_error_MustBeInWorkspace_message;
- public static String RweaveTexProcessing_Tex_error_NotFound_message;
- public static String RweaveTexProcessing_Tex_error_ResourceVariable_message;
- public static String RweaveTexProcessing_Output_error_NotFound_message;
- public static String RweaveTexProcessing_Output_info_SkipBecauseTex_message;
+ public static String ProduceTab_name;
static {
diff --git a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/Messages.properties b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/Messages.properties
index f2a4be6..9d6b6bd 100644
--- a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/Messages.properties
+++ b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/Messages.properties
@@ -12,59 +12,12 @@
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================#
-Weave_label= Weave R Chunks
-Processing_SweaveTab_label= S&weave
-RweaveTab_label= Process the Sweave document in R:
-RweaveTab_Skip_label= S&kip (Sweave manually)
-RweaveTab_InConsole_label= Run commands in active R C&onsole:
-RweaveTab_InConsole_InserVar_label= Insert &Variable...
-RweaveTab_RCmd_label= Run R C&MD Sweave:
-RweaveTab_RCmd_NewConfig_label= Create New
-RweaveTab_RCmd_NewConfig_seed= Run Sweave
-RweaveTab_RCmd_NewConfig_error_Creating_message= Creating a new launch configuration failed. Please perform it manually.
-RweaveTab_RCmd_error_NoConfigSelected_message= Select a launch configuration for 'R CMD Sweave'
-Insert_SweaveDirVariable_label= Insert Variable for: Directory Location of the Sweave File
-Insert_LatexDirVariable_label= Insert Variable for: Directory Location of the LaTeX File
-Insert_LatexFileVariable_label= Insert Variable for: Location of the LaTeX File
-Insert_OutputDirVariable_label= Insert Variable for: Directory Location of the Output File
+Format_LtxRweave_label= LaTeX+R
+Format_RweaveResult_label= R-Weave Result / {0}
+
+Weave_label= Weave R Chunks
+WeaveTab_name= R-Weave
+WeaveTab_OpenResult_label= O&pen R-Weave-Result
Produce_label= Produce Output
-Processing_TexTab_label= La&TeX
-TexTab_label= Process the generated LaTeX document:
-TexTab_OpenTex_label= Open tex file in &editor.
-TexTab_OpenTex_OnlyOnErrors_label= O&nly, if build finds errors in document.
-TexTab_OutputDir_longlabel= Output &directory (empty= directory of LaTeX file):
-TexTab_OutputDir_label= Output directory
-TexTab_OutputFormat_label= Output &format:
-TexTab_BuildDisabled_label= &Don't build tex file.
-TexTab_BuildEclipse_label= Build tex file using the Eclipse/Te&Xlipse configuration:
-TexTab_BuildRConsole_label= Build tex file using the &R commands:
-
-Processing_PreviewTab_label= &Preview
-PreviewTab_label= Open a viewer for generated document:
-PreviewTab_Disable_label= &Disable preview.
-PreviewTab_SystemEditor_label= Use the &Eclipse default editor/viewer.
-PreviewTab_LaunchConfig_label= Use the &specified viewer configuration (View LaTeX Document for the output format):
-PreviewTab_LaunchConfig_NewConfig_label= Create New
-PreviewTab_LaunchConfig_NewConfig_seed= {0} Viewer
-PreviewTab_LaunchConfig_NewConfig_error_Creating_message= Creating a new launch configuration failed. Please perform it manually.
-PreviewTab_LaunchConfig_error_NoConfigSelected_message= You have to select a viewer configuration.
-
-ProcessingConfig_error_MissingRCmdConfig_message= The launch configuration ''{0}'' to run R CMD Sweave is missing.
-ProcessingConfig_error_MissingViewerConfig_message= The launch configuration ''{0}'' to open the output viewer is missing.
-
-RweaveTexProcessing_info_Canceled_message= The processing was canceled.
-RweaveTexProcessing_Sweave_InConsole_label= Running Sweave command in R console
-RweaveTexProcessing_Sweave_error_ResourceVariable_message= Resolving resource location variables for the Sweave R command failed.
-RweaveTexProcessing_Sweave_Task_label= Processing ''{0}''
-RweaveTexProcessing_Sweave_Task_info_Canceled_message= The Sweave Task was canceled. The Sweave Document Processing is aborted.
-RweaveTexProcessing_Sweave_RCmd_label= Running R CMD Sweave
-RweaveTexProcessing_Sweave_RCmd_error_Found_message= Error found when running R CMD Sweave, R exit value is {0}. The Sweave Document Processing is aborted.
-RweaveTexProcessing_Tex_label= Building TeX file
-RweaveTexProcessing_Tex_error_MustBeInWorkspace_message= The working directory (folder of tex file) have to be in the Eclipse workspace.
-RweaveTexProcessing_Tex_error_NotFound_message= The TeX file, expected at ''{0}'' could not be found.
-RweaveTexProcessing_Tex_error_OutputDir_message= The output directory could not be resolved for TeX builder/viewer. The Sweave Document Processing is aborted.
-RweaveTexProcessing_Tex_error_BuilderNotConfigured_message= No (correct) TeX builder configured. The Sweave Document Processing is aborted.
-RweaveTexProcessing_Tex_error_ResourceVariable_message= Resolving resource location variables for the TeX R command failed.
-RweaveTexProcessing_Output_error_NotFound_message= The output file, expected at ''{0}'' can not be found.
-RweaveTexProcessing_Output_info_SkipBecauseTex_message= Opening the output automatically is skipped because of errors in TeX file.
+ProduceTab_name= Produce Output
diff --git a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/PreviewTab.java b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/PreviewTab.java
deleted file mode 100644
index 9a8f29f..0000000
--- a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/PreviewTab.java
+++ /dev/null
@@ -1,443 +0,0 @@
-/*=============================================================================#
- # Copyright (c) 2007, 2018 Stephan Wahlbrink and others.
- #
- # This program and the accompanying materials are made available under the
- # terms of the Eclipse Public License 2.0 which is available at
- # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
- # which is available at https://www.apache.org/licenses/LICENSE-2.0.
- #
- # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
- #
- # Contributors:
- # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
- #=============================================================================*/
-
-package org.eclipse.statet.internal.redocs.tex.r.ui.processing;
-
-import java.util.List;
-
-import org.eclipse.core.databinding.DataBindingContext;
-import org.eclipse.core.databinding.UpdateValueStrategy;
-import org.eclipse.core.databinding.observable.ChangeEvent;
-import org.eclipse.core.databinding.observable.Diffs;
-import org.eclipse.core.databinding.observable.Realm;
-import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
-import org.eclipse.core.databinding.observable.value.IObservableValue;
-import org.eclipse.core.databinding.observable.value.WritableValue;
-import org.eclipse.core.databinding.validation.IValidator;
-import org.eclipse.core.databinding.validation.ValidationStatus;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationListener;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.debug.ui.EnvironmentTab;
-import org.eclipse.debug.ui.ILaunchConfigurationTab;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.texlipse.Texlipse;
-import org.eclipse.texlipse.viewer.TexLaunchConfigurationDelegate;
-import org.eclipse.texlipse.viewer.TexLaunchConfigurationTab;
-import org.eclipse.texlipse.viewer.ViewerConfiguration;
-import org.eclipse.ui.statushandlers.StatusManager;
-
-import org.eclipse.statet.ecommons.debug.ui.config.LaunchConfigTabWithDbc;
-import org.eclipse.statet.ecommons.ui.util.LayoutUtil;
-import org.eclipse.statet.ecommons.ui.util.UIAccess;
-
-import org.eclipse.statet.docmlet.base.ui.DocBaseUIResources;
-import org.eclipse.statet.redocs.tex.r.ui.TexRweaveUI;
-
-
-public class PreviewTab extends LaunchConfigTabWithDbc {
-
-
- public static final String NS= "org.eclipse.statet.r.debug/DocPreview/"; //$NON-NLS-1$
- public static final String ATTR_VIEWER_CODE= NS + "Viewer.code"; //$NON-NLS-1$
-
-
- private class SelectionObservable extends AbstractObservableValue implements SelectionListener, ISelectionChangedListener, IDocumentListener, IValidator {
-
- private String encodedValue;
- private IStatus currentStatus;
-
-
- public SelectionObservable() {
- this.currentStatus= ValidationStatus.ok();
- }
-
-
- @Override
- public Object getValueType() {
- return String.class;
- }
-
- @Override
- protected void doSetValue(final Object value) {
- if (value instanceof String) {
- final String s= (String) value;
- this.encodedValue= s;
- if (s.startsWith(TexRweaveLaunchDelegate.PREVIEW_IDE)) {
- updateEnablement(TexRweaveLaunchDelegate.PREVIEW_IDE);
- this.currentStatus= ValidationStatus.ok();
- return;
- }
- else if (s.startsWith(TexRweaveLaunchDelegate.PREVIEW_SPECIAL)) {
- updateEnablement(TexRweaveLaunchDelegate.PREVIEW_SPECIAL);
-
- final String[] split= s.split(":", 2); //$NON-NLS-1$
- if (split.length == 2 && split[1].length() > 0) {
- final List<ViewerConfiguration> configs= PreviewTab.this.availablePreviewConfigs;
- for (final ViewerConfiguration config : configs) {
- if (config.getName().equals(split[1])) {
- PreviewTab.this.launchConfigTable.setSelection(new StructuredSelection(config));
- this.currentStatus= ValidationStatus.ok();
- return;
- }
- }
- }
- PreviewTab.this.launchConfigTable.setSelection(new StructuredSelection());
- this.currentStatus= ValidationStatus.warning(Messages.PreviewTab_LaunchConfig_error_NoConfigSelected_message);
- return;
- }
- }
-
- this.currentStatus= ValidationStatus.ok();
- updateEnablement(null);
- }
-
- @Override
- protected Object doGetValue() {
- return this.encodedValue;
- }
-
- @Override
- public void widgetDefaultSelected(final SelectionEvent e) {
- }
-
- @Override
- public void widgetSelected(final SelectionEvent e) {
- if (!isInitializing()) {
- updateValue();
- }
- }
-
- @Override
- public void selectionChanged(final SelectionChangedEvent event) {
- if (!isInitializing()) {
- updateValue();
- }
- }
-
- @Override
- public void documentAboutToBeChanged(final DocumentEvent event) {
- }
-
- @Override
- public void documentChanged(final DocumentEvent event) {
- if (!isInitializing()) {
- updateValue();
- }
- }
-
- private void updateValue() {
- String value;
- if (PreviewTab.this.systemSelectControl.getSelection()) {
- value= TexRweaveLaunchDelegate.PREVIEW_IDE;
- this.currentStatus= ValidationStatus.ok();
- updateEnablement(TexRweaveLaunchDelegate.PREVIEW_IDE);
- }
- else if (PreviewTab.this.launchConfigSelectControl.getSelection()) {
- final Object selectedLaunch= ((StructuredSelection) PreviewTab.this.launchConfigTable.getSelection()).getFirstElement();
- value= TexRweaveLaunchDelegate.PREVIEW_SPECIAL;
- if (selectedLaunch instanceof ViewerConfiguration) {
- value += ':'+((ViewerConfiguration) selectedLaunch).getName();
- this.currentStatus= ValidationStatus.ok();
- }
- else {
- this.currentStatus= ValidationStatus.warning(Messages.PreviewTab_LaunchConfig_error_NoConfigSelected_message);
- }
- updateEnablement(TexRweaveLaunchDelegate.PREVIEW_SPECIAL);
- }
- else {
- value= ""; //$NON-NLS-1$
- this.currentStatus= ValidationStatus.ok();
- updateEnablement(null);
- }
- if (!value.equals(this.encodedValue)) {
- final String oldValue= this.encodedValue;
- this.encodedValue= value;
- fireValueChange(Diffs.createValueDiff(oldValue, value));
- }
- }
-
- @Override
- public IStatus validate(final Object value) {
- return this.currentStatus;
- }
-
- public void updateEnablement(final String selection) {
- PreviewTab.this.disableSelectControl.setSelection(selection == null);
- PreviewTab.this.systemSelectControl.setSelection(selection == TexRweaveLaunchDelegate.PREVIEW_IDE);
- PreviewTab.this.launchConfigSelectControl.setSelection(selection == TexRweaveLaunchDelegate.PREVIEW_SPECIAL);
-
- PreviewTab.this.launchConfigTable.getControl().setEnabled(selection == TexRweaveLaunchDelegate.PREVIEW_SPECIAL);
- PreviewTab.this.launchConfigNewButton.setEnabled(selection == TexRweaveLaunchDelegate.PREVIEW_SPECIAL);
- }
-
- }
-
-
- private List<ViewerConfiguration> availablePreviewConfigs;
- private final IObservableValue<String> selectionValue;
-
- private ILaunchConfigurationListener launchConfigurationListener;
- private Button disableSelectControl;
- private Button systemSelectControl;
- private Button launchConfigSelectControl;
- private TableViewer launchConfigTable;
- private Button launchConfigNewButton;
-
- private String outputFormat;
- private TexTab texTab;
- private SelectionObservable selectionObservable;
-
-
- public PreviewTab() {
- final Realm realm= getRealm();
- this.selectionValue= new WritableValue<>(realm, null, String.class);
- }
-
- @Override
- public String getName() {
- return Messages.Processing_PreviewTab_label;
- }
-
- @Override
- public Image getImage() {
- return DocBaseUIResources.INSTANCE.getImage(DocBaseUIResources.TOOL_PREVIEW_IMAGE_ID);
- }
-
-
- @Override
- public void createControl(final Composite parent) {
- final Composite mainComposite= new Composite(parent, SWT.NONE);
- setControl(mainComposite);
- mainComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- mainComposite.setLayout(new GridLayout());
-
- final Label label= new Label(mainComposite, SWT.NONE);
- label.setText(Messages.PreviewTab_label);
- label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-
- LayoutUtil.addSmallFiller(mainComposite, false);
-
- Composite composite;
- composite= new Composite(mainComposite, SWT.NONE);
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- createOptions(composite);
-
- this.launchConfigurationListener= new ILaunchConfigurationListener() {
- @Override
- public void launchConfigurationAdded(final ILaunchConfiguration configuration) {
- updateAvailableConfigs();
- }
- @Override
- public void launchConfigurationChanged(final ILaunchConfiguration configuration) {
- updateAvailableConfigs();
- }
- @Override
- public void launchConfigurationRemoved(final ILaunchConfiguration configuration) {
- updateAvailableConfigs();
- }
- };
- DebugPlugin.getDefault().getLaunchManager().addLaunchConfigurationListener(this.launchConfigurationListener);
-
- initBindings();
- }
-
- private void createOptions(final Composite group) {
- GridData gd;
- group.setLayout(LayoutUtil.createCompositeGrid(2));
-
- this.disableSelectControl= new Button(group, SWT.RADIO);
- this.disableSelectControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- this.disableSelectControl.setText(Messages.PreviewTab_Disable_label);
-
- LayoutUtil.addSmallFiller(group, false);
-
- this.systemSelectControl= new Button(group, SWT.RADIO);
- this.systemSelectControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- this.systemSelectControl.setText(Messages.PreviewTab_SystemEditor_label);
-
- LayoutUtil.addSmallFiller(group, false);
-
- this.launchConfigSelectControl= new Button(group, SWT.RADIO);
- this.launchConfigSelectControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- this.launchConfigSelectControl.setText(Messages.PreviewTab_LaunchConfig_label);
-
- this.launchConfigTable= new TableViewer(group, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
- gd= new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
- gd.horizontalIndent= LayoutUtil.defaultIndent();
- gd.heightHint= LayoutUtil.hintHeight(this.launchConfigTable.getTable(), 5);
- this.launchConfigTable.getControl().setLayoutData(gd);
- this.launchConfigTable.setLabelProvider(new LabelProvider() {
- @Override
- public String getText(final Object element) {
- if (element instanceof ViewerConfiguration) {
- return ((ViewerConfiguration) element).getName();
- }
- return super.getText(element);
- }
- });
- this.launchConfigTable.setContentProvider(new ArrayContentProvider());
- this.launchConfigTable.setInput(new Object());
-
- this.launchConfigNewButton= new Button(group, SWT.PUSH);
- this.launchConfigNewButton.setText(Messages.PreviewTab_LaunchConfig_NewConfig_label);
- gd= new GridData(SWT.FILL, SWT.TOP, false, false);
- gd.widthHint= LayoutUtil.hintWidth(this.launchConfigNewButton);
- this.launchConfigNewButton.setLayoutData(gd);
- this.launchConfigNewButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(final SelectionEvent e) {
- createNewPreviewLaunchConfig();
- }
-
- });
- }
-
-
- private final Runnable fUpdateConfigsRunnable= new Runnable() {
- @Override
- public void run() {
- PreviewTab.this.fUpdateConfigsScheduled= false;
- if (PreviewTab.this.texTab == null) {
- final ILaunchConfigurationTab[] tabs= getLaunchConfigurationDialog().getTabs();
- for (int i= 0; i < tabs.length; i++) {
- if (tabs[i] instanceof TexTab) {
- PreviewTab.this.texTab= (TexTab) tabs[i];
- }
- }
- if (PreviewTab.this.texTab == null) {
- return;
- }
- if (!PreviewTab.this.texTab.addOutputFormatListener(
- (final ChangeEvent event) -> updateAvailableConfigs() )) {
- PreviewTab.this.texTab= null;
- return;
- }
- }
- PreviewTab.this.outputFormat= PreviewTab.this.texTab.getOutputFormat();
- PreviewTab.this.availablePreviewConfigs= Texlipse.getViewerManager().getAvailableConfigurations(PreviewTab.this.outputFormat);
- if (UIAccess.isOkToUse(PreviewTab.this.launchConfigTable)) {
- PreviewTab.this.launchConfigTable.setInput(PreviewTab.this.availablePreviewConfigs);
- if (PreviewTab.this.selectionObservable != null) {
- PreviewTab.this.selectionObservable.updateValue();
- }
- }
- }
- };
- private volatile boolean fUpdateConfigsScheduled;
-
- private void updateAvailableConfigs() {
- final Display display= UIAccess.getDisplay();
- if (display.getThread() == Thread.currentThread()) {
- this.fUpdateConfigsRunnable.run();
- }
- else if (!this.fUpdateConfigsScheduled) {
- this.fUpdateConfigsScheduled= true;
- display.asyncExec(this.fUpdateConfigsRunnable);
- }
- }
-
- private void createNewPreviewLaunchConfig() {
- try {
- final ILaunchManager launchManager= DebugPlugin.getDefault().getLaunchManager();
- final ILaunchConfigurationType type= launchManager.getLaunchConfigurationType(TexLaunchConfigurationDelegate.CONFIGURATION_ID);
- final String name= getLaunchConfigurationDialog().generateName(NLS.bind(Messages.PreviewTab_LaunchConfig_NewConfig_seed, this.outputFormat.toUpperCase()));
- final ILaunchConfigurationWorkingCopy config= type.newInstance(null, name);
- new EnvironmentTab().setDefaults(config);
- new TexLaunchConfigurationTab().setDefaults(config);
-
- this.selectionValue.setValue(TexRweaveLaunchDelegate.PREVIEW_SPECIAL+':'+name);
- setDirty(true);
-
- config.doSave();
- }
- catch (final CoreException e) {
- StatusManager.getManager().handle(new Status(IStatus.ERROR, TexRweaveUI.BUNDLE_ID, 0,
- Messages.PreviewTab_LaunchConfig_NewConfig_error_Creating_message, e), StatusManager.LOG | StatusManager.SHOW);
- }
- }
-
- @Override
- protected void addBindings(final DataBindingContext dbc, final Realm realm) {
- this.selectionObservable= new SelectionObservable();
- this.disableSelectControl.addSelectionListener(this.selectionObservable);
- this.systemSelectControl.addSelectionListener(this.selectionObservable);
- this.launchConfigSelectControl.addSelectionListener(this.selectionObservable);
- this.launchConfigTable.addSelectionChangedListener(this.selectionObservable);
- this.selectionValue.setValue("init"); //$NON-NLS-1$
-
- dbc.bindValue(this.selectionObservable, this.selectionValue, new UpdateValueStrategy().setAfterGetValidator(this.selectionObservable), null);
- }
-
-
- @Override
- public void setDefaults(final ILaunchConfigurationWorkingCopy configuration) {
- configuration.setAttribute(ATTR_VIEWER_CODE, TexRweaveLaunchDelegate.PREVIEW_IDE);
- }
-
- @Override
- protected void doInitialize(final ILaunchConfiguration configuration) {
- updateAvailableConfigs();
-
- String value= null;
- try {
- value= configuration.getAttribute(ATTR_VIEWER_CODE, ""); //$NON-NLS-1$
- } catch (final CoreException e) {
- logReadingError(e);
- }
- final Object firstConfig= this.launchConfigTable.getElementAt(0);
- this.launchConfigTable.setSelection((firstConfig != null) ? new StructuredSelection(firstConfig) : new StructuredSelection());
- this.selectionValue.setValue(value);
- }
-
- @Override
- protected void doSave(final ILaunchConfigurationWorkingCopy configuration) {
- configuration.setAttribute(ATTR_VIEWER_CODE, this.selectionValue.getValue());
- }
-
- @Override
- public void dispose() {
- if (this.launchConfigurationListener != null) {
- DebugPlugin.getDefault().getLaunchManager().removeLaunchConfigurationListener(this.launchConfigurationListener);
- this.launchConfigurationListener= null;
- }
- super.dispose();
- }
-
-}
diff --git a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/ProduceTab.java b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/ProduceTab.java
new file mode 100644
index 0000000..47536db
--- /dev/null
+++ b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/ProduceTab.java
@@ -0,0 +1,145 @@
+/*=============================================================================#
+ # Copyright (c) 2015, 2018 Stephan Wahlbrink and others.
+ #
+ # This program and the accompanying materials are made available under the
+ # terms of the Eclipse Public License 2.0 which is available at
+ # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
+ # which is available at https://www.apache.org/licenses/LICENSE-2.0.
+ #
+ # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
+ #
+ # Contributors:
+ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
+ #=============================================================================*/
+
+package org.eclipse.statet.internal.redocs.tex.r.ui.processing;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.swt.graphics.Image;
+
+import org.eclipse.statet.jcommons.collections.ImCollections;
+
+import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingConfig.Format;
+import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingConfigIOStepTab;
+import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingConfigMainTab;
+import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingConfigStepTab;
+import org.eclipse.statet.docmlet.base.ui.processing.operations.RunExternalProgramOperationSettings;
+import org.eclipse.statet.redocs.r.ui.RedocsRUIResources;
+import org.eclipse.statet.redocs.r.ui.processing.RunRCmdToolOperationSettings;
+import org.eclipse.statet.redocs.r.ui.processing.RunRConsoleSnippetOperation;
+import org.eclipse.statet.redocs.r.ui.processing.RunRConsoleSnippetOperationSettings;
+
+
+public class ProduceTab extends DocProcessingConfigIOStepTab
+ implements DocProcessingConfigStepTab.Listener {
+
+
+ private final DocProcessingConfigIOStepTab weaveTab;
+
+
+ public ProduceTab(final DocProcessingConfigMainTab mainTab,
+ final DocProcessingConfigIOStepTab weaveTab) {
+ super(mainTab, TexRweaveConfig.PRODUCE_ATTR_QUALIFIER);
+
+ this.weaveTab= weaveTab;
+ this.weaveTab.addListener(this);
+
+ setInput(TexRweaveConfig.SOURCE_FORMAT, null);
+ setAvailableOutputFormats(TexRweaveConfig.PRODUCE_OUTPUT_FORMATS,
+ TexRweaveConfig.EXT_PDF_FORMAT_KEY );
+
+ setAvailableOperations(ImCollections.newList(
+ new RunRConsoleSnippetOperationSettings(),
+ new RunRCmdToolOperationSettings(),
+ new RunExternalProgramOperationSettings() ));
+
+ this.weaveTab.getOutputFileValue().addValueChangeListener(this);
+ }
+
+
+ @Override
+ public Image getImage() {
+ return RedocsRUIResources.INSTANCE.getImage(RedocsRUIResources.TOOL_BUILDTEX_IMAGE_ID);
+ }
+
+ @Override
+ public String getName() {
+ return createName(Messages.ProduceTab_name);
+ }
+
+ @Override
+ public String getLabel() {
+ return Messages.Produce_label;
+ }
+
+ @Override
+ public void changed(final DocProcessingConfigStepTab source) {
+ if (source == this.weaveTab) {
+ updateInput();
+ }
+ }
+
+ @Override
+ public void handleValueChange(final ValueChangeEvent<?> event) {
+ if (event.getObservable() == this.weaveTab.getOutputFileValue()
+ && this.weaveTab.isEnabled() ) {
+ updateInput();
+ return;
+ }
+ super.handleValueChange(event);
+ }
+
+ private void updateInput() {
+ if (this.weaveTab.isEnabled()) {
+ final Format format= this.weaveTab.getOutputFormat();
+ setInput((format != null) ?
+ TexRweaveConfig.createWeaveOutputFormat(format) :
+ null,
+ this.weaveTab.getOutputFile() );
+ }
+ else {
+ setInput(TexRweaveConfig.SOURCE_FORMAT,
+ getMainTab().getSourceFile() );
+ }
+ }
+
+ @Override
+ protected IFile getInputFile(final Format format) throws CoreException {
+ if (this.weaveTab.isEnabled()) {
+ return this.weaveTab.getOutputFile();
+ }
+ return null;
+ }
+
+ @Override
+ protected void addBindings(final DataBindingContext dbc) {
+ super.addBindings(dbc);
+ }
+
+
+ @Override
+ protected String getDefaultOperationId() {
+ return RunRConsoleSnippetOperation.ID;
+ }
+
+ @Override
+ public void setDefaults(final ILaunchConfigurationWorkingCopy configuration) {
+ super.setDefaults(configuration);
+ }
+
+ @Override
+ protected void doInitialize(final ILaunchConfiguration configuration) {
+ super.doInitialize(configuration);
+ }
+
+ @Override
+ protected void doSave(final ILaunchConfigurationWorkingCopy configuration) {
+ super.doSave(configuration);
+ }
+
+}
diff --git a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/RweaveTab.java b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/RweaveTab.java
deleted file mode 100644
index 8d20b2b..0000000
--- a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/RweaveTab.java
+++ /dev/null
@@ -1,512 +0,0 @@
-/*=============================================================================#
- # Copyright (c) 2007, 2018 Stephan Wahlbrink and others.
- #
- # This program and the accompanying materials are made available under the
- # terms of the Eclipse Public License 2.0 which is available at
- # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
- # which is available at https://www.apache.org/licenses/LICENSE-2.0.
- #
- # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
- #
- # Contributors:
- # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
- #=============================================================================*/
-
-package org.eclipse.statet.internal.redocs.tex.r.ui.processing;
-
-import java.util.ArrayList;
-
-import org.eclipse.core.databinding.DataBindingContext;
-import org.eclipse.core.databinding.UpdateValueStrategy;
-import org.eclipse.core.databinding.observable.Diffs;
-import org.eclipse.core.databinding.observable.Realm;
-import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
-import org.eclipse.core.databinding.observable.value.IObservableValue;
-import org.eclipse.core.databinding.observable.value.WritableValue;
-import org.eclipse.core.databinding.validation.IValidator;
-import org.eclipse.core.databinding.validation.ValidationStatus;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationListener;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.debug.ui.DebugUITools;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.statushandlers.StatusManager;
-
-import org.eclipse.statet.jcommons.collections.ImCollections;
-
-import org.eclipse.statet.ecommons.debug.ui.config.LaunchConfigTabWithDbc;
-import org.eclipse.statet.ecommons.io.FileValidator;
-import org.eclipse.statet.ecommons.templates.TemplateVariableProcessor;
-import org.eclipse.statet.ecommons.ui.components.CustomizableVariableSelectionDialog;
-import org.eclipse.statet.ecommons.ui.util.LayoutUtil;
-import org.eclipse.statet.ecommons.ui.util.UIAccess;
-import org.eclipse.statet.ecommons.ui.util.VariableFilterUtils;
-import org.eclipse.statet.ecommons.ui.workbench.ResourceInputComposite;
-
-import org.eclipse.statet.internal.redocs.tex.r.RedocsTexRPlugin;
-import org.eclipse.statet.ltk.ui.sourceediting.SnippetEditor1;
-import org.eclipse.statet.r.cmd.ui.launching.RCmdLaunching;
-import org.eclipse.statet.r.core.RCore;
-import org.eclipse.statet.r.launching.ui.RLaunchingUI;
-import org.eclipse.statet.r.ui.sourceediting.RSourceViewerConfigurator;
-import org.eclipse.statet.r.ui.sourceediting.RTemplateSourceViewerConfigurator;
-import org.eclipse.statet.redocs.r.ui.RedocsRUIResources;
-import org.eclipse.statet.redocs.tex.r.ui.TexRweaveUI;
-
-
-public class RweaveTab extends LaunchConfigTabWithDbc {
-
-
- public static final String NS= "org.eclipse.statet.r.debug/Rweave/"; //$NON-NLS-1$
- public static final String ATTR_SWEAVE_FOLDER= NS + "sweave.folder"; //$NON-NLS-1$
- public static final String ATTR_SWEAVE_ID= NS + "SweaveProcessing"; //$NON-NLS-1$
-
-
- private class SelectionObservable extends AbstractObservableValue implements SelectionListener, ISelectionChangedListener, IDocumentListener, IValidator {
-
- private String fEncodedValue;
- private IStatus fCurrentStatus;
-
-
- public SelectionObservable() {
- this.fCurrentStatus= ValidationStatus.ok();
- }
-
-
- @Override
- public Object getValueType() {
- return String.class;
- }
-
- @Override
- protected void doSetValue(final Object value) {
- if (value instanceof String) {
- final String s= (String) value;
- this.fEncodedValue= s;
- if (s.startsWith(TexRweaveLaunchDelegate.SWEAVE_CONSOLE)) {
- updateEnablement(TexRweaveLaunchDelegate.SWEAVE_CONSOLE);
-
- final String[] split= s.split(":", 2); //$NON-NLS-1$
- final String command= (split.length == 2 && split[1].length() > 0) ? split[1] : TexRweaveLaunchDelegate.DEFAULT_SWEAVE_R_COMMANDS;
- if (!command.equals(RweaveTab.this.fConsoleCommandEditor.getDocument().get())) {
- RweaveTab.this.fConsoleCommandEditor.getDocument().set(command);
- }
-
- this.fCurrentStatus= ValidationStatus.ok();
- return;
- }
- else if (s.startsWith(TexRweaveLaunchDelegate.SWEAVE_LAUNCH)) {
- updateEnablement(TexRweaveLaunchDelegate.SWEAVE_LAUNCH);
-
- final String[] split= s.split(":", 2); //$NON-NLS-1$
- if (split.length == 2 && split[1].length() > 0) {
- final ILaunchConfiguration[] configs= RweaveTab.this.fAvailableConfigs;
- for (final ILaunchConfiguration config : configs) {
- if (config.getName().equals(split[1])) {
- RweaveTab.this.fCmdLaunchTable.setSelection(new StructuredSelection(config));
- this.fCurrentStatus= ValidationStatus.ok();
- return;
- }
- }
- }
- RweaveTab.this.fCmdLaunchTable.setSelection(new StructuredSelection());
- this.fCurrentStatus= ValidationStatus.warning(Messages.RweaveTab_RCmd_error_NoConfigSelected_message);
- return;
- }
- }
-
- this.fCurrentStatus= ValidationStatus.ok();
- updateEnablement(null);
- }
-
- @Override
- protected Object doGetValue() {
- return this.fEncodedValue;
- }
-
- @Override
- public void widgetDefaultSelected(final SelectionEvent e) {
- }
-
- @Override
- public void widgetSelected(final SelectionEvent e) {
- if (!isInitializing()) {
- updateValue();
- }
- }
-
- @Override
- public void selectionChanged(final SelectionChangedEvent event) {
- if (!isInitializing()) {
- updateValue();
- }
- }
-
- @Override
- public void documentAboutToBeChanged(final DocumentEvent event) {
- }
-
- @Override
- public void documentChanged(final DocumentEvent event) {
- if (!isInitializing()) {
- updateValue();
- }
- }
-
- private void updateValue() {
- String value;
- if (RweaveTab.this.fConsoleSelectControl.getSelection()) {
- value= TexRweaveLaunchDelegate.SWEAVE_CONSOLE + ':' + RweaveTab.this.fConsoleCommandEditor.getDocument().get();
- this.fCurrentStatus= ValidationStatus.ok();
- updateEnablement(TexRweaveLaunchDelegate.SWEAVE_CONSOLE);
- }
- else if (RweaveTab.this.fCmdLaunchSelectControl.getSelection()) {
- final Object selectedLaunch= ((StructuredSelection) RweaveTab.this.fCmdLaunchTable.getSelection()).getFirstElement();
- value= TexRweaveLaunchDelegate.SWEAVE_LAUNCH;
- if (selectedLaunch instanceof ILaunchConfiguration) {
- value += ':'+((ILaunchConfiguration) selectedLaunch).getName();
- this.fCurrentStatus= ValidationStatus.ok();
- }
- else {
- this.fCurrentStatus= ValidationStatus.warning(Messages.RweaveTab_RCmd_error_NoConfigSelected_message);
- }
- updateEnablement(TexRweaveLaunchDelegate.SWEAVE_LAUNCH);
- }
- else {
- value= ""; //$NON-NLS-1$
- this.fCurrentStatus= ValidationStatus.ok();
- updateEnablement(null);
- }
- if (!value.equals(this.fEncodedValue)) {
- final String oldValue= this.fEncodedValue;
- this.fEncodedValue= value;
- fireValueChange(Diffs.createValueDiff(oldValue, value));
- }
- }
-
- @Override
- public IStatus validate(final Object value) {
- return this.fCurrentStatus;
- }
-
- public void updateEnablement(final String selection) {
- RweaveTab.this.fSkipSelectControl.setSelection(selection == null);
- RweaveTab.this.fConsoleSelectControl.setSelection(selection == TexRweaveLaunchDelegate.SWEAVE_CONSOLE);
- RweaveTab.this.fCmdLaunchSelectControl.setSelection(selection == TexRweaveLaunchDelegate.SWEAVE_LAUNCH);
-
- RweaveTab.this.fConsoleCommandEditor.getTextControl().setEnabled(selection == TexRweaveLaunchDelegate.SWEAVE_CONSOLE);
- RweaveTab.this.fConsoleCommandInsertButton.setEnabled(selection == TexRweaveLaunchDelegate.SWEAVE_CONSOLE);
- RweaveTab.this.fCmdLaunchTable.getControl().setEnabled(selection == TexRweaveLaunchDelegate.SWEAVE_LAUNCH);
- RweaveTab.this.fCmdLaunchNewButton.setEnabled(selection == TexRweaveLaunchDelegate.SWEAVE_LAUNCH);
- }
-
- }
-
-
- private final IObservableValue<String> fDirValue;
-
- private final IObservableValue<String> fSelectionValue;
-
- private ResourceInputComposite fDirControl;
-
- private ILaunchConfiguration[] fAvailableConfigs;
-
- private ILaunchConfigurationListener fLaunchConfigurationListener;
- private Button fSkipSelectControl;
- private Button fConsoleSelectControl;
- private SnippetEditor1 fConsoleCommandEditor;
-
- private Button fConsoleCommandInsertButton;
- private Button fCmdLaunchSelectControl;
- private TableViewer fCmdLaunchTable;
- private Button fCmdLaunchNewButton;
-
-
- public RweaveTab() {
- final Realm realm= getRealm();
- this.fDirValue= new WritableValue<>(realm, "", String.class); //$NON-NLS-1$
- this.fSelectionValue= new WritableValue<>(realm, null, String.class);
- }
-
-
- @Override
- public String getName() {
- return Messages.Processing_SweaveTab_label;
- }
-
- @Override
- public Image getImage() {
- return RedocsRUIResources.INSTANCE.getImage(RedocsRUIResources.TOOL_RWEAVE_IMAGE_ID);
- }
-
-
- @Override
- public void createControl(final Composite parent) {
- final Composite mainComposite= new Composite(parent, SWT.NONE);
- setControl(mainComposite);
- mainComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- mainComposite.setLayout(new GridLayout());
-
- { final Label label= new Label(mainComposite, SWT.NONE);
- label.setText(Messages.RweaveTab_label);
- label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- }
- LayoutUtil.addSmallFiller(mainComposite, false);
-
- { final Composite composite= createDirectoryGroup(mainComposite);
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- }
- { final Composite composite= createSweaveCommandGroup(mainComposite);
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- }
- this.fLaunchConfigurationListener= new ILaunchConfigurationListener() {
- @Override
- public void launchConfigurationAdded(final ILaunchConfiguration configuration) {
- updateAvailableConfigs();
- }
- @Override
- public void launchConfigurationChanged(final ILaunchConfiguration configuration) {
- updateAvailableConfigs();
- }
- @Override
- public void launchConfigurationRemoved(final ILaunchConfiguration configuration) {
- updateAvailableConfigs();
- }
- };
- DebugPlugin.getDefault().getLaunchManager().addLaunchConfigurationListener(this.fLaunchConfigurationListener);
- updateAvailableConfigs();
-
- initBindings();
- }
-
- private Composite createDirectoryGroup(final Composite parent) {
- final Group group= new Group(parent, SWT.NONE);
- group.setText("Working &Folder (path in workspace):");
- group.setLayout(LayoutUtil.createGroupGrid(1));
-
- this.fDirControl= new ResourceInputComposite(group, ResourceInputComposite.STYLE_TEXT,
- ResourceInputComposite.MODE_DIRECTORY | ResourceInputComposite.MODE_OPEN | ResourceInputComposite.MODE_WS_ONLY,
- "Working Directory");
- this.fDirControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- this.fDirControl.setShowInsertVariable(true, VariableFilterUtils.DEFAULT_NON_ITERACTIVE_FILTERS,
- ImCollections.newList(TexRweaveLaunchDelegate.VARIABLE_SWEAVE_FILE) );
-
- return group;
- }
-
- private Composite createSweaveCommandGroup(final Composite parent) {
- final Composite group= new Composite(parent, SWT.NONE);
- group.setLayout(LayoutUtil.createCompositeGrid(2));
- GridData gd;
-
- this.fSkipSelectControl= new Button(group, SWT.RADIO);
- this.fSkipSelectControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- this.fSkipSelectControl.setText(Messages.RweaveTab_Skip_label);
-
- LayoutUtil.addSmallFiller(group, false);
-
- this.fConsoleSelectControl= new Button(group, SWT.RADIO);
- this.fConsoleSelectControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- this.fConsoleSelectControl.setText(Messages.RweaveTab_InConsole_label);
-
- final TemplateVariableProcessor templateVariableProcessor= new TemplateVariableProcessor();
- final RSourceViewerConfigurator configurator= new RTemplateSourceViewerConfigurator(
- RCore.WORKBENCH_ACCESS,
- templateVariableProcessor );
- this.fConsoleCommandEditor= new SnippetEditor1(configurator, null,
- PlatformUI.getWorkbench(), RLaunchingUI.LAUNCH_CONFIG_QUALIFIER );
- this.fConsoleCommandEditor.create(group, SnippetEditor1.DEFAULT_MULTI_LINE_STYLE);
- gd= new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
- gd.heightHint= LayoutUtil.hintHeight(this.fConsoleCommandEditor.getSourceViewer().getTextWidget(), 5);
- gd.horizontalIndent= LayoutUtil.defaultIndent();
- this.fConsoleCommandEditor.getControl().setLayoutData(gd);
-
- this.fConsoleCommandInsertButton= new Button(group, SWT.PUSH);
- this.fConsoleCommandInsertButton.setText(Messages.RweaveTab_InConsole_InserVar_label);
- this.fConsoleCommandInsertButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
- this.fConsoleCommandInsertButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(final SelectionEvent e) {
- final CustomizableVariableSelectionDialog dialog= new CustomizableVariableSelectionDialog(getShell());
- dialog.setFilters(VariableFilterUtils.DEFAULT_INTERACTIVE_FILTERS);
- dialog.addAdditional(TexRweaveLaunchDelegate.VARIABLE_SWEAVE_FILE);
- dialog.addAdditional(TexRweaveLaunchDelegate.VARIABLE_LATEX_FILE);
- if (dialog.open() != Dialog.OK) {
- return;
- }
- final String variable= dialog.getVariableExpression();
- if (variable == null) {
- return;
- }
- RweaveTab.this.fConsoleCommandEditor.getSourceViewer().getTextWidget().insert(variable);
- RweaveTab.this.fConsoleCommandEditor.getControl().setFocus();
- }
- });
-
- LayoutUtil.addSmallFiller(group, false);
-
- this.fCmdLaunchSelectControl= new Button(group, SWT.RADIO);
- this.fCmdLaunchSelectControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- this.fCmdLaunchSelectControl.setText(Messages.RweaveTab_RCmd_label);
-
- this.fCmdLaunchTable= new TableViewer(group, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
- gd= new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
- gd.horizontalIndent= LayoutUtil.defaultIndent();
- gd.heightHint= LayoutUtil.hintHeight(this.fCmdLaunchTable.getTable(), 5);
- this.fCmdLaunchTable.getControl().setLayoutData(gd);
- this.fCmdLaunchTable.setLabelProvider(DebugUITools.newDebugModelPresentation());
- this.fCmdLaunchTable.setContentProvider(new ArrayContentProvider());
- this.fCmdLaunchTable.setInput(new Object());
-
- this.fCmdLaunchNewButton= new Button(group, SWT.PUSH);
- this.fCmdLaunchNewButton.setText(Messages.RweaveTab_RCmd_NewConfig_label);
- gd= new GridData(SWT.FILL, SWT.TOP, false, false);
- gd.widthHint= LayoutUtil.hintWidth(this.fCmdLaunchNewButton);
- this.fCmdLaunchNewButton.setLayoutData(gd);
- this.fCmdLaunchNewButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(final SelectionEvent e) {
- createNewRCmdSweaveLaunchConfig();
- }
-
- });
- return group;
- }
-
-
- private void updateAvailableConfigs() {
- try {
- final ILaunchManager launchManager= DebugPlugin.getDefault().getLaunchManager();
- final ILaunchConfigurationType type= launchManager.getLaunchConfigurationType(RCmdLaunching.R_CMD_CONFIGURATION_TYPE_ID);
- final ILaunchConfiguration[] allConfigs= launchManager.getLaunchConfigurations(type);
- final ArrayList<Object> filteredConfigs= new ArrayList<>(allConfigs.length+1);
- for (final ILaunchConfiguration config : allConfigs) {
- if (config.getAttribute(RCmdLaunching.R_CMD_COMMAND_ATTR_NAME, "").equals("CMD Sweave")) { //$NON-NLS-1$ //$NON-NLS-2$
- filteredConfigs.add(config);
- }
- }
- this.fAvailableConfigs= filteredConfigs.toArray(new ILaunchConfiguration[filteredConfigs.size()]);
- if (UIAccess.isOkToUse(this.fCmdLaunchTable)) {
- this.fCmdLaunchTable.setInput(this.fAvailableConfigs);
- }
- }
- catch (final CoreException e) {
- RedocsTexRPlugin.logError(0, "An error occurred while updating R CMD list.", e);
- }
- }
-
- private void createNewRCmdSweaveLaunchConfig() {
- try {
- final String name= getLaunchConfigurationDialog().generateName(Messages.RweaveTab_RCmd_NewConfig_seed);
- final ILaunchConfigurationWorkingCopy config= RCmdLaunching.createNewRCmdConfig(name, "CMD Sweave"); //$NON-NLS-1$
-
- this.fSelectionValue.setValue(TexRweaveLaunchDelegate.SWEAVE_LAUNCH+':'+name);
- setDirty(true);
-
- config.doSave();
- }
- catch (final CoreException e) {
- StatusManager.getManager().handle(new Status(IStatus.ERROR, TexRweaveUI.BUNDLE_ID, 0,
- Messages.RweaveTab_RCmd_NewConfig_error_Creating_message, e), StatusManager.LOG | StatusManager.SHOW);
- }
- }
-
- @Override
- protected void addBindings(final DataBindingContext dbc, final Realm realm) {
- final FileValidator validator= this.fDirControl.getValidator();
- validator.setOnEmpty(IStatus.OK);
- dbc.bindValue(
- this.fDirControl.getObservable(),
- this.fDirValue,
- new UpdateValueStrategy().setAfterGetValidator(validator),
- null );
-
- final SelectionObservable obs= new SelectionObservable();
- this.fSkipSelectControl.addSelectionListener(obs);
- this.fConsoleSelectControl.addSelectionListener(obs);
- this.fCmdLaunchSelectControl.addSelectionListener(obs);
- this.fCmdLaunchTable.addSelectionChangedListener(obs);
- this.fConsoleCommandEditor.getDocument().addDocumentListener(obs);
-
- this.fSelectionValue.setValue("init"); //$NON-NLS-1$
-
- dbc.bindValue(obs, this.fSelectionValue,
- new UpdateValueStrategy().setAfterGetValidator(obs),
- null );
- }
-
-
- @Override
- public void setDefaults(final ILaunchConfigurationWorkingCopy configuration) {
- configuration.setAttribute(ATTR_SWEAVE_FOLDER, "${container_path:${source_file_path}}"); //$NON-NLS-1$
- configuration.setAttribute(ATTR_SWEAVE_ID, TexRweaveLaunchDelegate.SWEAVE_CONSOLE+':');
- }
-
- @Override
- protected void doInitialize(final ILaunchConfiguration configuration) {
- { String dir= ""; //$NON-NLS-1$
- try {
- dir= configuration.getAttribute(ATTR_SWEAVE_FOLDER, ""); //$NON-NLS-1$
- }
- catch (final CoreException e) {
- logReadingError(e);
- }
- this.fDirValue.setValue(dir);
- }
-
- this.fConsoleCommandEditor.getDocument().set(TexRweaveLaunchDelegate.DEFAULT_SWEAVE_R_COMMANDS);
- final Object firstConfig= this.fCmdLaunchTable.getElementAt(0);
- this.fCmdLaunchTable.setSelection((firstConfig != null) ? new StructuredSelection(firstConfig) : new StructuredSelection());
- { String value= ""; //$NON-NLS-1$
- try {
- value= configuration.getAttribute(ATTR_SWEAVE_ID, ""); //$NON-NLS-1$
- }
- catch (final CoreException e) {
- logReadingError(e);
- }
- this.fSelectionValue.setValue(value);
- }
- this.fConsoleCommandEditor.reset();
- }
-
- @Override
- protected void doSave(final ILaunchConfigurationWorkingCopy configuration) {
- configuration.setAttribute(ATTR_SWEAVE_ID, this.fSelectionValue.getValue());
- configuration.setAttribute(ATTR_SWEAVE_FOLDER, this.fDirValue.getValue());
- }
-
- @Override
- public void dispose() {
- if (this.fLaunchConfigurationListener != null) {
- DebugPlugin.getDefault().getLaunchManager().removeLaunchConfigurationListener(this.fLaunchConfigurationListener);
- this.fLaunchConfigurationListener= null;
- }
- super.dispose();
- }
-
-}
diff --git a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveConfig.java b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveConfig.java
new file mode 100644
index 0000000..7ccdba5
--- /dev/null
+++ b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveConfig.java
@@ -0,0 +1,57 @@
+/*=============================================================================#
+ # Copyright (c) 2015, 2018 Stephan Wahlbrink and others.
+ #
+ # This program and the accompanying materials are made available under the
+ # terms of the Eclipse Public License 2.0 which is available at
+ # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
+ # which is available at https://www.apache.org/licenses/LICENSE-2.0.
+ #
+ # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
+ #
+ # Contributors:
+ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
+ #=============================================================================*/
+
+package org.eclipse.statet.internal.redocs.tex.r.ui.processing;
+
+import org.eclipse.osgi.util.NLS;
+
+import org.eclipse.statet.jcommons.collections.ImCollections;
+import org.eclipse.statet.jcommons.collections.ImList;
+
+import org.eclipse.statet.redocs.r.ui.processing.RWeaveDocProcessingConfig;
+
+
+public class TexRweaveConfig extends RWeaveDocProcessingConfig {
+
+
+ public static final String TYPE_ID= "org.eclipse.statet.redocs.launchConfigurations.TexRweaveDocProcessing"; //$NON-NLS-1$
+
+
+/*[ Attributes ]===============================================================*/
+
+ // see RWeaveDocProcessingConfig
+
+
+/*[ Formats ]==================================================================*/
+
+
+ public static final Format SOURCE_FORMAT= createSourceFormat(
+ Messages.Format_LtxRweave_label );
+
+ public static Format createWeaveOutputFormat(final Format format) {
+ return new Format(format.getKey(),
+ NLS.bind(Messages.Format_RweaveResult_label, format.getInfoLabel()),
+ format.getExt() );
+ }
+
+ public static final ImList<Format> WEAVE_OUTPUT_FORMATS= ImCollections.newList(
+ TexRweaveConfig.EXT_LTX_FORMAT,
+ TexRweaveConfig.EXT_OTHER_FORMAT );
+
+ public static final ImList<Format> PRODUCE_OUTPUT_FORMATS= ImCollections.newList(
+ TexRweaveConfig.EXT_PDF_FORMAT,
+ TexRweaveConfig.EXT_OTHER_FORMAT );
+
+
+}
diff --git a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveConfigTabGroup.java b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveConfigTabGroup.java
index 5d1016d..7aeda01 100644
--- a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveConfigTabGroup.java
+++ b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveConfigTabGroup.java
@@ -14,12 +14,24 @@
package org.eclipse.statet.internal.redocs.tex.r.ui.processing;
+import java.util.Collections;
+
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
+import org.eclipse.statet.jcommons.collections.ImCollections;
+import org.eclipse.statet.jcommons.collections.ImList;
+
+import org.eclipse.statet.ecommons.debug.ui.config.LaunchConfigPresets;
import org.eclipse.statet.ecommons.debug.ui.util.CheckedCommonTab;
+import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingConfigMainTab;
+import org.eclipse.statet.docmlet.base.ui.processing.PreviewTab;
+import org.eclipse.statet.redocs.r.ui.processing.RunRConsoleSnippetOperation;
+
/**
* Tab group for Sweave (LaTeX+R) output creation toolchain.
@@ -27,17 +39,61 @@
public class TexRweaveConfigTabGroup extends AbstractLaunchConfigurationTabGroup {
+ private static final LaunchConfigPresets PRESETS;
+ static {
+ final LaunchConfigPresets presets= new LaunchConfigPresets(
+ TexRweaveConfig.TYPE_ID );
+
+ { final ILaunchConfigurationWorkingCopy config= presets.add("PDF using R:tools (texi2dvi)");
+ config.setAttribute(TexRweaveConfig.WEAVE_ENABLED_ATTR_NAME, true);
+ config.setAttribute(TexRweaveConfig.WEAVE_OUTPUT_FORMAT_ATTR_NAME,
+ TexRweaveConfig.EXT_LTX_FORMAT_KEY );
+ config.setAttribute(TexRweaveConfig.WEAVE_OPERATION_ID_ATTR_NAME,
+ RunRConsoleSnippetOperation.ID );
+ config.setAttribute(TexRweaveConfig.WEAVE_OPERATION_SETTINGS_ATTR_NAME,
+ Collections.singletonMap(RunRConsoleSnippetOperation.R_SNIPPET_CODE_ATTR_NAME,
+ "Sweave(" +
+ "file= \"${resource_loc}\", " +
+ "encoding= \"${resource_enc}\")" ));
+ config.setAttribute(TexRweaveConfig.PRODUCE_ENABLED_ATTR_NAME, true);
+ config.setAttribute(TexRweaveConfig.PRODUCE_OUTPUT_FORMAT_ATTR_NAME,
+ TexRweaveConfig.EXT_PDF_FORMAT_KEY );
+ config.setAttribute(TexRweaveConfig.PRODUCE_OPERATION_ID_ATTR_NAME,
+ RunRConsoleSnippetOperation.ID );
+ config.setAttribute(TexRweaveConfig.PRODUCE_OPERATION_SETTINGS_ATTR_NAME,
+ Collections.singletonMap(RunRConsoleSnippetOperation.R_SNIPPET_CODE_ATTR_NAME,
+ "tools::texi2dvi(" +
+ "file= \"${resource_loc}\", " +
+ "pdf= TRUE)" ));
+ }
+
+ PRESETS= presets;
+ }
+
+
public TexRweaveConfigTabGroup() {
}
@Override
public void createTabs(final ILaunchConfigurationDialog dialog, final String mode) {
+ final DocProcessingConfigMainTab mainTab= new DocProcessingConfigMainTab(PRESETS) {
+ @Override
+ protected ImList<ILaunchConfigurationTab> getPresetTabs(final ILaunchConfiguration config) {
+ return ImCollections.<ILaunchConfigurationTab>newList(getStepTab(1), getStepTab(2) );
+ }
+ };
+ final TexTab texTab= new TexTab(mainTab);
+ final ProduceTab produceTab= new ProduceTab(mainTab, texTab);
+ final PreviewTab previewTab= new PreviewTab(mainTab, produceTab);
+
final ILaunchConfigurationTab[] tabs= new ILaunchConfigurationTab[] {
- new RweaveTab(),
- new TexTab(),
- new PreviewTab(),
+ mainTab,
+ texTab,
+ produceTab,
+ previewTab,
new CheckedCommonTab()
};
+
setTabs(tabs);
}
diff --git a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveConfigsMenuContribution.java b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveConfigsMenuContribution.java
index 40e3531..6bf7dca 100644
--- a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveConfigsMenuContribution.java
+++ b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveConfigsMenuContribution.java
@@ -14,8 +14,7 @@
package org.eclipse.statet.internal.redocs.tex.r.ui.processing;
-import static org.eclipse.statet.internal.redocs.tex.r.ui.processing.TexRweaveLaunchDelegate.BUILDTEX_TYPE_DISABLED;
-
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.swt.SWT;
@@ -27,7 +26,6 @@
import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingUI.CommonFlags;
import org.eclipse.statet.docmlet.base.ui.processing.actions.RunConfigsMenuContribution;
import org.eclipse.statet.redocs.r.ui.RedocsRUI;
-import org.eclipse.statet.redocs.tex.r.core.TexRweaveCore;
public class TexRweaveConfigsMenuContribution extends RunConfigsMenuContribution {
@@ -39,56 +37,58 @@
private class ThisConfigContribution extends ConfigContribution {
- public ThisConfigContribution(final Image image, final String label,
+ public ThisConfigContribution(final Image icon, final String label,
final ILaunchConfiguration configuration) {
- super(image, label, configuration);
+ super(icon, label, configuration);
}
@Override
protected void addLaunchItems(final Menu menu) {
- boolean weaveDisabled= false;
- boolean texDisabled= false;
- String processDetail= null;
+ String buildDetail= null;
String weaveDetail= null;
- String texDetail= null;
-
+ String produceDetail= null;
try {
final ILaunchConfiguration config= getConfiguration();
- final String attribute= config.getAttribute(RweaveTab.ATTR_SWEAVE_ID, (String) null);
- if (attribute != null && !attribute.isEmpty()) {
- weaveDetail= " (Rnw > TeX)"; //$NON-NLS-1$
- }
- else {
- weaveDisabled= true;
- }
+ final IFile file= getFile();
+ final String sourceInputExt= resolveFormatExt(TexRweaveConfig.SOURCE_FORMAT,
+ file.getFileExtension() );
+ final boolean weaveEnabled= config.getAttribute(TexRweaveConfig.WEAVE_ENABLED_ATTR_NAME, false);
+ final String weaveInputExt= sourceInputExt;
+ final String weaveOutputExt= resolveFormatExt(TexRweaveConfig.getFormat(
+ TexRweaveConfig.WEAVE_OUTPUT_FORMATS, null,
+ config.getAttribute(TexRweaveConfig.WEAVE_OUTPUT_FORMAT_ATTR_NAME, (String) null) ),
+ weaveInputExt );
+ final boolean produceEnabled= config.getAttribute(TexRweaveConfig.PRODUCE_ENABLED_ATTR_NAME, false);
+ final String produceInputExt= (weaveEnabled) ? weaveOutputExt : sourceInputExt;
+ final String produceOutputExt= resolveFormatExt(TexRweaveConfig.getFormat(
+ TexRweaveConfig.PRODUCE_OUTPUT_FORMATS, null,
+ config.getAttribute(TexRweaveConfig.PRODUCE_OUTPUT_FORMAT_ATTR_NAME, (String) null) ),
+ produceInputExt );
- if (config.getAttribute(TexTab.ATTR_BUILDTEX_TYPE, -2) > BUILDTEX_TYPE_DISABLED) {
- final String format= config.getAttribute(TexTab.ATTR_BUILDTEX_FORMAT, (String) null);
- if (format != null) {
- texDetail= " (TeX > " + format + ")"; //$NON-NLS-1$ //$NON-NLS-2$
- processDetail= " (Rnw > " + format + ")"; //$NON-NLS-1$ //$NON-NLS-2$
- }
+ if (weaveEnabled | produceEnabled) {
+ buildDetail= createDetail(
+ (weaveEnabled) ? weaveInputExt : produceInputExt,
+ (produceEnabled) ? produceOutputExt : weaveOutputExt );
}
- else {
- texDisabled= true;
- }
+ weaveDetail= createDetail(weaveInputExt, weaveOutputExt);
+ produceDetail= createDetail(produceInputExt, produceOutputExt);
} catch (final CoreException e) {
}
addLaunchItem(menu, CommonFlags.PROCESS_AND_PREVIEW, null, true,
DocProcessingUI.PROCESS_AND_PREVIEW_DOC_DEFAULT_COMMAND_ID,
DocProcessingUI.ACTIONS_RUN_CONFIG_HELP_CONTEXT_ID );
- addLaunchItem(menu, CommonFlags.PROCESS, processDetail, true,
+ addLaunchItem(menu, CommonFlags.PROCESS, buildDetail, (buildDetail != null),
DocProcessingUI.PROCESS_DOC_DEFAULT_COMMAND_ID,
DocProcessingUI.ACTIONS_RUN_CONFIG_PROCESS_HELP_CONTEXT_ID );
new MenuItem(menu, SWT.SEPARATOR);
- addLaunchItem(menu, CommonFlags.WEAVE, weaveDetail, !weaveDisabled,
+ addLaunchItem(menu, CommonFlags.WEAVE, weaveDetail, (weaveDetail != null),
RedocsRUI.PROCESS_WEAVE_DEFAULT_COMMAND_ID,
DocProcessingUI.ACTIONS_RUN_CONFIG_STEP_HELP_CONTEXT_ID );
- addLaunchItem(menu, CommonFlags.PRODUCE_OUTPUT, texDetail, !texDisabled,
+ addLaunchItem(menu, CommonFlags.PRODUCE_OUTPUT, produceDetail, (produceDetail != null),
PROCESS_TEX_COMMAND_ID,
DocProcessingUI.ACTIONS_RUN_CONFIG_STEP_HELP_CONTEXT_ID );
addLaunchItem(menu, CommonFlags.OPEN_OUTPUT, null, true,
@@ -102,7 +102,7 @@
public TexRweaveConfigsMenuContribution() {
- super(TexRweaveCore.LTX_R_CONTENT_TYPE);
+ super(); // use dynamically content type of editor
}
diff --git a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveLaunchDelegate.java b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveLaunchDelegate.java
index 352e97c..88ef8ca 100644
--- a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveLaunchDelegate.java
+++ b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveLaunchDelegate.java
@@ -15,106 +15,52 @@
package org.eclipse.statet.internal.redocs.tex.r.ui.processing;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
import java.util.Set;
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
-import org.eclipse.core.variables.IStringVariable;
-import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.debug.ui.IDebugUIConstants;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.texlipse.TexPathConfig;
-import org.eclipse.texlipse.Texlipse;
-import org.eclipse.texlipse.builder.Builder;
-import org.eclipse.texlipse.builder.BuilderRegistry;
-
-import org.eclipse.statet.ecommons.debug.core.util.OverlayLaunchConfiguration;
-import org.eclipse.statet.ecommons.io.FileValidator;
-import org.eclipse.statet.ecommons.variables.core.StringVariable;
-import org.eclipse.statet.ecommons.variables.core.VariableText;
import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingOperation;
import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingToolConfig;
import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingToolConfig.StepConfig;
import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingToolJob;
import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingToolLaunchDelegate;
+import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingToolProcess;
import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingUI;
-import org.eclipse.statet.r.cmd.ui.launching.RCmdLaunching;
-import org.eclipse.statet.r.launching.core.RLaunching;
-import org.eclipse.statet.r.launching.ui.REnvTab;
-import org.eclipse.statet.redocs.r.ui.processing.RWeaveDocProcessingConfig;
+import org.eclipse.statet.docmlet.base.ui.processing.operations.CloseInDocViewerOperation;
+import org.eclipse.statet.docmlet.base.ui.processing.operations.OpenUsingDocViewerOperation;
+import org.eclipse.statet.docmlet.base.ui.processing.operations.OpenUsingEclipseOperation;
+import org.eclipse.statet.docmlet.base.ui.processing.operations.RunExternalProgramOperation;
+import org.eclipse.statet.redocs.r.ui.processing.RunRCmdToolOperation;
+import org.eclipse.statet.redocs.r.ui.processing.RunRConsoleSnippetOperation;
import org.eclipse.statet.redocs.tex.r.ui.TexRweaveUI;
public class TexRweaveLaunchDelegate extends DocProcessingToolLaunchDelegate {
- public static final String VARNAME_SWEAVE_FILE= "source_file_path"; //$NON-NLS-1$
- public static final String VARNAME_LATEX_FILE= "latex_file_path"; //$NON-NLS-1$
- public static final String VARNAME_OUTPUT_FILE= "output_file_path"; //$NON-NLS-1$
-
- public static final IStringVariable VARIABLE_SWEAVE_FILE= new StringVariable(VARNAME_SWEAVE_FILE, "Returns the workspace relative path of the Sweave file.");
- public static final IStringVariable VARIABLE_LATEX_FILE= new StringVariable(VARNAME_LATEX_FILE, "Returns the workspace relative path of the LaTeX file.");
- public static final IStringVariable VARIABLE_OUTPUT_FILE= new StringVariable(VARNAME_OUTPUT_FILE, "Returns the workspace relative path of the output file.");
-
-
- public static final String SWEAVE_CONSOLE= "console"; //$NON-NLS-1$
- public static final String SWEAVE_LAUNCH= "cmdlaunch"; //$NON-NLS-1$
- public static final String DEFAULT_SWEAVE_R_COMMANDS= "Sweave(file= \"${resource_loc:${"+VARNAME_SWEAVE_FILE+"}}\")"; //$NON-NLS-1$ //$NON-NLS-2$
- public static final int SWEAVE_TYPE_DISABLED= 0;
- public static final int SWEAVE_TYPE_RCMD= 1;
- public static final int SWEAVE_TYPE_RCONSOLE= 2;
-
- public static final int BUILDTEX_TYPE_DISABLED= 0;
- public static final int BUILDTEX_TYPE_ECLIPSE= 1;
- public static final int BUILDTEX_TYPE_RCONSOLE= 2;
- public static final int DEFAULT_BUILDTEX_TYPE= BUILDTEX_TYPE_ECLIPSE;
-
- public static final String DEFAULT_BUILDTEX_R_COMMANDS= "require(tools)\ntexi2dvi(file= \"${resource_loc:${"+VARNAME_LATEX_FILE+"}}\", pdf= TRUE)"; //$NON-NLS-1$ //$NON-NLS-2$
- public static final String DEFAULT_BUILDTEX_FORMAT= "pdf"; //$NON-NLS-1$
-
- public static final String PREVIEW_IDE= "ide"; //$NON-NLS-1$
- public static final String PREVIEW_SPECIAL= "tex"; //$NON-NLS-1$
-
-
static class Config extends DocProcessingToolConfig {
-// protected static class WeaveStepConfig extends StepConfig {
-//
-//
-// public WeaveStepConfig(final DocProcessingToolConfig config) {
-// super(config, TexRweaveConfig.WEAVE_ATTR_QUALIFIER, Messages.WeaveTab_label);
-// }
-//
-//
-// @Override
-// public void initPost(final ILaunchConfiguration configuration,
-// final SubMonitor m) throws CoreException {
-// if (isPostOpen(configuration.getAttribute(
-// TexRweaveConfig.WEAVE_OPEN_RESULT_ATTR_NAME, "" ))) { //$NON-NLS-1$
-//// addPost();
-// }
-// }
-//
-// }
-
-
- public final StepConfig weave= new StepConfig(this,
- RWeaveDocProcessingConfig.WEAVE_ATTR_QUALIFIER, Messages.Weave_label );
- public final StepConfig produce= new StepConfig(this,
- RWeaveDocProcessingConfig.PRODUCE_ATTR_QUALIFIER, Messages.Produce_label );
+ public final StepConfig weave= new ProcessingStepConfig(this,
+ TexRweaveConfig.WEAVE_ATTR_QUALIFIER, Messages.Weave_label );
+ public final StepConfig produce= new ProcessingStepConfig(this,
+ TexRweaveConfig.PRODUCE_ATTR_QUALIFIER, Messages.Produce_label ) {
+ @Override
+ public void initPre(final ILaunchConfiguration configuration,
+ final SubMonitor m) throws CoreException {
+ { final CloseInDocViewerOperation operation= new CloseInDocViewerOperation();
+ operation.init(this, Collections.emptyMap(), m);
+ addPre(operation);
+ }
+ }
+ };
public final StepConfig preview= new PreviewStepConfig(this);
@@ -129,7 +75,7 @@
byte runPreview= 0;
final Set<String> steps= configuration.getAttribute(
- DocProcessingUI.RUN_STEPS_ATTR_NAME, Collections.EMPTY_SET );
+ DocProcessingUI.RUN_STEPS_ATTR_NAME, Collections.<String>emptySet() );
if (steps.isEmpty()) {
runWeave= StepConfig.RUN_DEFAULT;
runProduce= StepConfig.RUN_DEFAULT;
@@ -166,6 +112,21 @@
@Override
protected DocProcessingOperation createStepOperation(final String id) {
+ if (id.equals(RunRConsoleSnippetOperation.ID)) {
+ return new RunRConsoleSnippetOperation();
+ }
+ if (id.equals(RunRCmdToolOperation.ID)) {
+ return new RunRCmdToolOperation();
+ }
+ if (id.equals(RunExternalProgramOperation.ID)) {
+ return new RunExternalProgramOperation();
+ }
+ if (id.equals(OpenUsingDocViewerOperation.ID)) {
+ return new OpenUsingDocViewerOperation();
+ }
+ if (id.equals(OpenUsingEclipseOperation.ID)) {
+ return new OpenUsingEclipseOperation();
+ }
return null;
}
@@ -178,7 +139,8 @@
@Override
public void launch(final ILaunchConfiguration configuration, final String mode,
- final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
+ final ILaunch launch,
+ final IProgressMonitor monitor) throws CoreException {
final Config config= new Config();
if (!config.initRun(configuration)) {
return; // nothing to do
@@ -188,100 +150,62 @@
((config.preview.getRun() == StepConfig.RUN_EXPLICITE) ? 30 : 0) );
try {
{ final SubMonitor m1= m.newChild(10);
- config.initSourceFile(configuration, m1);
- }
-
- final TexRweaveProcessToolProcess toolProcess= new TexRweaveProcessToolProcess(launch, config);
-
- // Tex config (for output format, before sweave)
- { toolProcess.fTexOpenEditor= configuration.getAttribute(TexTab.ATTR_OPENTEX_ENABLED, TexTab.OPEN_OFF);
+ final boolean weaveRequired= (config.weave.isRun() || config.weave.isEnabled());
+ final boolean produceRequired= (config.produce.isRun() || config.preview.isRun());
+ final boolean previewRequired= (config.produce.isRun() || config.preview.isRun()); // also used by pre produce operation
+ m1.setWorkRemaining(2 + 1 +
+ ((weaveRequired) ? 2 : 0) +
+ ((produceRequired) ? 2 : 0) +
+ ((previewRequired) ? 1 : 0) );
- final VariableText outputDir= new VariableText(
- replaceOldVariables(configuration.getAttribute(TexTab.ATTR_BUILDTEX_OUTPUTDIR, "")), //$NON-NLS-1$
- TexRweaveProcessToolProcess.OUTPUT_DIR_VARNAMES);
- final String outputFormat;
+ config.initSourceFile(configuration, m1.newChild(2));
+ config.initWorkingDirectory(configuration, m1.newChild(1));
- int texType= configuration.getAttribute(TexTab.ATTR_BUILDTEX_TYPE, -2);
- if (texType == -2) {
- texType= configuration.getAttribute(TexTab.ATTR_BUILDTEX_ENABLED, false) ? BUILDTEX_TYPE_ECLIPSE : BUILDTEX_TYPE_DISABLED;
+ if (weaveRequired) {
+ final IFile inputFile= config.getSourceFile();
+ config.weave.initIOFiles(inputFile, configuration, m1.newChild(2));
}
- switch (texType) {
- case BUILDTEX_TYPE_ECLIPSE:
- final Builder builder= BuilderRegistry.get(configuration.getAttribute(TexTab.ATTR_BUILDTEX_ECLIPSE_BUILDERID, -1));
- toolProcess.setBuildTex(builder);
- outputFormat= (builder != null) ? builder.getOutputFormat() : null;
- break;
- case BUILDTEX_TYPE_RCONSOLE:
- toolProcess.setBuildTex(new VariableText(
- configuration.getAttribute(TexTab.ATTR_BUILDTEX_R_COMMANDS, ""), //$NON-NLS-1$
- TexRweaveProcessToolProcess.TEX_COMMAND_VARNAMES) );
- //$FALL-THROUGH$
- default:
- outputFormat= configuration.getAttribute(TexTab.ATTR_BUILDTEX_FORMAT, ""); //$NON-NLS-1$
+ if (produceRequired) {
+ final IFile inputFile= (config.weave.isEnabled()) ?
+ config.weave.getOutputFile() : config.getSourceFile();
+ config.produce.initIOFiles(inputFile, configuration, m1.newChild(2));
}
- toolProcess.setOutput(outputDir, outputFormat);
- }
- m.newChild(10);
- // Sweave config
- { final String sweaveFolderRaw= configuration.getAttribute(RweaveTab.ATTR_SWEAVE_FOLDER, ""); //$NON-NLS-1$
- if (!sweaveFolderRaw.isEmpty()) {
- toolProcess.setWorkingDir(new VariableText(sweaveFolderRaw,
- TexRweaveProcessToolProcess.SWEAVE_FOLDER_VARNAMES ));
- }
-
- final String sweaveProcessing= configuration.getAttribute(RweaveTab.ATTR_SWEAVE_ID, ""); //$NON-NLS-1$
- if (sweaveProcessing.startsWith(TexRweaveLaunchDelegate.SWEAVE_LAUNCH)) {
- final String[] split= sweaveProcessing.split(":", 2); //$NON-NLS-1$
- final String sweaveConfigName= (split.length == 2) ? split[1] : ""; //$NON-NLS-1$
-
- final Map<String, Object> attributes= new HashMap<>();
- attributes.put(RCmdLaunching.R_CMD_RESOURCE_ATTR_NAME, config.getSourceFile().getLocation().toOSString());
- attributes.put(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, false);
-
- final ILaunchConfiguration sweaveConfig= getRCmdSweaveConfig(sweaveConfigName, attributes);
- if (sweaveConfig == null && config.weave.isRun()) {
- throw new CoreException(new Status(IStatus.ERROR, TexRweaveUI.BUNDLE_ID, 0,
- NLS.bind(Messages.ProcessingConfig_error_MissingRCmdConfig_message, sweaveConfigName), null));
- }
- toolProcess.setSweave(sweaveConfig);
-
- IFileStore wd= toolProcess.getWorkingDirectory();
- if (wd == null) {
- final FileValidator workingDirectory= REnvTab.getWorkingDirectoryValidator(sweaveConfig, true);
- final IStatus status= toolProcess.setWorkingDir(workingDirectory.getFileStore(), (IContainer) workingDirectory.getWorkspaceResource(), false);
- if (status.getSeverity() >= IStatus.ERROR && config.weave.isRun()) {
- throw new CoreException(status);
- }
- wd= workingDirectory.getFileStore();
- }
- attributes.put(RLaunching.ATTR_WORKING_DIRECTORY, wd.toURI().toString());
- }
- else if (sweaveProcessing.startsWith(TexRweaveLaunchDelegate.SWEAVE_CONSOLE)) {
- final String[] split= sweaveProcessing.split(":", 2); //$NON-NLS-1$
- toolProcess.setSweave(new VariableText(
- (split.length == 2 && split[1].length() > 0) ? replaceOldVariables(split[1]) : DEFAULT_SWEAVE_R_COMMANDS,
- TexRweaveProcessToolProcess.SWEAVE_COMMAND_VARNAMES) );
- }
- else if (toolProcess.getWorkingDirectory() == null) {
- toolProcess.setWorkingDir(null, config.getSourceFile().getParent(), true);
+ if (previewRequired) {
+ final IFile inputFile= config.produce.getOutputFile();
+ config.preview.initIOFiles(inputFile, configuration, m1.newChild(1));
}
}
- // Preview config
- { final String preview= configuration.getAttribute(PreviewTab.ATTR_VIEWER_CODE, ""); //$NON-NLS-1$
+ if (m.isCanceled()) {
+ return;
+ }
+
+ { final SubMonitor m1= m.newChild(10);
+ m1.setWorkRemaining(
+ ((config.weave.isRun()) ? 3 : 0) +
+ ((config.produce.isRun()) ? 4 : 0) +
+ ((config.preview.isRun()) ? 2 : 0) );
+
if (config.weave.isRun()) {
- if (preview.startsWith(PREVIEW_SPECIAL)) {
- final String previewConfigName= preview.split(":", -1)[1]; //$NON-NLS-1$
- toolProcess.fPreviewConfig= Texlipse.getViewerManager().getConfiguration(previewConfigName);
- if (toolProcess.fPreviewConfig == null) {
- throw new CoreException(new Status(IStatus.ERROR, TexRweaveUI.BUNDLE_ID, 0,
- NLS.bind(Messages.ProcessingConfig_error_MissingViewerConfig_message, previewConfigName),
- null ));
- }
- }
+ config.weave.initOperation(configuration, m1.newChild(2));
+ config.weave.initPost(configuration, m1.newChild(1));
+ }
+ if (config.produce.isRun()) {
+ config.produce.initPre(configuration, m1.newChild(1));
+ config.produce.initOperation(configuration, m1.newChild(2));
+ config.produce.initPost(configuration, m1.newChild(1));
+ }
+ if (config.preview.isRun()) {
+ config.preview.initOperation(configuration, m1.newChild(2));
}
}
+ if (m.isCanceled()) {
+ return;
+ }
+
+ final DocProcessingToolProcess toolProcess= new DocProcessingToolProcess(launch, config);
+
if (config.preview.getRun() == StepConfig.RUN_EXPLICITE) {
final IStatus status= toolProcess.run(m.newChild(30, SubMonitor.SUPPRESS_NONE));
if (status.getSeverity() == IStatus.ERROR) {
@@ -297,29 +221,4 @@
}
}
-
- private OverlayLaunchConfiguration getRCmdSweaveConfig(final String name, final Map<String, Object> attributes) throws CoreException {
- final ILaunchManager launchManager= DebugPlugin.getDefault().getLaunchManager();
- final ILaunchConfigurationType launchType= launchManager.getLaunchConfigurationType(RCmdLaunching.R_CMD_CONFIGURATION_TYPE_ID); //$NON-NLS-1
- final ILaunchConfiguration[] launchConfigurations= launchManager.getLaunchConfigurations(launchType);
-
- if (name != null && name.length() > 0) {
- for (final ILaunchConfiguration config : launchConfigurations) {
- if (config.getName().equals(name)) {
- return new OverlayLaunchConfiguration(config, attributes);
- }
- }
- }
- return null;
- }
-
- private String replaceOldVariables(String text) {
- text= text.replace(TexPathConfig.SOURCEFILE_LOC_VARIABLE, "${resource_loc:${"+VARNAME_SWEAVE_FILE+"}}"); //$NON-NLS-1$ //$NON-NLS-2$
- text= text.replace(TexPathConfig.SOURCEFILE_PATH_VARIABLE, "${"+VARNAME_SWEAVE_FILE+"}"); //$NON-NLS-1$ //$NON-NLS-2$
- text= text.replace(TexPathConfig.TEXFILE_LOC_VARIABLE, "${resource_loc:${"+VARNAME_LATEX_FILE+"}}"); //$NON-NLS-1$ //$NON-NLS-2$
- text= text.replace(TexPathConfig.TEXFILE_PATH_VARIABLE, "${"+VARNAME_LATEX_FILE+"}"); //$NON-NLS-1$ //$NON-NLS-2$
- return text;
- }
-
-
}
diff --git a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveProcessToolProcess.java b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveProcessToolProcess.java
deleted file mode 100644
index 426fb63..0000000
--- a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexRweaveProcessToolProcess.java
+++ /dev/null
@@ -1,901 +0,0 @@
-/*=============================================================================#
- # Copyright (c) 2008, 2018 Stephan Wahlbrink and others.
- #
- # This program and the accompanying materials are made available under the
- # terms of the Eclipse Public License 2.0 which is available at
- # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
- # which is available at https://www.apache.org/licenses/LICENSE-2.0.
- #
- # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
- #
- # Contributors:
- # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
- #=============================================================================*/
-
-package org.eclipse.statet.internal.redocs.tex.r.ui.processing;
-
-import static org.eclipse.statet.docmlet.base.ui.processing.DocProcessingOperation.NO_SETTINGS;
-import static org.eclipse.statet.docmlet.base.ui.processing.DocProcessingToolConfig.StepConfig.RUN_DEFAULT;
-import static org.eclipse.statet.docmlet.base.ui.processing.DocProcessingToolConfig.StepConfig.RUN_EXPLICITE;
-import static org.eclipse.statet.internal.redocs.tex.r.ui.processing.TexRweaveLaunchDelegate.BUILDTEX_TYPE_ECLIPSE;
-import static org.eclipse.statet.internal.redocs.tex.r.ui.processing.TexRweaveLaunchDelegate.BUILDTEX_TYPE_RCONSOLE;
-import static org.eclipse.statet.internal.redocs.tex.r.ui.processing.TexRweaveLaunchDelegate.SWEAVE_TYPE_RCMD;
-import static org.eclipse.statet.internal.redocs.tex.r.ui.processing.TexRweaveLaunchDelegate.SWEAVE_TYPE_RCONSOLE;
-import static org.eclipse.statet.internal.redocs.tex.r.ui.processing.TexRweaveLaunchDelegate.VARNAME_LATEX_FILE;
-import static org.eclipse.statet.internal.redocs.tex.r.ui.processing.TexRweaveLaunchDelegate.VARNAME_OUTPUT_FILE;
-import static org.eclipse.statet.internal.redocs.tex.r.ui.processing.TexRweaveLaunchDelegate.VARNAME_SWEAVE_FILE;
-
-import java.util.concurrent.Callable;
-
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceRuleFactory;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubMonitor;
-import org.eclipse.core.runtime.jobs.ISchedulingRule;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.debug.core.DebugException;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.texlipse.TexPathConfig;
-import org.eclipse.texlipse.Texlipse;
-import org.eclipse.texlipse.builder.AbstractBuilder;
-import org.eclipse.texlipse.builder.Builder;
-import org.eclipse.texlipse.builder.TexlipseBuilder;
-import org.eclipse.texlipse.viewer.ViewerConfiguration;
-import org.eclipse.ui.statushandlers.StatusManager;
-
-import org.eclipse.statet.jcommons.collections.ImCollections;
-import org.eclipse.statet.jcommons.collections.ImList;
-
-import org.eclipse.statet.ecommons.debug.core.util.LaunchUtils;
-import org.eclipse.statet.ecommons.io.FileUtil;
-import org.eclipse.statet.ecommons.io.FileValidator;
-import org.eclipse.statet.ecommons.ts.core.Tool;
-import org.eclipse.statet.ecommons.ts.core.ToolRunnable;
-import org.eclipse.statet.ecommons.ts.core.ToolService;
-import org.eclipse.statet.ecommons.variables.core.VariableText;
-import org.eclipse.statet.ecommons.variables.core.VariableText.LocationProcessor;
-
-import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingToolProcess;
-import org.eclipse.statet.docmlet.base.ui.processing.operations.OpenUsingEclipseOperation;
-import org.eclipse.statet.internal.redocs.tex.r.ui.processing.TexRweaveLaunchDelegate.Config;
-import org.eclipse.statet.nico.core.runtime.IRequireSynch;
-import org.eclipse.statet.nico.core.runtime.ToolProcess;
-import org.eclipse.statet.nico.core.runtime.ToolWorkspace;
-import org.eclipse.statet.nico.ui.NicoUI;
-import org.eclipse.statet.nico.ui.NicoUITools;
-import org.eclipse.statet.r.console.core.IRBasicAdapter;
-import org.eclipse.statet.r.console.core.RConsoleTool;
-import org.eclipse.statet.r.core.RUtil;
-import org.eclipse.statet.redocs.tex.r.ui.TexRweaveUI;
-import org.eclipse.statet.rj.services.RServiceControlExtension;
-
-
-class TexRweaveProcessToolProcess extends DocProcessingToolProcess {
-
-
- private static final int TICKS_PREPARER= 5;
- private static final int TICKS_RWEAVE= 30;
- private static final int TICKS_TEX= 30;
- private static final int TICKS_OPEN_TEX= 5;
- private static final int TICKS_OPEN_OUTPUT= 20;
- private static final int TICKS_REST= 10;
-
-
- public static final ImList<String> SWEAVE_FOLDER_VARNAMES= ImCollections.newList(
- VARNAME_SWEAVE_FILE );
- public static final ImList<String> SWEAVE_COMMAND_VARNAMES= ImCollections.newList(
- VARNAME_SWEAVE_FILE, VARNAME_LATEX_FILE, VARNAME_OUTPUT_FILE );
- public static final ImList<String> OUTPUT_DIR_VARNAMES= ImCollections.newList(
- VARNAME_SWEAVE_FILE, VARNAME_LATEX_FILE );
- public static final ImList<String> TEX_COMMAND_VARNAMES= ImCollections.newList(
- VARNAME_SWEAVE_FILE, VARNAME_LATEX_FILE, VARNAME_OUTPUT_FILE );
-
-
- private class R implements ToolRunnable {
-
-
- public static final int TASK_FINISHED= 1;
- public static final int TASK_PREPARE_TEX= 2;
-
- private int task= 0;
-
-
- R() {
- }
-
- @Override
- public String getTypeId() {
- return "r/sweave/commands"; //$NON-NLS-1$
- }
-
- @Override
- public boolean canRunIn(final Tool tool) {
- return (tool.isProvidingFeatureSet(RConsoleTool.R_BASIC_FEATURESET_ID));
- }
-
- @Override
- public String getLabel() {
- return NLS.bind(Messages.RweaveTexProcessing_Sweave_Task_label, getConfig().getSourceFile().getName());
- }
-
- @Override
- public boolean changed(final int event, final Tool tool) {
- switch (event) {
- case REMOVING_FROM:
- case BEING_ABANDONED:
- getStatus().add(new Status(IStatus.CANCEL, TexRweaveUI.BUNDLE_ID, -1,
- Messages.RweaveTexProcessing_Sweave_Task_info_Canceled_message, null));
- continueAfterR();
- break;
- // finishing handled in run
- }
- return true;
- }
-
- @Override
- public void run(final ToolService service,
- final IProgressMonitor monitor) throws CoreException {
- final IRBasicAdapter r= (IRBasicAdapter) service;
- TexRweaveProcessToolProcess.this.fProgress2= monitor;
- Callable<Boolean> cancel= null;
- if (r instanceof RServiceControlExtension) {
- cancel= new Callable<Boolean>() {
- @Override
- public Boolean call() throws Exception {
- terminate();
- return Boolean.FALSE;
- }
- };
- ((RServiceControlExtension) r).addCancelHandler(cancel);
- }
- try {
- if (checkExit(0)) {
- return;
- }
-
- final ToolWorkspace workspace= r.getWorkspaceData();
- if (TexRweaveProcessToolProcess.this.fWorkingFolder == null) {
- r.refreshWorkspaceData(0, monitor);
- updatePathInformations(r.getWorkspaceData());
- }
- else {
- String path= workspace.toToolPath(TexRweaveProcessToolProcess.this.fWorkingFolder);
- path= RUtil.escapeBackslash(path);
- r.submitToConsole("setwd(\""+path+"\")", monitor); //$NON-NLS-1$ //$NON-NLS-2$
- r.refreshWorkspaceData(0, monitor);
- if (!TexRweaveProcessToolProcess.this.fWorkingFolder.equals(workspace.getWorkspaceDir())) {
- getStatus().add(new Status(IStatus.ERROR, TexRweaveUI.BUNDLE_ID,
- "Failed to set the R working directory." ));
- }
- }
-
- if (checkExit(0)) {
- return;
- }
-
- final LocationProcessor processor= new LocationProcessor() {
- @Override
- public String process(String path) throws CoreException {
- final IFileStore store= FileUtil.getFileStore(path);
- path= workspace.toToolPath(store);
- path= RUtil.escapeBackslash(path);
- return path;
- }
- };
-
- if (getConfig().weave.isRun() && TexRweaveProcessToolProcess.this.fSweaveType == SWEAVE_TYPE_RCONSOLE) {
- monitor.subTask("Sweave"); //$NON-NLS-1$
- final SubMonitor progress= TexRweaveProcessToolProcess.this.fProgress.newChild(TICKS_RWEAVE);
- progress.beginTask(Messages.RweaveTexProcessing_Sweave_InConsole_label, 100);
-
- try {
- TexRweaveProcessToolProcess.this.fSweaveRCommands.set(VARNAME_SWEAVE_FILE, getConfig().getSourceFile().getFullPath().toString());
- TexRweaveProcessToolProcess.this.fSweaveRCommands.set(VARNAME_LATEX_FILE, TexRweaveProcessToolProcess.this.fTexFile.getFullPath().toString());
- TexRweaveProcessToolProcess.this.fSweaveRCommands.set(VARNAME_OUTPUT_FILE, TexRweaveProcessToolProcess.this.fTexPathConfig.getOutputFile().getFullPath().toString());
- TexRweaveProcessToolProcess.this.fSweaveRCommands.performFinalStringSubstitution(processor);
- }
- catch (final NullPointerException e) {
- throw new CoreException(new Status(IStatus.ERROR, TexRweaveUI.BUNDLE_ID,
- Messages.RweaveTexProcessing_Sweave_error_ResourceVariable_message));
- }
- catch (final CoreException e) {
- throw new CoreException(new Status(IStatus.ERROR, TexRweaveUI.BUNDLE_ID,
- Messages.RweaveTexProcessing_Sweave_error_ResourceVariable_message + ' ' + e.getLocalizedMessage()));
- }
- final String[] commands= RUtil.LINE_SEPARATOR_PATTERN.split(TexRweaveProcessToolProcess.this.fSweaveRCommands.getText());
- for (int i= 0; i < commands.length; i++) {
- r.submitToConsole(commands[i], monitor);
- }
- if (r instanceof IRequireSynch) {
- ((IRequireSynch) r).synch(monitor);
- }
- }
-
- if (getConfig().produce.isRun() && TexRweaveProcessToolProcess.this.fTexType == BUILDTEX_TYPE_RCONSOLE) {
- monitor.subTask("LaTeX"); //$NON-NLS-1$
- if (checkExit(0)) {
- return;
- }
-
- waitTask(TASK_PREPARE_TEX);
- if (checkExit(0) || this.task < 0) {
- return;
- }
-
- final SubMonitor progress= TexRweaveProcessToolProcess.this.fProgress.newChild(TICKS_TEX);
- progress.beginTask(Messages.RweaveTexProcessing_Tex_label, 100);
-
- try {
- TexRweaveProcessToolProcess.this.fTexRCommands.set(VARNAME_SWEAVE_FILE, getConfig().getSourceFile().getFullPath().toString());
- TexRweaveProcessToolProcess.this.fTexRCommands.set(VARNAME_LATEX_FILE, TexRweaveProcessToolProcess.this.fTexFile.getFullPath().toString());
- TexRweaveProcessToolProcess.this.fTexRCommands.set(VARNAME_OUTPUT_FILE, TexRweaveProcessToolProcess.this.fTexPathConfig.getOutputFile().getFullPath().toString());
- TexRweaveProcessToolProcess.this.fTexRCommands.performFinalStringSubstitution(processor);
- progress.setWorkRemaining(90);
- }
- catch (final NullPointerException e) {
- throw new CoreException(new Status(IStatus.ERROR, TexRweaveUI.BUNDLE_ID,
- Messages.RweaveTexProcessing_Tex_error_ResourceVariable_message));
- }
- catch (final CoreException e) {
- throw new CoreException(new Status(IStatus.ERROR, TexRweaveUI.BUNDLE_ID,
- Messages.RweaveTexProcessing_Tex_error_ResourceVariable_message + ' ' + e.getLocalizedMessage()));
- }
-
- Texlipse.getViewerManager().closeDocInViewer(TexRweaveProcessToolProcess.this.fTexPathConfig);
-
- final String[] commands= RUtil.LINE_SEPARATOR_PATTERN.split(TexRweaveProcessToolProcess.this.fTexRCommands.getText());
- for (int i= 0; i < commands.length; i++) {
- r.submitToConsole(commands[i], monitor);
- progress.setWorkRemaining(90-80/commands.length*(i+1));
- }
- if (r instanceof IRequireSynch) {
- ((IRequireSynch) r).synch(monitor);
- }
- }
- }
- catch (final CoreException e) {
- getStatus().add(e.getStatus());
- throw e;
- }
- finally {
- if (cancel != null) {
- ((RServiceControlExtension) r).removeCancelHandler(cancel);
- cancel= null;
- }
- continueAfterR();
- TexRweaveProcessToolProcess.this.fProgress2= null;
- }
-
- }
-
- private void updatePathInformations(final ToolWorkspace workspace) {
- final IFileStore wd= workspace.getWorkspaceDir();
- final IStatus status= setWorkingDir(wd, null, true);
- if (status.getSeverity() > IStatus.OK) {
- getStatus().add(status);
- }
- }
-
- private synchronized void waitTask(final int task) {
- this.task= task;
- while (this.task == task) {
- notifyAll();
- try {
- this.wait();
- }
- catch (final InterruptedException e) {
- }
- }
- }
-
- private synchronized void continueAfterR() {
- this.task= TASK_FINISHED;
- notifyAll();
- }
-
- }
-
- private SubMonitor fProgress;
- private IProgressMonitor fProgress2;
-
- private IContainer fWorkingFolderInWorkspace;
- private IFileStore fWorkingFolder;
- private String fBaseFileName;
- private String fTexFileExtension;
-
- private int fSweaveType;
- private VariableText fSweaveRCommands;
- private ILaunchConfiguration fSweaveConfig;
-
- private String fOutputFormat;
- private VariableText fOutputDir;
- private boolean fOutputInitialized;
-
- private IFile fTexFile;
- int fTexOpenEditor= 0;
- private int fTexType;
- private Builder fTexBuilder;
- private VariableText fTexRCommands;
- private TexPathConfig fTexPathConfig;
-
- ViewerConfiguration fPreviewConfig;
-
-
- public TexRweaveProcessToolProcess(final ILaunch launch, final TexRweaveLaunchDelegate.Config config) {
- super(launch, config);
- }
-
-
- @Override
- public TexRweaveLaunchDelegate.Config getConfig() {
- return (TexRweaveLaunchDelegate.Config) super.getConfig();
- }
-
- public void setWorkingDir(final VariableText wd) throws CoreException {
- wd.performInitialStringSubstitution(true);
- wd.set(VARNAME_SWEAVE_FILE, getConfig().getSourceFile().getFullPath().toString());
- wd.performFinalStringSubstitution(null);
-
- final FileValidator validator= new FileValidator(false);
- validator.setResourceLabel("Sweave Working / Output Folder");
- validator.setOnFile(IStatus.ERROR);
- validator.setOnExisting(IStatus.OK);
- validator.setOnNotExisting(IStatus.ERROR);
- validator.setRequireWorkspace(true, true);
- { final IStatus status= validator.validate(wd.getText());
- if (!status.isOK()) {
- throw new CoreException(status);
- }
- }
- { final IStatus status= setWorkingDir(null, (IContainer) validator.getWorkspaceResource(), true);
- if (!status.isOK()) {
- throw new CoreException(status);
- }
- }
- }
-
- public void setSweave(final VariableText rCommands) throws CoreException {
- if (this.fSweaveType > 0 || rCommands == null) {
- throw new IllegalArgumentException();
- }
- this.fSweaveType= SWEAVE_TYPE_RCONSOLE;
- this.fSweaveRCommands= rCommands;
- this.fSweaveRCommands.performInitialStringSubstitution(true);
- }
-
- public void setSweave(final ILaunchConfiguration rCmd) {
- if (this.fSweaveType > 0 || rCmd == null) {
- throw new IllegalArgumentException();
- }
- this.fSweaveType= SWEAVE_TYPE_RCMD;
- this.fSweaveConfig= rCmd;
- }
-
- public void setOutput(final VariableText directory, final String format) throws CoreException {
- this.fOutputDir= directory;
- this.fOutputDir.performInitialStringSubstitution(true);
- this.fOutputFormat= format;
-
- if (this.fWorkingFolder != null && !this.fOutputInitialized) {
- final IStatus status= initOutputDir();
- if (!status.isOK()) {
- throw new CoreException(status);
- }
- }
- }
-
- public void setBuildTex(final VariableText commands) throws CoreException {
- if (this.fTexType > 0 || commands == null) {
- throw new IllegalArgumentException();
- }
- this.fTexType= BUILDTEX_TYPE_RCONSOLE;
- this.fTexRCommands= commands;
- this.fTexRCommands.performInitialStringSubstitution(true);
- }
-
- public void setBuildTex(final Builder texBuilder) {
- if (this.fTexType > 0 || texBuilder == null) {
- throw new IllegalArgumentException();
- }
- this.fTexType= BUILDTEX_TYPE_ECLIPSE;
- this.fTexBuilder= texBuilder;
- }
-
-
- public IStatus setWorkingDir(final IFileStore efsFolder, final IContainer workspaceFolder, final boolean synch) {
- this.fWorkingFolder= efsFolder;
- this.fWorkingFolderInWorkspace= workspaceFolder;
- if (synch) {
- if (this.fWorkingFolder == null && this.fWorkingFolderInWorkspace != null) {
- this.fWorkingFolder= EFS.getLocalFileSystem().getStore(this.fWorkingFolderInWorkspace.getLocation());
- }
- else if (this.fWorkingFolder != null && this.fWorkingFolderInWorkspace == null) {
- final IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
- final IContainer[] found= root.findContainersForLocationURI(this.fWorkingFolder.toURI());
- for (int i= 0; i < found.length; i++) {
- if (found[i].getType() == IResource.PROJECT || found[i].getType() == IResource.FOLDER) {
- this.fWorkingFolderInWorkspace= found[i];
- break;
- }
- }
- }
- }
- if (this.fWorkingFolderInWorkspace == null) {
- doSetExitValue(11);
- return new Status(IStatus.ERROR, TexRweaveUI.BUNDLE_ID, -1,
- Messages.RweaveTexProcessing_Tex_error_MustBeInWorkspace_message, null);
- }
-
- if (this.fBaseFileName == null) {
- this.fBaseFileName= getConfig().getSourceFile().getName();
- final int idx= this.fBaseFileName.lastIndexOf('.');
- if (idx >= 0) {
- this.fBaseFileName= this.fBaseFileName.substring(0, idx);
- }
- }
-
- if (this.fTexFileExtension == null) {
- this.fTexFileExtension= "tex"; //$NON-NLS-1$
- }
- this.fTexFile= this.fWorkingFolderInWorkspace.getFile(new Path(this.fBaseFileName + '.' + this.fTexFileExtension));
-
- if (this.fOutputDir != null && !this.fOutputInitialized) {
- return initOutputDir();
- }
- return Status.OK_STATUS;
- }
-
- private IStatus initOutputDir() {
- this.fOutputInitialized= true;
- final String texFilePath= this.fTexFile.getFullPath().toString();
- this.fOutputDir.set(VARNAME_SWEAVE_FILE, getConfig().getSourceFile().getFullPath().toString());
- this.fOutputDir.set(VARNAME_LATEX_FILE, texFilePath);
-
- // 21x
- if (this.fOutputFormat == null) {
- return new Status(IStatus.ERROR, TexRweaveUI.BUNDLE_ID, -1,
- Messages.RweaveTexProcessing_Tex_error_BuilderNotConfigured_message, null );
- }
- final IContainer outputDir;
- try {
- outputDir= TexPathConfig.resolveDirectory(this.fOutputDir.getText(), this.fTexFile, getConfig().getSourceFile());
- }
- catch (final CoreException e) {
- return new Status(IStatus.ERROR, TexRweaveUI.BUNDLE_ID, -1,
- Messages.RweaveTexProcessing_Tex_error_OutputDir_message, e );
- }
- this.fTexPathConfig= new TexPathConfig(this.fTexFile, outputDir, this.fOutputFormat);
-
- return Status.OK_STATUS;
- }
-
- public IFileStore getWorkingDirectory() {
- return this.fWorkingFolder;
- }
-
-
- @Override
- protected void runProcessing(final SubMonitor m) {
- this.fProgress= m;
-
- if (checkExit(0)) {
- return;
- }
-
- doWeave();
- if (checkExit(0)) {
- return;
- }
-
- if (!this.fOutputInitialized) {
- final IStatus status= initOutputDir();
- if (!status.isOK()) {
- getStatus().add(status);
- }
- }
- if (checkExit(0)) {
- return;
- }
-
- if (getConfig().produce.isRun() && this.fTexType == BUILDTEX_TYPE_RCONSOLE) {
- finallyTex(this.fProgress.newChild(1));
- }
- else {
- doPrepareTex();
- if (checkExit(0)) {
- return;
- }
-
- doProcessTex();
- if (checkExit(0)) {
- return;
- }
- }
-
- doOpenOutput();
-
- this.fProgress.done();
- }
-
- @Override
- protected int calculateTicks() {
- final Config config= getConfig();
- int sum= 0;
- if (config.weave.isRun()) {
- sum += TICKS_RWEAVE;
- }
- else {
- sum += TICKS_RWEAVE/10;
- }
- if (this.fTexOpenEditor >= TexTab.OPEN_ALWAYS) {
- sum += TICKS_OPEN_TEX;
- }
- if (config.produce.isRun()) {
- sum += TICKS_TEX;
- }
- if (config.preview.isRun()) {
- sum += TICKS_OPEN_OUTPUT;
- }
- sum += TICKS_REST;
-
- return sum;
- }
-
-
- @Override
- protected void runFinished() {
- super.runFinished();
-
- this.fProgress= null;
-
- if (getStatus().getSeverity() > IStatus.OK) {
- if (getStatus().getSeverity() == IStatus.ERROR) {
- StatusManager.getManager().handle(getStatus(), StatusManager.LOG | StatusManager.SHOW);
- return;
- }
- StatusManager.getManager().handle(getStatus(), StatusManager.LOG);
- }
- }
-
-
- private void doWeave() { // 1xx
- final Config config= getConfig();
- if (this.fSweaveType == SWEAVE_TYPE_RCONSOLE || this.fTexType == BUILDTEX_TYPE_RCONSOLE) { // 11x
- if (!(config.weave.isRun() || config.produce.isRun()) && this.fWorkingFolder != null) {
- return;
- }
- try {
- // RCodeLaunchRegistry.runRCodeDirect(RUtil.LINE_SEPARATOR_PATTERN.split(fSweaveCommands), false);
- final ToolProcess rProcess= NicoUI.getToolRegistry().getActiveToolSession(
- getConfig().getWorkbenchPage() ).getProcess();
- if (rProcess == null) {
- NicoUITools.accessTool(RConsoleTool.TYPE, rProcess); // throws CoreException
- }
-
- final R rTask= new R();
- if (config.weave.isRun() || config.produce.isRun()) {
- this.fProgress.worked(TICKS_PREPARER);
-
- final IStatus submitStatus= rProcess.getQueue().add(rTask);
- if (submitStatus.getSeverity() > IStatus.OK) {
- getStatus().add(submitStatus);
- if (checkExit(112)) {
- return;
- }
- }
- RTASK: while (true) {
- synchronized (rTask) {
- boolean ok= false;
- try {
- rTask.notifyAll();
- if (rTask.task != R.TASK_FINISHED && checkExit(0)) {
- rTask.task= -1;
- // removing runnable sets the cancel status
- rProcess.getQueue().remove(rTask);
- }
- switch (rTask.task) {
- case R.TASK_FINISHED:
- ok= true;
- break RTASK;
- case R.TASK_PREPARE_TEX:
- doPrepareTex();
- ok= true;
- rTask.task= 0;
- break;
- default:
- ok= true;
- }
- rTask.wait(100);
- }
- catch (final InterruptedException e) {
- // continue loop, monitor is checked
- }
- finally {
- if (!ok) {
- rTask.task= -1;
- }
- }
- }
- }
- if (checkExit(113)) {
- return;
- }
- }
- else if (this.fWorkingFolder == null) { // we need the working directory
- final SubMonitor m= this.fProgress.newChild(TICKS_RWEAVE/10);
- rTask.updatePathInformations(rProcess.getWorkspaceData());
- m.done();
- }
- }
- catch (final CoreException e) {
- abort(e, 110);
- return;
- }
- }
- else if (this.fSweaveConfig != null) { // 12x
- if (!config.weave.isRun() && this.fWorkingFolder != null) {
- return;
- }
- try {
- if (config.weave.isRun()) {
- final SubMonitor monitor= this.fProgress.newChild(TICKS_RWEAVE);
- monitor.beginTask(Messages.RweaveTexProcessing_Sweave_RCmd_label, 100);
- final ILaunchConfigurationDelegate delegate= LaunchUtils.getLaunchConfigurationDelegate(
- this.fSweaveConfig, ILaunchManager.RUN_MODE, getStatus() );
- delegate.launch(this.fSweaveConfig, ILaunchManager.RUN_MODE, getLaunch(), monitor.newChild(75));
- final IProcess[] processes= getLaunch().getProcesses();
- if (processes.length == 0) {
- throw new IllegalStateException();
- }
- final IProcess sweaveProcess= processes[processes.length-1];
- if (!sweaveProcess.isTerminated()) {
- throw new IllegalStateException();
- }
- final int exitValue= sweaveProcess.getExitValue();
- if (exitValue != 0) {
- abort(IStatus.CANCEL, NLS.bind(Messages.RweaveTexProcessing_Sweave_RCmd_error_Found_message, exitValue), null,
- 121);
- return;
- }
- monitor.done();
- }
- }
- catch (final CoreException e) {
- abort(e, 120);
- return;
- }
- }
- }
-
- private void doPrepareTex() {
- final Config config= getConfig();
- final ISchedulingRule rule= beginSchedulingRule(this.fTexFile.getParent(), this.fProgress.newChild(1));
- try {
- if ((config.weave.isRun() || config.produce.isRun()) && this.fTexFile.exists() && this.fTexFile.getType() == IResource.FILE) {
- try {
- this.fTexFile.deleteMarkers(TexlipseBuilder.MARKER_TYPE, true, IResource.DEPTH_INFINITE);
- this.fTexFile.deleteMarkers(TexlipseBuilder.LAYOUT_WARNING_TYPE, true, IResource.DEPTH_INFINITE);
- }
- catch (final CoreException e) {}
- }
- this.fProgress.worked(1);
- refreshDir(this.fTexFile, this.fProgress.newChild(1));
- if (checkExit(195)) {
- return;
- }
-
- final boolean exists= this.fTexFile.exists() && this.fTexFile.getType() == IResource.FILE;
- if (config.produce.isRun() && !exists) {
- doSetExitValue(199);
- getStatus().add(new Status(IStatus.ERROR, TexRweaveUI.BUNDLE_ID, -1,
- NLS.bind(Messages.RweaveTexProcessing_Tex_error_NotFound_message, this.fTexFile.getFullPath().toString()), null));
- return;
- }
-
- if ((config.weave.isRun() || getConfig().produce.isRun()) && exists && this.fTexOpenEditor == TexTab.OPEN_ALWAYS) {
- final OpenUsingEclipseOperation operation= new OpenUsingEclipseOperation(this.fTexFile);
- try {
- operation.init(config.produce, NO_SETTINGS, this.fProgress.newChild(1));
- operation.setFailSeverity(IStatus.WARNING);
- operation.run(this, this.fProgress.newChild(TICKS_OPEN_TEX - 1));
- }
- catch (final CoreException e) {}
- }
- }
- finally {
- endSchedulingRule(rule);
- }
- }
-
- private void doProcessTex() { // 2xx
- if (getConfig().produce.isRun() && this.fTexType == TexRweaveLaunchDelegate.BUILDTEX_TYPE_ECLIPSE) {
- final SubMonitor m1= this.fProgress.newChild(TICKS_TEX);
- this.fProgress.beginTask(Messages.RweaveTexProcessing_Tex_label, 100);
- Texlipse.getViewerManager().closeDocInViewer(this.fTexPathConfig);
- try {
- this.fTexBuilder.reset(m1.newChild(60, SubMonitor.SUPPRESS_SUBTASK));
- this.fTexBuilder.build(this.fTexPathConfig);
- AbstractBuilder.checkOutput(this.fTexPathConfig, m1.newChild(10));
- }
- catch (final OperationCanceledException e) {
- abort(IStatus.CANCEL, Messages.RweaveTexProcessing_info_Canceled_message, e,
- 211);
- return;
- }
- catch (final CoreException e) {
- abort(e, 210);
- return;
- }
- finally {
- finallyTex(m1);
- }
- m1.done();
- }
-
- if (getStatus().getSeverity() < IStatus.ERROR) {
- try { // 28x
- if (getConfig().produce.isRun() && this.fTexOpenEditor > TexTab.OPEN_ALWAYS && this.fTexFile.findMaxProblemSeverity(IMarker.PROBLEM, true, IResource.DEPTH_ZERO) >= this.fTexOpenEditor) {
- final OpenUsingEclipseOperation operation= new OpenUsingEclipseOperation(this.fTexFile);
- try {
- operation.init(getConfig().produce, NO_SETTINGS, this.fProgress.newChild(1));
- operation.setFailSeverity(IStatus.WARNING);
- operation.run(this, this.fProgress.newChild(TICKS_OPEN_TEX - 1));
- }
- catch (final CoreException e) {}
- }
- }
- catch (final CoreException e) {
- abort(e, 280);
- return;
- }
- }
- }
-
- private void finallyTex(final SubMonitor m) {
- refreshDir(this.fTexPathConfig.getOutputFile(), m.isCanceled() ? null : m.newChild(5));
- if (!this.fWorkingFolderInWorkspace.equals(this.fTexPathConfig.getOutputFile().getParent())) {
- final Job job= new Job("Refresh after TeX build") {
- @Override
- protected IStatus run(final IProgressMonitor monitor) {
- return refreshDir(TexRweaveProcessToolProcess.this.fWorkingFolderInWorkspace, m.isCanceled() ? null : m.newChild(5));
- }
- };
- job.setSystem(true);
- final IResourceRuleFactory ruleFactory= this.fWorkingFolderInWorkspace.getWorkspace().getRuleFactory();
- job.setRule(ruleFactory.refreshRule(this.fWorkingFolderInWorkspace));
- }
- }
-
- private void doOpenOutput() { // 3xx
- final Config config= getConfig();
- if (config.preview.isRun()) {
- final SubMonitor m1= this.fProgress.newChild(TICKS_OPEN_OUTPUT);
- m1.setWorkRemaining(100);
- if (!this.fTexPathConfig.getOutputFile().exists()) {
- abort((config.preview.getRun() == RUN_EXPLICITE) ? IStatus.ERROR : IStatus.INFO,
- NLS.bind(Messages.RweaveTexProcessing_Output_error_NotFound_message, this.fTexPathConfig.getOutputFile().getFullPath().toString()), null,
- 301);
- return;
- }
- try {
- if (config.preview.getRun() == RUN_DEFAULT && this.fTexFile.findMaxProblemSeverity(IMarker.PROBLEM, true, IResource.DEPTH_ZERO) >= IMarker.SEVERITY_ERROR) {
- abort(IStatus.CANCEL, Messages.RweaveTexProcessing_Output_info_SkipBecauseTex_message, null,
- 302);
- return;
- }
- }
- catch (final CoreException e) {
- abort(e, 303);
- return;
- }
- m1.worked(10);
- if (this.fPreviewConfig != null) {
- Texlipse.getViewerManager().openDocInViewer(this.fTexPathConfig, this.fPreviewConfig);
- }
- else {
- final OpenUsingEclipseOperation operation= new OpenUsingEclipseOperation(
- this.fTexPathConfig.getOutputFile() );
- try {
- operation.init(getConfig().preview, NO_SETTINGS, m1);
- operation.run(this, m1);
- }
- catch (final CoreException e) {
- abort(e, 304);
- }
- }
- m1.done();
-// final ILaunchConfigurationDelegate delegate= getRunDelegate(fPreviewConfig);
-// delegate.launch(fPreviewConfig, ILaunchManager.RUN_MODE, fLaunch, new SubProgressMonitor(fMonitor, 10));
- }
- }
-
- private boolean checkExit(final int code) {
- if (getStatus().getSeverity() >= IStatus.ERROR) {
- if (code != 0 && doGetExitValue() == 0) {
- doSetExitValue(code);
- }
- return true;
- }
- if (this.fProgress.isCanceled()) {
- final IProgressMonitor p2= this.fProgress2;
- if (p2 != null && !p2.isCanceled()) {
- p2.setCanceled(true);
- }
- if (getStatus().getSeverity() < IStatus.CANCEL) {
- getStatus().add(new Status(IStatus.CANCEL, TexRweaveUI.BUNDLE_ID, Messages.RweaveTexProcessing_info_Canceled_message));
- }
- return true;
- }
- else {
- final IProgressMonitor p2= this.fProgress2;
- if (p2 != null && p2.isCanceled()) {
- this.fProgress.setCanceled(true);
- if (getStatus().getSeverity() < IStatus.CANCEL) {
- getStatus().add(new Status(IStatus.CANCEL, TexRweaveUI.BUNDLE_ID, Messages.RweaveTexProcessing_info_Canceled_message));
- }
- return true;
- }
- }
- return false;
- }
-
- private void abort(final CoreException e, final int exitCode) {
- final IStatus status= e.getStatus();
- if (status.getSeverity() == IStatus.CANCEL) {
- getStatus().add(status);
- }
- else {
- abort(status.getSeverity(), status.getMessage(), e, exitCode);
- }
- }
-
- private void abort(final int severity, final String message, final Throwable cause, final int exitValue) {
- getStatus().add(new Status(severity, TexRweaveUI.BUNDLE_ID, -1, message, cause));
- doSetExitValue(exitValue);
- }
-
-
- private IStatus refreshDir(final IResource resource, final IProgressMonitor monitor) {
- try {
- resource.refreshLocal(IResource.DEPTH_ONE, monitor);
- return Status.OK_STATUS;
- }
- catch (final OperationCanceledException e) {
- return new Status(IStatus.CANCEL, TexRweaveUI.BUNDLE_ID, -1,
- Messages.RweaveTexProcessing_info_Canceled_message, e);
- }
- catch (final CoreException e) {
- return e.getStatus();
- }
- }
-
-
- @Override
- public void terminate() throws DebugException {
- { final IProgressMonitor monitor= this.fProgress2;
- if (monitor != null) {
- monitor.setCanceled(true);
- }
- }
-
- super.terminate();
- }
-
-}
diff --git a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexTab.java b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexTab.java
index 153e845..90b9c7c 100644
--- a/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexTab.java
+++ b/redocs/org.eclipse.statet.redocs.tex.r/src/org/eclipse/statet/internal/redocs/tex/r/ui/processing/TexTab.java
@@ -14,570 +14,133 @@
package org.eclipse.statet.internal.redocs.tex.r.ui.processing;
-import static org.eclipse.statet.internal.redocs.tex.r.ui.processing.TexRweaveLaunchDelegate.BUILDTEX_TYPE_ECLIPSE;
-import static org.eclipse.statet.internal.redocs.tex.r.ui.processing.TexRweaveLaunchDelegate.BUILDTEX_TYPE_RCONSOLE;
-
import org.eclipse.core.databinding.DataBindingContext;
-import org.eclipse.core.databinding.UpdateValueStrategy;
-import org.eclipse.core.databinding.observable.Diffs;
-import org.eclipse.core.databinding.observable.IChangeListener;
import org.eclipse.core.databinding.observable.Realm;
-import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
-import org.eclipse.core.databinding.observable.value.ComputedValue;
-import org.eclipse.core.databinding.observable.value.IObservableValue;
-import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
-import org.eclipse.core.databinding.observable.value.WritableValue;
-import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.jface.databinding.swt.ISWTObservableValue;
-import org.eclipse.jface.databinding.swt.WidgetProperties;
-import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.texlipse.builder.Builder;
-import org.eclipse.texlipse.builder.BuilderChooser;
-import org.eclipse.texlipse.builder.BuilderRegistry;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.statet.jcommons.collections.ImCollections;
-import org.eclipse.statet.ecommons.databinding.jface.RadioGroupObservable;
-import org.eclipse.statet.ecommons.databinding.jface.SWTMultiEnabledObservable;
-import org.eclipse.statet.ecommons.debug.ui.config.LaunchConfigTabWithDbc;
-import org.eclipse.statet.ecommons.templates.TemplateVariableProcessor;
-import org.eclipse.statet.ecommons.ui.SharedMessages;
-import org.eclipse.statet.ecommons.ui.components.CustomizableVariableSelectionDialog;
import org.eclipse.statet.ecommons.ui.util.LayoutUtil;
-import org.eclipse.statet.ecommons.ui.util.VariableFilterUtils;
-import org.eclipse.statet.ecommons.ui.workbench.ResourceInputComposite;
-import org.eclipse.statet.ltk.ui.sourceediting.SnippetEditor1;
-import org.eclipse.statet.r.core.RCore;
-import org.eclipse.statet.r.launching.ui.RLaunchingUI;
-import org.eclipse.statet.r.ui.sourceediting.RSourceViewerConfigurator;
-import org.eclipse.statet.r.ui.sourceediting.RTemplateSourceViewerConfigurator;
+import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingConfigIOStepTab;
+import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingConfigMainTab;
+import org.eclipse.statet.docmlet.base.ui.processing.operations.DocProcessingConfigOpenFileSetting;
import org.eclipse.statet.redocs.r.ui.RedocsRUIResources;
+import org.eclipse.statet.redocs.r.ui.processing.RWeaveDocProcessingConfig;
+import org.eclipse.statet.redocs.r.ui.processing.RunRCmdToolOperationSettings;
+import org.eclipse.statet.redocs.r.ui.processing.RunRConsoleSnippetOperation;
+import org.eclipse.statet.redocs.r.ui.processing.RunRConsoleSnippetOperationSettings;
-public class TexTab extends LaunchConfigTabWithDbc {
+public class TexTab extends DocProcessingConfigIOStepTab {
- private static class BuildChooserObservable extends AbstractObservableValue<Integer> implements SelectionListener {
+ private final DocProcessingConfigOpenFileSetting openResult;
+
+
+ public TexTab(final DocProcessingConfigMainTab mainTab) {
+ super(mainTab, RWeaveDocProcessingConfig.WEAVE_ATTR_QUALIFIER);
- private final BuilderChooser fControl;
- private Integer fCurrentBuilder;
+ setInput(TexRweaveConfig.SOURCE_FORMAT, null);
+ setAvailableOutputFormats(TexRweaveConfig.WEAVE_OUTPUT_FORMATS,
+ TexRweaveConfig.EXT_LTX_FORMAT_KEY );
- public BuildChooserObservable(final BuilderChooser control) {
- this.fControl= control;
- this.fCurrentBuilder= this.fControl.getSelectedBuilder();
- this.fControl.addSelectionListener(this);
- }
+ setAvailableOperations(ImCollections.newList(
+ new RunRConsoleSnippetOperationSettings(),
+ new RunRCmdToolOperationSettings() ));
- @Override
- public Object getValueType() {
- return Integer.class;
- }
-
- @Override
- protected Integer doGetValue() {
- return this.fCurrentBuilder;
- }
-
- @Override
- protected void doSetValue(final Integer value) {
- if (value != null) {
- this.fCurrentBuilder= value;
- this.fControl.setSelectedBuilder(this.fCurrentBuilder);
- return;
- }
- }
-
- @Override
- public void widgetDefaultSelected(final SelectionEvent e) {
- }
-
- @Override
- public void widgetSelected(final SelectionEvent e) {
- final int oldValue= this.fCurrentBuilder;
- this.fCurrentBuilder= this.fControl.getSelectedBuilder();
- fireValueChange(Diffs.createValueDiff(oldValue, this.fCurrentBuilder));
- }
-
- }
-
-
- public static final String NS= "org.eclipse.statet.r.debug/Tex/"; //$NON-NLS-1$
-
- public static final String ATTR_OPENTEX_ENABLED= NS + "OpenTex.enabled"; //$NON-NLS-1$
- /** @Deprecated replaced by {@link #ATTR_BUILDTEX_TYPE} */
- public static final String ATTR_BUILDTEX_ENABLED= NS + "BuildTex.enabled"; //$NON-NLS-1$
- public static final String ATTR_BUILDTEX_TYPE= NS + "BuildTex.type"; //$NON-NLS-1$
- public static final String ATTR_BUILDTEX_ECLIPSE_BUILDERID= NS + "BuildTex.builderId"; //$NON-NLS-1$
- public static final String ATTR_BUILDTEX_R_COMMANDS= NS + "BuildTex.rCommands"; //$NON-NLS-1$
- public static final String ATTR_BUILDTEX_FORMAT= NS + "BuildTex.format"; //$NON-NLS-1$
- public static final String ATTR_BUILDTEX_OUTPUTDIR= NS + "BuildTex.outputDir"; //$NON-NLS-1$
-
- public static final int OPEN_OFF= -1;
- public static final int OPEN_ALWAYS= 0;
-
-
- private final IObservableValue<String> fOutputDirValue;
-
- private final IObservableValue<String> fOutputFormatValue;
-
- private final IObservableValue<Boolean> fOpenTexEnabledValue;
- private final IObservableValue<Boolean> fOpenTexOnErrorsEnabledValue;
-
- private final IObservableValue<Integer> fBuildTexTypeValue;
- private final IObservableValue<Integer> fBuildTexBuilderIdValue;
- private final IObservableValue<String> fBuildTexRCommandsValue;
-
- private Button fOpenTexFileControl;
- private Button fOpenTexFileOnErrorsControl;
-
- private ResourceInputComposite fOutputDirControl;
-
- private Button fBuildTexFileDisabledControl;
- private Button fBuildTexFileEclipseControl;
- private BuilderChooser fBuildTexTypeChooser;
- private Button fBuildTexFileRControl;
- private SnippetEditor1 fConsoleCommandEditor;
- private Combo fOutputFormatControl;
-
-
- public TexTab() {
final Realm realm= getRealm();
- this.fOpenTexEnabledValue= new WritableValue<>(realm, false, Boolean.class);
- this.fOpenTexOnErrorsEnabledValue= new WritableValue<>(realm, false, Boolean.class);
- this.fOutputDirValue= new WritableValue<>(realm, null, String.class);
- this.fBuildTexTypeValue= new WritableValue<>(realm, 0, Integer.class);
- this.fBuildTexBuilderIdValue= new WritableValue<>(realm, 0, Integer.class);
- this.fBuildTexRCommandsValue= new WritableValue<>(realm, "", String.class); //$NON-NLS-1$
- this.fOutputFormatValue= new WritableValue<>(realm, "", String.class); //$NON-NLS-1$
+ this.openResult= new DocProcessingConfigOpenFileSetting(
+ RWeaveDocProcessingConfig.WEAVE_OPEN_RESULT_ATTR_NAME, realm );
}
@Override
- public String getName() {
- return Messages.Processing_TexTab_label;
- }
-
- @Override
public Image getImage() {
- return RedocsRUIResources.INSTANCE.getImage(RedocsRUIResources.TOOL_BUILDTEX_IMAGE_ID);
+ return RedocsRUIResources.INSTANCE.getImage(RedocsRUIResources.TOOL_RWEAVE_IMAGE_ID);
+ }
+
+ @Override
+ public String getName() {
+ return createName(Messages.WeaveTab_name);
+ }
+
+ @Override
+ public String getLabel() {
+ return Messages.Weave_label;
+ }
+
+
+ private void updateInput() {
+ setInput(TexRweaveConfig.SOURCE_FORMAT, getMainTab().getSourceFile());
}
@Override
- public void createControl(final Composite parent) {
- final Composite mainComposite= new Composite(parent, SWT.NONE);
- setControl(mainComposite);
- mainComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- mainComposite.setLayout(new GridLayout());
+ protected void addControls(final Composite parent) {
+ updateInput();
- final Group group= new Group(mainComposite, SWT.NONE);
- group.setLayout(LayoutUtil.createGroupGrid(1));
- group.setText(Messages.TexTab_label);
- group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ super.addControls(parent);
- this.fOpenTexFileControl= new Button(group, SWT.CHECK);
- this.fOpenTexFileControl.setText(Messages.TexTab_OpenTex_label);
- this.fOpenTexFileControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- this.fOpenTexFileOnErrorsControl= new Button(group, SWT.CHECK);
- this.fOpenTexFileOnErrorsControl.setText(Messages.TexTab_OpenTex_OnlyOnErrors_label);
- final GridData gd= new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
- gd.horizontalIndent= LayoutUtil.defaultIndent();
- this.fOpenTexFileOnErrorsControl.setLayoutData(gd);
-
- LayoutUtil.addSmallFiller(group, false);
-
- createOutputOptions(group);
-
- LayoutUtil.addSmallFiller(group, false);
-
- createBuildOptions(group);
-
- initBindings();
- }
-
- private void createOutputOptions(final Group composite) {
- { final Label label= new Label(composite, SWT.NONE);
- label.setText(Messages.TexTab_OutputDir_longlabel);
- label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- }
- this.fOutputDirControl= new ResourceInputComposite(composite,
- ResourceInputComposite.STYLE_TEXT,
- ResourceInputComposite.MODE_DIRECTORY | ResourceInputComposite.MODE_SAVE,
- Messages.TexTab_OutputDir_label) {
-
- @Override
- protected void fillMenu(final Menu menu) {
- super.fillMenu(menu);
- { final MenuItem item= new MenuItem(menu, SWT.PUSH);
- item.setText(Messages.Insert_SweaveDirVariable_label);
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(final SelectionEvent e) {
- insertText("${container_loc:${"+TexRweaveLaunchDelegate.VARNAME_SWEAVE_FILE+"}}"); //$NON-NLS-1$ //$NON-NLS-2$
- getTextControl().setFocus();
- }
- });
- }
- { final MenuItem item= new MenuItem(menu, SWT.PUSH);
- item.setText(Messages.Insert_LatexDirVariable_label);
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(final SelectionEvent e) {
- insertText("${container_loc:${"+TexRweaveLaunchDelegate.VARNAME_LATEX_FILE+"}}"); //$NON-NLS-1$ //$NON-NLS-2$
- getTextControl().setFocus();
- }
- });
- }
- }
- };
- this.fOutputDirControl.setShowInsertVariable(true,
- VariableFilterUtils.DEFAULT_INTERACTIVE_FILTERS,
- ImCollections.newList(
- TexRweaveLaunchDelegate.VARIABLE_SWEAVE_FILE,
- TexRweaveLaunchDelegate.VARIABLE_LATEX_FILE ));
- this.fOutputDirControl.getValidator().setOnEmpty(IStatus.OK);
- this.fOutputDirControl.getValidator().setOnExisting(IStatus.OK);
- this.fOutputDirControl.getValidator().setOnFile(IStatus.ERROR);
- this.fOutputDirControl.getValidator().setOnLateResolve(IStatus.OK);
- this.fOutputDirControl.getValidator().setOnNotLocal(IStatus.ERROR);
- this.fOutputDirControl.getValidator().setIgnoreRelative(true);
- this.fOutputDirControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-
- { final Composite lineComposite= new Composite(composite, SWT.NONE);
- lineComposite.setLayout(LayoutUtil.createCompositeGrid(2));
- lineComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- { final Label label= new Label(lineComposite, SWT.NONE);
- label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
- label.setText(Messages.TexTab_OutputFormat_label);
- }
- { this.fOutputFormatControl= new Combo(lineComposite, SWT.BORDER | SWT.DROP_DOWN);
- final GridData gd= new GridData(SWT.LEFT, SWT.CENTER, true, false);
- gd.widthHint= LayoutUtil.hintWidth(this.fOutputFormatControl, 3);
- this.fOutputFormatControl.setLayoutData(gd);
- this.fOutputFormatControl.setItems(new String[] { "dvi", "pdf" }); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- }
-
- private void createBuildOptions(final Composite composite) {
- // Disabled
- this.fBuildTexFileDisabledControl= new Button(composite, SWT.RADIO);
- this.fBuildTexFileDisabledControl.setText(Messages.TexTab_BuildDisabled_label);
- this.fBuildTexFileDisabledControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- this.fBuildTexFileDisabledControl.setSelection(true);
-
- // Eclipse/TeXlipse
- this.fBuildTexFileEclipseControl= new Button(composite, SWT.RADIO);
- this.fBuildTexFileEclipseControl.setText(Messages.TexTab_BuildEclipse_label);
- this.fBuildTexFileEclipseControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-
- { this.fBuildTexTypeChooser= new BuilderChooser(composite);
- final GridData gd= new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
- gd.horizontalIndent= LayoutUtil.defaultIndent();
- this.fBuildTexTypeChooser.getControl().setLayoutData(gd);
- }
-
- // R Console
- { this.fBuildTexFileRControl= new Button(composite, SWT.RADIO);
- this.fBuildTexFileRControl.setText(Messages.TexTab_BuildRConsole_label);
- this.fBuildTexFileRControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- }
- { final TemplateVariableProcessor templateVariableProcessor= new TemplateVariableProcessor();
- final RSourceViewerConfigurator configurator= new RTemplateSourceViewerConfigurator(
- RCore.WORKBENCH_ACCESS,
- templateVariableProcessor );
- this.fConsoleCommandEditor= new SnippetEditor1(configurator, null,
- PlatformUI.getWorkbench(), RLaunchingUI.LAUNCH_CONFIG_QUALIFIER, true ) {
- @Override
- protected void fillToolMenu(final Menu menu) {
- { final MenuItem item= new MenuItem(menu, SWT.PUSH);
- item.setText(SharedMessages.InsertVariable_label);
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(final SelectionEvent e) {
- final CustomizableVariableSelectionDialog dialog= new CustomizableVariableSelectionDialog(getTextControl().getShell());
- dialog.addVariableFilter(VariableFilterUtils.EXCLUDE_JAVA_FILTER);
- dialog.addAdditional(TexRweaveLaunchDelegate.VARIABLE_SWEAVE_FILE);
- dialog.addAdditional(TexRweaveLaunchDelegate.VARIABLE_LATEX_FILE);
- dialog.addAdditional(TexRweaveLaunchDelegate.VARIABLE_OUTPUT_FILE);
- if (dialog.open() != Dialog.OK) {
- return;
- }
- final String variable= dialog.getVariableExpression();
- if (variable == null) {
- return;
- }
- getTextControl().insert(variable);
- getTextControl().setFocus();
- }
- });
- }
- { final MenuItem item= new MenuItem(menu, SWT.PUSH);
- item.setText(Messages.Insert_LatexFileVariable_label);
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(final SelectionEvent e) {
- getTextControl().insert("${resource_loc:${"+TexRweaveLaunchDelegate.VARNAME_LATEX_FILE+"}}"); //$NON-NLS-1$ //$NON-NLS-2$
- getTextControl().setFocus();
- }
- });
- }
- { final MenuItem item= new MenuItem(menu, SWT.PUSH);
- item.setText(Messages.Insert_OutputDirVariable_label);
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(final SelectionEvent e) {
- getTextControl().insert("${container_loc:${"+TexRweaveLaunchDelegate.VARNAME_OUTPUT_FILE+"}}"); //$NON-NLS-1$ //$NON-NLS-2$
- getTextControl().setFocus();
- }
- });
- }
- }
- };
- this.fConsoleCommandEditor.create(composite, SnippetEditor1.DEFAULT_MULTI_LINE_STYLE);
- final GridData gd= new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
- gd.heightHint= LayoutUtil.hintHeight(this.fConsoleCommandEditor.getSourceViewer().getTextWidget(), 5);
- gd.horizontalIndent= LayoutUtil.defaultIndent();
- this.fConsoleCommandEditor.getControl().setLayoutData(gd);
+ { final Composite group= createPostGroup(parent);
+ group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
}
}
@Override
- protected void addBindings(final DataBindingContext dbc, final Realm realm) {
- final ISWTObservableValue openObs= WidgetProperties.selection().observe(this.fOpenTexFileControl);
- dbc.bindValue(
- openObs,
- this.fOpenTexEnabledValue );
- dbc.bindValue(
- WidgetProperties.selection().observe(this.fOpenTexFileOnErrorsControl),
- this.fOpenTexOnErrorsEnabledValue );
- dbc.bindValue(
- new RadioGroupObservable(realm, new Button[] {
- this.fBuildTexFileDisabledControl,
- this.fBuildTexFileEclipseControl,
- this.fBuildTexFileRControl
- } ),
- this.fBuildTexTypeValue );
- dbc.bindValue(
- new BuildChooserObservable(this.fBuildTexTypeChooser),
- this.fBuildTexBuilderIdValue );
- dbc.bindValue(
- WidgetProperties.text(SWT.Modify).observe(this.fConsoleCommandEditor.getTextControl()),
- this.fBuildTexRCommandsValue );
- dbc.bindValue(
- WidgetProperties.text().observe(this.fOutputFormatControl),
- this.fOutputFormatValue );
+ protected Composite createPostGroup(final Composite parent) {
+ final Composite group= super.createPostGroup(parent);
+ group.setLayout(LayoutUtil.createGroupGrid(2));
- this.fBuildTexBuilderIdValue.addValueChangeListener(
- (final ValueChangeEvent<? extends Integer> event) ->
- updateFormat() );
- this.fBuildTexTypeValue.addValueChangeListener((
- final ValueChangeEvent<? extends Integer> event) -> {
- final Object newValue= event.diff.getNewValue();
- final int typeId= (newValue instanceof Integer) ? ((Integer) newValue).intValue() : -1;
- switch (typeId) {
- case BUILDTEX_TYPE_ECLIPSE:
- updateFormat();
- break;
- case BUILDTEX_TYPE_RCONSOLE:
- if (TexRweaveLaunchDelegate.DEFAULT_BUILDTEX_R_COMMANDS.equals(TexTab.this.fBuildTexRCommandsValue.getValue())) {
- TexTab.this.fOutputFormatValue.setValue(TexRweaveLaunchDelegate.DEFAULT_BUILDTEX_FORMAT);
- }
- break;
- }
- } );
-
- // Enablement
- dbc.bindValue(
- WidgetProperties.enabled().observe(this.fOpenTexFileOnErrorsControl),
- openObs );
- final Composite group= this.fBuildTexTypeChooser.getControl();
- dbc.bindValue(new SWTMultiEnabledObservable(realm, group.getChildren(), null),
- new ComputedValue<Boolean>(realm, Boolean.class) {
- @Override
- protected Boolean calculate() {
- return ((TexTab.this.fBuildTexTypeValue.getValue()) == TexRweaveLaunchDelegate.BUILDTEX_TYPE_ECLIPSE);
- }
- } );
- dbc.bindValue(new SWTMultiEnabledObservable(realm, new Control[] { this.fConsoleCommandEditor.getControl() }, null),
- new ComputedValue<Boolean>(realm, Boolean.class) {
- @Override
- protected Boolean calculate() {
- return ((TexTab.this.fBuildTexTypeValue.getValue()) == TexRweaveLaunchDelegate.BUILDTEX_TYPE_RCONSOLE);
- }
- } );
- dbc.bindValue(new SWTMultiEnabledObservable(realm, new Control[] { this.fOutputFormatControl }, null),
- new ComputedValue<Boolean>(realm, Boolean.class) {
- @Override
- protected Boolean calculate() {
- return ((TexTab.this.fBuildTexTypeValue.getValue()) != TexRweaveLaunchDelegate.BUILDTEX_TYPE_ECLIPSE);
- }
- } );
-
- dbc.bindValue(
- this.fOutputDirControl.getObservable(),
- this.fOutputDirValue,
- new UpdateValueStrategy().setAfterGetValidator(this.fOutputDirControl.getValidator()),
- null );
- }
-
- private void updateFormat() {
- final Object texBuilderId= this.fBuildTexBuilderIdValue.getValue();
- if (texBuilderId instanceof Integer) {
- final Builder builder= BuilderRegistry.get((Integer) texBuilderId);
- if (builder != null) {
- this.fOutputFormatValue.setValue(builder.getOutputFormat());
- }
+ { final ComboViewer viewer= this.openResult.createControls(group, Messages.WeaveTab_OpenResult_label);
+ viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
}
+
+ return group;
}
+ @Override
+ protected void addBindings(final DataBindingContext dbc) {
+ super.addBindings(dbc);
+
+ this.openResult.addBindings(dbc);
+ }
+
+
+ @Override
+ protected String getDefaultOperationId() {
+ return RunRConsoleSnippetOperation.ID;
+ }
@Override
public void setDefaults(final ILaunchConfigurationWorkingCopy configuration) {
- configuration.setAttribute(ATTR_OPENTEX_ENABLED, OPEN_OFF);
- configuration.setAttribute(ATTR_BUILDTEX_TYPE, TexRweaveLaunchDelegate.DEFAULT_BUILDTEX_TYPE);
- configuration.setAttribute(ATTR_BUILDTEX_ECLIPSE_BUILDERID, 0);
- configuration.setAttribute(ATTR_BUILDTEX_OUTPUTDIR, ""); //$NON-NLS-1$
+ super.setDefaults(configuration);
}
@Override
protected void doInitialize(final ILaunchConfiguration configuration) {
- int open= OPEN_OFF;
- try {
- open= configuration.getAttribute(ATTR_OPENTEX_ENABLED, open);
- } catch (final CoreException e) {
- logReadingError(e);
- }
- this.fOpenTexEnabledValue.setValue(open >= OPEN_ALWAYS);
- this.fOpenTexOnErrorsEnabledValue.setValue(open > OPEN_ALWAYS);
+ super.doInitialize(configuration);
- int buildType= TexRweaveLaunchDelegate.DEFAULT_BUILDTEX_TYPE;
try {
- buildType= configuration.getAttribute(ATTR_BUILDTEX_TYPE, -2);
+ this.openResult.load(configuration);
}
catch (final CoreException e) {
logReadingError(e);
}
- if (buildType == -2) {
- try {
- buildType= configuration.getAttribute(ATTR_BUILDTEX_ENABLED, false) ?
- TexRweaveLaunchDelegate.BUILDTEX_TYPE_ECLIPSE :
- TexRweaveLaunchDelegate.BUILDTEX_TYPE_DISABLED;
- }
- catch (final CoreException e) {
- logReadingError(e);
- }
- }
- this.fBuildTexTypeValue.setValue(buildType);
-
- int texBuilderId= 0;
- try {
- texBuilderId= configuration.getAttribute(ATTR_BUILDTEX_ECLIPSE_BUILDERID, texBuilderId);
- }
- catch (final CoreException e) {
- logReadingError(e);
- }
- this.fBuildTexBuilderIdValue.setValue(texBuilderId);
-
- String rCommands= TexRweaveLaunchDelegate.DEFAULT_BUILDTEX_R_COMMANDS;
- try {
- rCommands= configuration.getAttribute(ATTR_BUILDTEX_R_COMMANDS, rCommands);
- }
- catch (final CoreException e) {
- logReadingError(e);
- }
- this.fBuildTexRCommandsValue.setValue(rCommands);
-
- if (buildType == BUILDTEX_TYPE_ECLIPSE) {
- updateFormat();
- }
- else {
- String format= TexRweaveLaunchDelegate.DEFAULT_BUILDTEX_FORMAT;
- try {
- format= configuration.getAttribute(ATTR_BUILDTEX_FORMAT, format);
- }
- catch (final CoreException e) {
- logReadingError(e);
- }
- this.fOutputFormatValue.setValue(format);
- }
-
- String outputDir= ""; //$NON-NLS-1$
- try {
- outputDir= configuration.getAttribute(ATTR_BUILDTEX_OUTPUTDIR, outputDir);
- }
- catch (final CoreException e) {
- logReadingError(e);
- }
- this.fOutputDirValue.setValue(outputDir);
}
@Override
protected void doSave(final ILaunchConfigurationWorkingCopy configuration) {
- int open= OPEN_OFF;
- if (this.fOpenTexEnabledValue.getValue()) {
- open= (this.fOpenTexOnErrorsEnabledValue.getValue()) ? IMarker.SEVERITY_ERROR : OPEN_ALWAYS;
- }
- configuration.setAttribute(ATTR_OPENTEX_ENABLED, open);
+ super.doSave(configuration);
- final int buildType= this.fBuildTexTypeValue.getValue();
- configuration.setAttribute(ATTR_BUILDTEX_TYPE, buildType);
-
- final Integer texBuilderId= this.fBuildTexBuilderIdValue.getValue();
- if (texBuilderId != null
- && (buildType == TexRweaveLaunchDelegate.BUILDTEX_TYPE_ECLIPSE || texBuilderId.intValue() != 0) ) {
- configuration.setAttribute(ATTR_BUILDTEX_ECLIPSE_BUILDERID, texBuilderId.intValue());
- }
- else {
- configuration.removeAttribute(ATTR_BUILDTEX_ECLIPSE_BUILDERID);
- }
-
- final String rCommands= this.fBuildTexRCommandsValue.getValue();
- if (buildType == TexRweaveLaunchDelegate.BUILDTEX_TYPE_RCONSOLE || !rCommands.equals(TexRweaveLaunchDelegate.DEFAULT_BUILDTEX_R_COMMANDS)) {
- configuration.setAttribute(ATTR_BUILDTEX_R_COMMANDS, rCommands);
- }
- else {
- configuration.removeAttribute(ATTR_BUILDTEX_R_COMMANDS);
- }
-
- final String format= this.fOutputFormatValue.getValue();
- configuration.setAttribute(ATTR_BUILDTEX_FORMAT, format);
-
- configuration.setAttribute(ATTR_BUILDTEX_OUTPUTDIR, this.fOutputDirValue.getValue());
- }
-
-
- public boolean addOutputFormatListener(final IChangeListener listener) {
- if (this.fOutputFormatValue != null) {
- this.fOutputFormatValue.addChangeListener(listener);
- return true;
- }
- return false;
- }
-
- public String getOutputFormat() {
- return this.fOutputFormatValue.getValue();
+ this.openResult.save(configuration);
}
}
diff --git a/redocs/org.eclipse.statet.redocs.wikitext.r/src/org/eclipse/statet/internal/redocs/wikitext/r/ui/processing/DocumentRule.java b/redocs/org.eclipse.statet.redocs.wikitext.r/src/org/eclipse/statet/internal/redocs/wikitext/r/ui/processing/DocumentRule.java
deleted file mode 100644
index 9f4e066..0000000
--- a/redocs/org.eclipse.statet.redocs.wikitext.r/src/org/eclipse/statet/internal/redocs/wikitext/r/ui/processing/DocumentRule.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*=============================================================================#
- # Copyright (c) 2014, 2018 Stephan Wahlbrink and others.
- #
- # This program and the accompanying materials are made available under the
- # terms of the Eclipse Public License 2.0 which is available at
- # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
- # which is available at https://www.apache.org/licenses/LICENSE-2.0.
- #
- # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
- #
- # Contributors:
- # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
- #=============================================================================*/
-
-package org.eclipse.statet.internal.redocs.wikitext.r.ui.processing;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.jobs.ISchedulingRule;
-
-
-public class DocumentRule implements ISchedulingRule {
-
-
- private final IFile sweaveFile;
-
-
- public DocumentRule(final IFile sweaveFile) {
- if (sweaveFile == null) {
- throw new NullPointerException("sweaveFile"); //$NON-NLS-1$
- }
- this.sweaveFile= sweaveFile;
- }
-
-
- private boolean equalRule(final DocumentRule other) {
- return (this.sweaveFile.equals(other.sweaveFile));
- }
-
- @Override
- public boolean contains(final ISchedulingRule rule) {
- return (rule instanceof DocumentRule && equalRule((DocumentRule) rule));
- }
-
- @Override
- public boolean isConflicting(final ISchedulingRule rule) {
- return (rule instanceof DocumentRule && equalRule((DocumentRule) rule));
- }
-
-
- @Override
- public int hashCode() {
- return this.sweaveFile.hashCode() + 9543;
- }
-
- @Override
- public boolean equals(final Object obj) {
- return (this == obj
- || (obj instanceof DocumentRule && equalRule((DocumentRule) obj)) );
- }
-
-}
diff --git a/redocs/org.eclipse.statet.redocs.wikitext.r/src/org/eclipse/statet/internal/redocs/wikitext/r/ui/processing/WikitextRweaveConfigTabGroup.java b/redocs/org.eclipse.statet.redocs.wikitext.r/src/org/eclipse/statet/internal/redocs/wikitext/r/ui/processing/WikitextRweaveConfigTabGroup.java
index f8f7bf9..9b8f82b 100644
--- a/redocs/org.eclipse.statet.redocs.wikitext.r/src/org/eclipse/statet/internal/redocs/wikitext/r/ui/processing/WikitextRweaveConfigTabGroup.java
+++ b/redocs/org.eclipse.statet.redocs.wikitext.r/src/org/eclipse/statet/internal/redocs/wikitext/r/ui/processing/WikitextRweaveConfigTabGroup.java
@@ -34,7 +34,7 @@
/**
- * Tab group for Sweave (LaTeX+R) output creation toolchain.
+ * Tab group for Wikitext+R output creation toolchain.
*/
public class WikitextRweaveConfigTabGroup extends AbstractLaunchConfigurationTabGroup {
@@ -44,7 +44,7 @@
final LaunchConfigPresets presets= new LaunchConfigPresets(
WikitextRweaveConfig.TYPE_ID );
- { final ILaunchConfigurationWorkingCopy config= presets.add("PDF using knitr + pandoc");
+ { final ILaunchConfigurationWorkingCopy config= presets.add("PDF using R:knitr + R:pandoc");
config.setAttribute(WikitextRweaveConfig.WEAVE_ENABLED_ATTR_NAME, true);
config.setAttribute(WikitextRweaveConfig.WEAVE_OUTPUT_FORMAT_ATTR_NAME,
WikitextRweaveConfig.AUTO_WIKITEXT_FORMAT_KEY );
@@ -68,7 +68,7 @@
"format= \"latex\", " +
"encoding= \"${resource_enc:${source_file_path}}\")" ));
}
- { final ILaunchConfigurationWorkingCopy config= presets.add("PDF using RMarkdown, two-step");
+ { final ILaunchConfigurationWorkingCopy config= presets.add("PDF using R:RMarkdown, two-step");
config.setAttribute(WikitextRweaveConfig.WEAVE_ENABLED_ATTR_NAME, true);
config.setAttribute(WikitextRweaveConfig.WEAVE_OUTPUT_FORMAT_ATTR_NAME,
WikitextRweaveConfig.AUTO_WIKITEXT_FORMAT_KEY );
@@ -94,7 +94,7 @@
"output_file= \"${resource_loc:${out_file_path}}\", " +
"encoding= \"${resource_enc:${source_file_path}}\")" ));
}
- { final ILaunchConfigurationWorkingCopy config= presets.add("PDF using RMarkdown, single-step");
+ { final ILaunchConfigurationWorkingCopy config= presets.add("PDF using R:RMarkdown, single-step");
config.setAttribute(WikitextRweaveConfig.WEAVE_ENABLED_ATTR_NAME, false);
config.setAttribute(WikitextRweaveConfig.WEAVE_OUTPUT_FORMAT_ATTR_NAME,
WikitextRweaveConfig.AUTO_WIKITEXT_FORMAT_KEY );
@@ -120,7 +120,7 @@
"output_file= \"${resource_loc:${out_file_path}}\", " +
"encoding= \"${resource_enc}\")" ));
}
- { final ILaunchConfigurationWorkingCopy config= presets.add("Auto (YAML) using RMarkdown, two-step");
+ { final ILaunchConfigurationWorkingCopy config= presets.add("Auto (YAML) using R:RMarkdown, two-step");
config.setAttribute(WikitextRweaveConfig.WEAVE_ENABLED_ATTR_NAME, true);
config.setAttribute(WikitextRweaveConfig.WEAVE_OUTPUT_FORMAT_ATTR_NAME,
WikitextRweaveConfig.AUTO_WIKITEXT_FORMAT_KEY );
@@ -145,7 +145,7 @@
"output_dir= \"${container_loc:${out_file_path}}\", " +
"encoding= \"${resource_enc:${source_file_path}}\")" ));
}
- { final ILaunchConfigurationWorkingCopy config= presets.add("Auto (YAML) using RMarkdown, single-step");
+ { final ILaunchConfigurationWorkingCopy config= presets.add("Auto (YAML) using R:RMarkdown, single-step");
config.setAttribute(WikitextRweaveConfig.WEAVE_ENABLED_ATTR_NAME, false);
config.setAttribute(WikitextRweaveConfig.WEAVE_OUTPUT_FORMAT_ATTR_NAME,
WikitextRweaveConfig.AUTO_WIKITEXT_FORMAT_KEY );