blob: ce309da37affcf6f0a0664d28b62a474316b1685 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2010, 2020 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.r.ui.dataeditor;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.statet.jcommons.ts.core.Tool;
import org.eclipse.statet.r.core.model.RElementName;
import org.eclipse.statet.rj.data.RArray;
import org.eclipse.statet.rj.data.RObject;
import org.eclipse.statet.rj.data.RStore;
import org.eclipse.statet.rj.services.FQRObjectRef;
/**
* Editor input of a R data elements in an R process.
*/
public class RLiveDataEditorInput extends PlatformObject implements IRDataEditorInput {
public static boolean isSupported(final RObject element) {
switch (element.getRObjectType()) {
case RObject.TYPE_VECTOR:
case RObject.TYPE_DATAFRAME:
return true;
case RObject.TYPE_ARRAY:
return (((RArray<RStore>) element).getDim().getLength() == 2);
default:
return false;
}
}
private final RToolDataTableInput input;
public RLiveDataEditorInput(final RElementName elementName, final FQRObjectRef elementRef) {
this.input= new RToolDataTableInput(elementName, elementRef);
}
@Override
public ImageDescriptor getImageDescriptor() {
return null;
}
@Override
public String getName() {
return this.input.getName();
}
@Override
public String getToolTipText() {
return NLS.bind("{0} in {1}", this.input.getElementName().getDisplayName(),
this.input.getTool().getLabel(Tool.LONG_LABEL));
}
@Override
public boolean exists() {
return this.input.isAvailable();
}
@Override
public IPersistableElement getPersistable() {
return null;
}
@Override
public RToolDataTableInput getRDataTableInput() {
return this.input;
}
@Override
public int hashCode() {
return this.input.hashCode();
}
@Override
public boolean equals(final Object obj) {
if (!(obj instanceof RLiveDataEditorInput)) {
return false;
}
return (this.input.equals(((RLiveDataEditorInput) obj).input));
}
}