/**
* Copyright 2014 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.tools.forge.ui.internal.ext.provider;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import org.eclipse.ui.ide.IDE;
import org.jboss.forge.addon.ui.DefaultUIDesktop;
import org.jboss.forge.addon.ui.UIDesktop;
import org.jboss.tools.forge.ui.internal.ForgeUIPlugin;
/**
* Implementation of the {@link UIDesktop} interface
*
*/
public class ForgeUIDesktop extends DefaultUIDesktop {
private final Shell parent;
public ForgeUIDesktop(Shell parent) {
this.parent = parent;
}
@Override
public void open(File file) throws IOException {
// Open should do the same as edit in Eclipse
edit(file);
}
@Override
public void edit(File file) throws IOException {
IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.toURI());
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
try {
IDE.openEditorOnFileStore(page, fileStore);
} catch (PartInitException e) {
Status status = new Status(IStatus.ERROR, ForgeUIPlugin.PLUGIN_ID,
"Edit File action failed");
ForgeUIPlugin.log(e);
MessageDialog.openError(parent, "Edit File", status.getMessage());
}
}
@Override
public void browse(URI uri) throws IOException {
IWorkbenchBrowserSupport support = PlatformUI.getWorkbench()
.getBrowserSupport();
try {
support.getExternalBrowser().openURL(uri.toURL());
} catch (PartInitException e) {
Status status = new Status(IStatus.ERROR, ForgeUIPlugin.PLUGIN_ID,
"Browser initialization failed");
ForgeUIPlugin.log(e);
MessageDialog.openError(parent, "Browse URL", status.getMessage());
}
}
}