blob: b6b41b5937fc31bac5bc10b2cf0317c9076c9ea5 [file] [log] [blame]
/*=============================================================================#
# 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.ui.dataeditor;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.statet.r.ui.dataeditor.RDataTableComposite;
public class FindDialogHandler extends AbstractHandler {
private final IWorkbenchPart fWorkbenchPart;
public FindDialogHandler(final IWorkbenchPart part) {
this.fWorkbenchPart= part;
}
protected RDataTableComposite getTable() {
return this.fWorkbenchPart.getAdapter(RDataTableComposite.class);
}
@Override
public void setEnabled(final Object evaluationContext) {
final RDataTableComposite table= getTable();
setBaseEnabled(table != null);
final IWorkbenchPage page= this.fWorkbenchPart.getSite().getPage();
if (page.getActivePart() == this.fWorkbenchPart) {
final FindDataDialog dialog= FindDataDialog.get(page.getWorkbenchWindow(), false);
if (dialog != null) {
dialog.update(this.fWorkbenchPart);
}
}
}
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final IWorkbenchWindow window= this.fWorkbenchPart.getSite().getWorkbenchWindow();
final FindDataDialog dialog= FindDataDialog.get(window, true);
dialog.update(this.fWorkbenchPart);
dialog.open();
return null;
}
}