提交 fc599284 编写于 作者: S serge-rider

Opening editor files thru RMI


Former-commit-id: 7ccb43b2
上级 32c1989b
......@@ -107,28 +107,11 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor im
log.warn(e);
}
*/
List<String> filesToOpen = new ArrayList<>();
String[] cliParameters = Platform.getCommandLineArgs();
boolean prevParam = false, prevFile = false;
for (String param : cliParameters) {
if (!param.startsWith("-") && (!prevParam || prevFile)) {
filesToOpen.add(param);
}
prevParam = param.startsWith("-");
prevFile = param.equals("-file");
}
for (String filePath : filesToOpen) {
File file = new File(filePath);
if (file.exists()) {
try {
IEditorDescriptor desc = window.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
IFileStore fileStore = EFS.getStore(file.toURI());
IEditorInput input = new FileStoreEditorInput(fileStore);
IDE.openEditor(window.getActivePage(), input, desc.getId());
} catch (CoreException e) {
log.error("Can't open editor from file '" + file.getAbsolutePath(), e);
}
}
try {
DBeaverApplication.executeCommandLineCommands(DBeaverApplication.getCommandLine(), DBeaverCore.getInstance().getInstanceServer());
} catch (Exception e) {
log.error("Error processing command line", e);
}
}
......
......@@ -17,7 +17,10 @@
*/
package org.jkiss.dbeaver.core.application;
import org.apache.commons.cli.*;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.eclipse.core.runtime.Platform;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
......@@ -30,9 +33,9 @@ import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferenceConstants;
import org.eclipse.ui.PlatformUI;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.IInstanceController;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.IInstanceController;
import org.jkiss.utils.ArrayUtils;
import java.io.File;
......@@ -154,14 +157,17 @@ public class DBeaverApplication implements IApplication
return false;
}
return callRemoteServer(commandLine, controller);
} catch (Throwable e) {
return executeCommandLineCommands(commandLine, controller);
} catch (RemoteException e) {
log.error("Error calling remote server", e);
return true;
} catch (Throwable e) {
log.error("Internal error while calling remote server", e);
return false;
}
}
private boolean callRemoteServer(CommandLine commandLine, IInstanceController controller) throws RemoteException {
public static boolean executeCommandLineCommands(CommandLine commandLine, IInstanceController controller) throws Exception {
String[] files = commandLine.getOptionValues(DBeaverCommandLine.PARAM_FILE);
String[] fileArgs = commandLine.getArgs();
if (!ArrayUtils.isEmpty(files) || !ArrayUtils.isEmpty(fileArgs)) {
......
......@@ -27,6 +27,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.IInstanceController;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.model.data.DBDRegistry;
......@@ -90,6 +91,7 @@ public class DBeaverCore implements DBPApplication {
private final List<IPluginService> activatedServices = new ArrayList<>();
private static boolean disposed = false;
private IInstanceController instanceServer;
public static DBeaverCore getInstance()
{
......@@ -185,7 +187,7 @@ public class DBeaverCore implements DBPApplication {
if (standalone) {
// Start instance server
DBeaverInstanceServer.startInstanceServer();
instanceServer = DBeaverInstanceServer.startInstanceServer();
}
QMUtils.initApplication(this);
......@@ -288,6 +290,7 @@ public class DBeaverCore implements DBPApplication {
}
DBeaverInstanceServer.stopInstanceServer();
instanceServer = null;
}
// Remove temp folder
......@@ -317,6 +320,10 @@ public class DBeaverCore implements DBPApplication {
return getProjectRegistry();
}
public IInstanceController getInstanceServer() {
return instanceServer;
}
/**
* Returns configuration file
*/
......
......@@ -18,8 +18,17 @@
package org.jkiss.dbeaver.core;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.ide.IDE;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.IInstanceController;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.IOUtils;
......@@ -47,8 +56,26 @@ public class DBeaverInstanceServer implements IInstanceController {
}
@Override
public void openExternalFiles(String[] fileNames) {
public void openExternalFiles(final String[] fileNames) {
final IWorkbenchWindow window = DBeaverUI.getActiveWorkbenchWindow();
UIUtils.runInUI(window.getShell(), new Runnable() {
@Override
public void run() {
for (String filePath : fileNames) {
File file = new File(filePath);
if (file.exists()) {
try {
IEditorDescriptor desc = window.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
IFileStore fileStore = EFS.getStore(file.toURI());
IEditorInput input = new FileStoreEditorInput(fileStore);
IDE.openEditor(window.getActivePage(), input, desc.getId());
} catch (CoreException e) {
log.error("Can't open editor from file '" + file.getAbsolutePath(), e);
}
}
}
}
});
}
@Override
......@@ -62,7 +89,7 @@ public class DBeaverInstanceServer implements IInstanceController {
System.exit(-1);
}
public static void startInstanceServer() {
public static IInstanceController startInstanceServer() {
DBeaverInstanceServer server = new DBeaverInstanceServer();
try {
......@@ -80,8 +107,10 @@ public class DBeaverInstanceServer implements IInstanceController {
try (OutputStream os = new FileOutputStream(rmiFile)) {
props.store(os, "DBeaver instance server properties");
}
return server;
} catch (Exception e) {
log.error("Can't start RMI server", e);
return null;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册