| /*=============================================================================# |
| # Copyright (c) 2010, 2019 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.r.debug.ui; |
| |
| import org.eclipse.jface.resource.ImageDescriptor; |
| import org.eclipse.ui.IPersistableElement; |
| |
| import org.eclipse.statet.jcommons.ts.core.Tool; |
| |
| import org.eclipse.statet.ecommons.text.ISourceFragment; |
| |
| import org.eclipse.statet.ltk.ui.sourceediting.ISourceFragmentEditorInput; |
| import org.eclipse.statet.nico.core.runtime.ToolProcess; |
| import org.eclipse.statet.r.debug.core.sourcelookup.RRuntimeSourceFragment; |
| |
| |
| public class RRuntimeSourceEditorInput implements ISourceFragmentEditorInput { |
| |
| |
| private final RRuntimeSourceFragment fragment; |
| |
| |
| public RRuntimeSourceEditorInput(final RRuntimeSourceFragment fragment) { |
| if (fragment == null) { |
| throw new NullPointerException("fragment"); //$NON-NLS-1$ |
| } |
| this.fragment = fragment; |
| } |
| |
| |
| @Override |
| public ISourceFragment getSourceFragment() { |
| return this.fragment; |
| } |
| |
| @Override |
| public ImageDescriptor getImageDescriptor() { |
| return RDebugUIPlugin.getInstance().getImageRegistry().getDescriptor( |
| RDebugUIPlugin.IMG_OBJ_R_SOURCE_FROM_RUNTIME ); |
| } |
| |
| @Override |
| public String getName() { |
| return this.fragment.getName(); |
| } |
| |
| @Override |
| public boolean exists() { |
| return !this.fragment.getProcess().isTerminated(); |
| } |
| |
| @Override |
| public String getToolTipText() { |
| return this.fragment.getFullName() + '\n' + this.fragment.getProcess().getLabel(Tool.LONG_LABEL); |
| } |
| |
| @Override |
| public IPersistableElement getPersistable() { |
| return null; |
| } |
| |
| |
| @Override |
| @SuppressWarnings("unchecked") |
| public <T> T getAdapter(final Class<T> adapterType) { |
| if (adapterType == ToolProcess.class) { |
| return (T) this.fragment.getProcess(); |
| } |
| return null; |
| } |
| |
| @Override |
| public int hashCode() { |
| return this.fragment.hashCode(); |
| } |
| |
| @Override |
| public boolean equals(final Object obj) { |
| if (this == obj) { |
| return true; |
| } |
| if (!(obj instanceof RRuntimeSourceEditorInput)) { |
| return false; |
| } |
| final RRuntimeSourceEditorInput other = (RRuntimeSourceEditorInput) obj; |
| return this.fragment.equals(other.fragment); |
| } |
| |
| @Override |
| public String toString() { |
| return this.fragment.getFullName() + " - " + this.fragment.getProcess().getLabel(Tool.LONG_LABEL); //$NON-NLS-1$ |
| } |
| |
| } |