| /******************************************************************************* |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Pierre Allard, |
| * Regent L'Archeveque, |
| * Olivier L. Larouche - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| * |
| *******************************************************************************/ |
| package org.eclipse.apogy.core.invocator.ui.parts; |
| |
| import java.util.HashMap; |
| |
| import org.eclipse.apogy.common.emf.ui.parts.AbstractEObjectSelectionPart; |
| import org.eclipse.apogy.core.invocator.ScriptBasedProgram; |
| import org.eclipse.apogy.core.invocator.ui.ApogyCoreInvocatorUIRCPConstants; |
| import org.eclipse.apogy.core.invocator.ui.composites.TextScriptEditorComposite; |
| import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
| import org.eclipse.e4.ui.workbench.modeling.ISelectionListener; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.layout.GridLayout; |
| import org.eclipse.swt.widgets.Composite; |
| |
| public abstract class ScriptBasedProgramTextEditorPart extends AbstractEObjectSelectionPart { |
| private ScriptBasedProgram scriptBasedProgram = null; |
| |
| private Composite top; |
| |
| private TextScriptEditorComposite textScriptEditorComposite; |
| |
| @Override |
| protected void createContentComposite(Composite parent, int style) { |
| this.top = new Composite(parent, SWT.BORDER); |
| this.top.setLayout(new GridLayout(1, false)); |
| |
| this.textScriptEditorComposite = new TextScriptEditorComposite(this.top, SWT.BORDER) { |
| @Override |
| protected void fileDirtyChanged(boolean isDirty) { |
| if (isDirty) { |
| // Adds the * to from part label. |
| ScriptBasedProgramTextEditorPart.this.mPart.setDirty(true); |
| } else { |
| // Removes * from part label. |
| ScriptBasedProgramTextEditorPart.this.mPart.setDirty(false); |
| } |
| } |
| }; |
| GridData gd_textScriptEditorComposite = new GridData(SWT.FILL, SWT.FILL, false, false); |
| this.textScriptEditorComposite.setLayoutData(gd_textScriptEditorComposite); |
| } |
| |
| protected abstract String getRelativeScriptPath(ScriptBasedProgram scriptBasedProgram); |
| |
| @Override |
| protected void setCompositeContents(EObject eObject) { |
| if (eObject instanceof ScriptBasedProgram) { |
| this.scriptBasedProgram = (ScriptBasedProgram) eObject; |
| this.textScriptEditorComposite.setScriptPath(getRelativeScriptPath(this.scriptBasedProgram)); |
| } else { |
| this.textScriptEditorComposite.setScriptPath(null); |
| } |
| } |
| |
| @Override |
| public void userPostConstruct(MPart mPart) { |
| |
| super.userPostConstruct(mPart); |
| } |
| |
| public ScriptBasedProgram getSelectedProgram() { |
| return this.scriptBasedProgram; |
| } |
| |
| @Override |
| public void userPreDestroy(MPart mPart) { |
| |
| super.userPreDestroy(mPart); |
| } |
| |
| @Override |
| protected HashMap<String, ISelectionListener> getSelectionProvidersIdsToSelectionListeners() { |
| HashMap<String, ISelectionListener> selectionProvidersIdsToSelectionListeners = new HashMap<String, ISelectionListener>(); |
| |
| selectionProvidersIdsToSelectionListeners |
| .put(ApogyCoreInvocatorUIRCPConstants.PART__SCRIPT_BASED_PROGRAMS_LIST__ID, this.DEFAULT_LISTENER); |
| |
| return selectionProvidersIdsToSelectionListeners; |
| } |
| } |