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

Merge remote-tracking branch 'origin/devel' into devel

......@@ -253,6 +253,9 @@ command.org.jkiss.dbeaver.core.resultset.grid.columnsFitValue.name=Columns pack:
command.org.jkiss.dbeaver.core.resultset.grid.columnsFitValue.description=Resize columns to fit row values
command.org.jkiss.dbeaver.core.resultset.grid.columnsFitScreen.name=Columns pack: fit screen
command.org.jkiss.dbeaver.core.resultset.grid.columnsFitScreen.description=Resize columns to see maximum information
command.org.jkiss.dbeaver.core.resultset.openWith.name=Open With
command.org.jkiss.dbeaver.core.resultset.openWith.description=Open data in external application
command.org.jkiss.dbeaver.core.resultset.openWith.param.panelId.name=Processor
command.org.jkiss.dbeaver.core.resultset.export.name=Export Resultset ...
command.org.jkiss.dbeaver.core.resultset.export.description=Export result set to file or another table
command.org.jkiss.dbeaver.core.resultset.row.first.name=First row
......
......@@ -342,7 +342,15 @@
id="panelId"
name="%command.org.jkiss.dbeaver.core.resultset.grid.togglePanel.param.panelId.name"
optional="false"
values="org.jkiss.dbeaver.ui.controls.resultset.PanelIdParameterValues">
values="org.jkiss.dbeaver.ui.controls.resultset.ResultSetHandlerTogglePanel$PanelIdParameterValues">
</commandParameter>
</command>
<command id="org.jkiss.dbeaver.core.resultset.openWith" name="%command.org.jkiss.dbeaver.core.resultset.openWith.name" description="%command.org.jkiss.dbeaver.core.resultset.openWith.description" categoryId="org.jkiss.dbeaver.core.rs">
<commandParameter
id="processorId"
name="%command.org.jkiss.dbeaver.core.resultset.openWith.param.processorId.name"
optional="false"
values="org.jkiss.dbeaver.ui.controls.resultset.ResultSetHandlerOpenWith$OpenWithParameterValues">
</commandParameter>
</command>
<command id="org.jkiss.dbeaver.core.resultset.grid.toggleLayout" name="%command.org.jkiss.dbeaver.core.resultset.grid.toggleLayout.name" description="%command.org.jkiss.dbeaver.core.resultset.grid.toggleLayout.description" categoryId="org.jkiss.dbeaver.core.rs"/>
......@@ -1351,6 +1359,13 @@
<handler commandId="org.jkiss.dbeaver.core.resultset.grid.togglePanel" class="org.jkiss.dbeaver.ui.controls.resultset.ResultSetHandlerTogglePanel">
<activeWhen><reference definitionId="org.jkiss.dbeaver.core.ui.resultset.part"/></activeWhen>
</handler>
<handler commandId="org.jkiss.dbeaver.core.resultset.openWith" class="org.jkiss.dbeaver.ui.controls.resultset.ResultSetHandlerOpenWith">
<enabledWhen>
<with variable="activePart">
<test property="org.jkiss.dbeaver.core.resultset.hasData"/>
</with>
</enabledWhen>
</handler>
<handler commandId="org.jkiss.dbeaver.core.resultset.grid.toggleLayout" class="org.jkiss.dbeaver.ui.controls.resultset.ResultSetHandlerMain">
<!--<activeWhen><reference definitionId="org.jkiss.dbeaver.core.ui.resultset.part"/></activeWhen>-->
</handler>
......@@ -2573,6 +2588,10 @@
<menuContribution allPopups="false" locationURI="menu:org.jkiss.dbeaver.core.resultset.panels">
<dynamic id="org.jkiss.dbeaver.core.resultset.panels" class="org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer$PanelsMenuContributor"/>
</menuContribution>
<!-- RSV open-with drop-down menu -->
<menuContribution allPopups="false" locationURI="menu:org.jkiss.dbeaver.core.resultset.openWith">
<dynamic id="org.jkiss.dbeaver.core.resultset.openWith" class="org.jkiss.dbeaver.ui.controls.resultset.ResultSetHandlerOpenWith$OpenWithMenuContributor"/>
</menuContribution>
</extension>
......
......@@ -36,6 +36,7 @@ import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSDataContainer;
import org.jkiss.dbeaver.model.struct.DBSEntityAssociation;
import org.jkiss.dbeaver.ui.controls.resultset.panel.IResultSetPanel;
import java.util.List;
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
* Copyright (C) 2017-2018 Alexander Fedorov (alexander.fedorov@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.controls.resultset;
import org.eclipse.core.commands.IParameterValues;
import java.util.HashMap;
import java.util.Map;
public class PanelIdParameterValues implements IParameterValues {
@Override
public Map<String,String> getParameterValues() {
final Map<String,String> values = new HashMap<>();
for (ResultSetPanelDescriptor pd : ResultSetPresentationRegistry.getInstance().getAllPanels()) {
values.put(pd.getLabel(), pd.getId());
}
return values;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.controls.resultset;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IParameterValues;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.ui.actions.CompoundContributionItem;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.menus.UIElement;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.data.DBDAttributeBinding;
import org.jkiss.dbeaver.model.data.DBDDataFilter;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.runtime.AbstractJob;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.tools.transfer.IDataTransferProcessor;
import org.jkiss.dbeaver.tools.transfer.database.DatabaseProducerSettings;
import org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer;
import org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor;
import org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor;
import org.jkiss.dbeaver.tools.transfer.registry.DataTransferRegistry;
import org.jkiss.dbeaver.tools.transfer.stream.IStreamDataExporter;
import org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings;
import org.jkiss.dbeaver.tools.transfer.stream.StreamTransferConsumer;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.utils.CommonUtils;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* Open results in external application
*/
public class ResultSetHandlerOpenWith extends AbstractHandler implements IElementUpdater {
private static final Log log = Log.getLog(ResultSetHandlerOpenWith.class);
public static final String CMD_OPEN_WITH = "org.jkiss.dbeaver.core.resultset.openWith";
public static final String PARAM_PROCESSOR_ID = "processorId";
public static final String PARAM_ACTIVE_APP = "org.jkiss.dbeaver.core.resultset.openWith.currentApp";
@Override
public Object execute(ExecutionEvent event) throws ExecutionException
{
IResultSetController resultSet = ResultSetHandlerMain.getActiveResultSet(HandlerUtil.getActivePart(event));
if (resultSet == null) {
return null;
}
DataTransferProcessorDescriptor processor = getActiveProcessor(event.getParameter(PARAM_PROCESSOR_ID));
if (processor == null) {
return null;
}
switch (event.getCommand().getId()) {
case CMD_OPEN_WITH:
openResultsWith(resultSet, processor);
break;
}
return null;
}
static DataTransferProcessorDescriptor getActiveProcessor(String processorId) {
if (CommonUtils.isEmpty(processorId)) {
processorId = DBWorkbench.getPlatform().getPreferenceStore().getString(PARAM_ACTIVE_APP);
}
if (CommonUtils.isEmpty(processorId)) {
DataTransferProcessorDescriptor defaultAppProcessor = getDefaultProcessor();
if (defaultAppProcessor != null) {
return defaultAppProcessor;
}
} else {
return DataTransferRegistry.getInstance().getProcessor(processorId);
}
return null;
}
static DataTransferProcessorDescriptor getDefaultProcessor() {
DataTransferProcessorDescriptor defaultAppProcessor = getDefaultAppProcessor();
if (defaultAppProcessor != null) {
return defaultAppProcessor;
}
return null;
}
private static void openResultsWith(IResultSetController resultSet, DataTransferProcessorDescriptor processor) {
ResultSetDataContainerOptions options = new ResultSetDataContainerOptions();
IResultSetSelection rsSelection = resultSet.getSelection();
List<ResultSetRow> rsSelectedRows = rsSelection.getSelectedRows();
if (rsSelectedRows.size() > 1) {
List<Long> selectedRows = new ArrayList<>();
for (ResultSetRow selectedRow : rsSelectedRows) {
selectedRows.add((long) selectedRow.getRowNumber());
}
List<String> selectedAttributes = new ArrayList<>();
for (DBDAttributeBinding attributeBinding : rsSelection.getSelectedAttributes()) {
selectedAttributes.add(attributeBinding.getName());
}
options.setSelectedRows(selectedRows);
options.setSelectedColumns(selectedAttributes);
}
ResultSetDataContainer dataContainer = new ResultSetDataContainer(resultSet.getDataContainer(), resultSet.getModel(), options);
if (dataContainer.getDataSource() == null) {
DBeaverUI.getInstance().showError("Open " + processor.getAppName(), "Not connected to a database");
return;
}
DBPPreferenceStore preferenceStore = DBWorkbench.getPlatform().getPreferenceStore();
String prevActiveApp = preferenceStore.getString(PARAM_ACTIVE_APP);
if (!CommonUtils.equalObjects(prevActiveApp, processor.getFullId())) {
//preferenceStore.setValue(PARAM_ACTIVE_APP, processor.getFullId());
//resultSet.updateEditControls();
//resultSet.getControl().layout(true);
}
AbstractJob exportJob = new AbstractJob("Open " + processor.getAppName()) {
{
setUser(true);
setSystem(false);
}
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
File tempDir = DBWorkbench.getPlatform().getTempFolder(monitor, "data-files");
File tempFile = new File(tempDir, new SimpleDateFormat(
"yyyyMMdd-HHmmss").format(System.currentTimeMillis()) + "." + processor.getAppFileExtension());
tempFile.deleteOnExit();
IDataTransferProcessor processorInstance = processor.getInstance();
if (!(processorInstance instanceof IStreamDataExporter)) {
return Status.CANCEL_STATUS;
}
IStreamDataExporter exporter = (IStreamDataExporter) processorInstance;
StreamTransferConsumer consumer = new StreamTransferConsumer();
StreamConsumerSettings settings = new StreamConsumerSettings();
settings.setOutputEncodingBOM(false);
settings.setOpenFolderOnFinish(false);
settings.setOutputFolder(tempDir.getAbsolutePath());
settings.setOutputFilePattern(tempFile.getName());
Map<Object, Object> properties = new HashMap<>();
for (DBPPropertyDescriptor prop : processor.getProperties()) {
properties.put(prop.getId(), prop.getDefaultValue());
}
// Remove extension property (we specify file name directly)
properties.remove(StreamConsumerSettings.PROP_FILE_EXTENSION);
consumer.initTransfer(dataContainer, settings, processor.isBinaryFormat(), exporter, properties);
DBDDataFilter dataFilter = resultSet.getModel().getDataFilter();
DatabaseTransferProducer producer = new DatabaseTransferProducer(dataContainer, dataFilter);
DatabaseProducerSettings producerSettings = new DatabaseProducerSettings();
producerSettings.setExtractType(DatabaseProducerSettings.ExtractType.SINGLE_QUERY);
producerSettings.setQueryRowCount(false);
producerSettings.setSelectedRowsOnly(true);
producerSettings.setSelectedColumnsOnly(true);
producer.transferData(monitor, consumer, null, producerSettings);
consumer.finishTransfer(monitor, false);
UIUtils.asyncExec(() -> {
if (!UIUtils.launchProgram(tempFile.getAbsolutePath())) {
DBeaverUI.getInstance().showError(
"Open " + processor.getAppName(),
"Can't open " + processor.getAppFileExtension() + " file '" + tempFile.getAbsolutePath() + "'");
}
});
} catch (Exception e) {
DBeaverUI.getInstance().showError("Error opening in " + processor.getAppName(), null, e);
}
return Status.OK_STATUS;
}
};
exportJob.schedule();
}
@Override
public void updateElement(UIElement element, Map parameters) {
// Put processor name in command label
DataTransferProcessorDescriptor processor = getActiveProcessor((String) parameters.get(PARAM_PROCESSOR_ID));
if (processor != null) {
element.setText(processor.getAppName());
if (!CommonUtils.isEmpty(processor.getDescription())) {
element.setTooltip(processor.getDescription());
}
if (processor.getIcon() != null) {
element.setIcon(DBeaverIcons.getImageDescriptor(processor.getIcon()));
}
}
}
private static DataTransferProcessorDescriptor getDefaultAppProcessor() {
List<DataTransferProcessorDescriptor> processors = new ArrayList<>();
for (final DataTransferNodeDescriptor consumerNode : DataTransferRegistry.getInstance().getNodes(DataTransferNodeDescriptor.NodeType.CONSUMER)) {
for (DataTransferProcessorDescriptor processor : consumerNode.getProcessors()) {
if (processor.getAppFileExtension() != null) {
processors.add(processor);
}
}
}
processors.sort(Comparator.comparingInt(DataTransferProcessorDescriptor::getOrder));
return processors.isEmpty() ? null : processors.get(0);
}
public static class OpenWithParameterValues implements IParameterValues {
@Override
public Map<String,String> getParameterValues() {
final Map<String,String> values = new HashMap<>();
for (final DataTransferNodeDescriptor consumerNode : DataTransferRegistry.getInstance().getNodes(DataTransferNodeDescriptor.NodeType.CONSUMER)) {
for (DataTransferProcessorDescriptor processor : consumerNode.getProcessors()) {
if (processor.getAppFileExtension() != null) {
values.put(processor.getAppName(), processor.getFullId());
}
}
}
return values;
}
}
public static class OpenWithMenuContributor extends CompoundContributionItem
{
@Override
protected IContributionItem[] getContributionItems() {
final ResultSetViewer rsv = (ResultSetViewer) ResultSetHandlerMain.getActiveResultSet(
UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart());
if (rsv == null) {
return new IContributionItem[0];
}
return rsv.fillOpenWithMenu().getItems();
}
}
}
......@@ -19,12 +19,15 @@ package org.jkiss.dbeaver.ui.controls.resultset;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IParameterValues;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.menus.UIElement;
import org.jkiss.dbeaver.ui.controls.resultset.panel.ResultSetPanelDescriptor;
import org.jkiss.utils.CommonUtils;
import java.util.HashMap;
import java.util.Map;
/**
......@@ -85,4 +88,17 @@ public class ResultSetHandlerTogglePanel extends AbstractHandler implements IEle
}
}
}
public static class PanelIdParameterValues implements IParameterValues {
@Override
public Map<String,String> getParameterValues() {
final Map<String,String> values = new HashMap<>();
for (ResultSetPanelDescriptor pd : ResultSetPresentationRegistry.getInstance().getAllPanels()) {
values.put(pd.getLabel(), pd.getId());
}
return values;
}
}
}
......@@ -22,6 +22,7 @@ import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.exec.DBCResultSet;
import org.jkiss.dbeaver.ui.controls.resultset.panel.ResultSetPanelDescriptor;
import java.util.ArrayList;
import java.util.Comparator;
......@@ -34,6 +35,7 @@ public class ResultSetPresentationRegistry {
private static final String TAG_PRESENTATION = "presentation"; //NON-NLS-1
private static final String TAG_PANEL = "panel"; //NON-NLS-1
private static final String TAG_OPEN_WITH = "openWith"; //NON-NLS-1
private static ResultSetPresentationRegistry instance;
......
......@@ -79,9 +79,14 @@ import org.jkiss.dbeaver.model.virtual.*;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.runtime.jobs.DataSourceJob;
import org.jkiss.dbeaver.runtime.ui.DBUserInterface;
import org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor;
import org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor;
import org.jkiss.dbeaver.tools.transfer.registry.DataTransferRegistry;
import org.jkiss.dbeaver.ui.*;
import org.jkiss.dbeaver.ui.controls.ToolbarSeparatorContribution;
import org.jkiss.dbeaver.ui.controls.autorefresh.AutoRefreshControl;
import org.jkiss.dbeaver.ui.controls.resultset.panel.IResultSetPanel;
import org.jkiss.dbeaver.ui.controls.resultset.panel.ResultSetPanelDescriptor;
import org.jkiss.dbeaver.ui.controls.resultset.valuefilter.FilterValueEditDialog;
import org.jkiss.dbeaver.ui.controls.resultset.valuefilter.FilterValueEditPopup;
import org.jkiss.dbeaver.ui.controls.resultset.view.EmptyPresentation;
......@@ -1009,6 +1014,44 @@ public class ResultSetViewer extends Viewer
return items;
}
MenuManager fillOpenWithMenu() {
MenuManager openWithMenu = new MenuManager(ActionUtils.findCommandName(ResultSetHandlerOpenWith.CMD_OPEN_WITH));
ResultSetDataContainerOptions options = new ResultSetDataContainerOptions();
ResultSetDataContainer dataContainer = new ResultSetDataContainer(getDataContainer(), getModel(), options);
List<DataTransferProcessorDescriptor> appProcessors = new ArrayList<>();
for (final DataTransferNodeDescriptor consumerNode : DataTransferRegistry.getInstance().getAvailableConsumers(Collections.singleton(dataContainer))) {
for (DataTransferProcessorDescriptor processor : consumerNode.getProcessors()) {
if (processor.getAppFileExtension() != null) {
appProcessors.add(processor);
}
}
}
appProcessors.sort(Comparator.comparingInt(DataTransferProcessorDescriptor::getOrder));
for (DataTransferProcessorDescriptor processor : appProcessors) {
CommandContributionItemParameter params = new CommandContributionItemParameter(
site,
processor.getId(),
ResultSetHandlerOpenWith.CMD_OPEN_WITH,
CommandContributionItem.STYLE_RADIO
);
params.label = processor.getAppName();
if (processor.getIcon() != null) {
params.icon = DBeaverIcons.getImageDescriptor(processor.getIcon());
}
Map<String, Object> parameters = new HashMap<>();
parameters.put(ResultSetHandlerOpenWith.PARAM_PROCESSOR_ID, processor.getFullId());
params.parameters = parameters;
openWithMenu.add(new CommandContributionItem(params));
}
return openWithMenu;
}
private void addDefaultPanelActions() {
panelToolBar.add(new Action("View Menu", DBeaverIcons.getViewMenuImageDescriptor()) {
@Override
......@@ -1241,7 +1284,7 @@ public class ResultSetViewer extends Viewer
"org.jkiss.dbeaver.core.resultset.panels",
ResultSetHandlerMain.CMD_TOGGLE_PANELS,
CommandContributionItem.STYLE_PULLDOWN);
ciParam.label = "Panels";
ciParam.label = CoreMessages.controls_resultset_config_panels;
ciParam.mode = CommandContributionItem.MODE_FORCE_TEXT;
configToolbar.add(new CommandContributionItem(ciParam));
}
......@@ -1261,6 +1304,27 @@ public class ResultSetViewer extends Viewer
{
ToolBarManager addToolbar = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
addToolbar.add(new GroupMarker(TOOLBAR_GROUP_PRESENTATIONS));
/*
if (false) {
CommandContributionItemParameter ciParam = new CommandContributionItemParameter(
site,
"org.jkiss.dbeaver.core.resultset.openWith",
ResultSetHandlerOpenWith.CMD_OPEN_WITH,
CommandContributionItem.STYLE_PULLDOWN);
ciParam.mode = CommandContributionItem.MODE_FORCE_TEXT;
DataTransferProcessorDescriptor activeProcessor = ResultSetHandlerOpenWith.getDefaultProcessor();
if (activeProcessor != null) {
ciParam.label = activeProcessor.getAppName();
ciParam.icon = DBeaverIcons.getImageDescriptor(activeProcessor.getIcon());
}
Map<String, String> params = new HashMap<>();
//params.put(ResultSetHandlerOpenWith.PARAM_PROCESSOR_ID, "stream:stream.xlsx");
ciParam.parameters = params;
addToolbar.add(new CommandContributionItem(ciParam));
}
*/
addToolbar.add(new Separator(TOOLBAR_GROUP_ADDITIONS));
final IMenuService menuService = getSite().getService(IMenuService.class);
if (menuService != null) {
......@@ -2065,6 +2129,7 @@ public class ResultSetViewer extends Viewer
final DBSDataContainer dataContainer = getDataContainer();
if (dataContainer != null && model.hasData()) {
manager.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_EXPORT));
manager.add(fillOpenWithMenu());
}
manager.add(new GroupMarker("results_export"));
manager.add(new GroupMarker(CoreCommands.GROUP_TOOLS));
......
......@@ -15,12 +15,13 @@
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.controls.resultset;
package org.jkiss.dbeaver.ui.controls.resultset.panel;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.ui.controls.resultset.IResultSetPresentation;
/**
* ResultSet panel.
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.controls.resultset;
package org.jkiss.dbeaver.ui.controls.resultset.panel;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.dbeaver.DBException;
......@@ -23,6 +23,8 @@ import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.registry.AbstractContextDescriptor;
import org.jkiss.dbeaver.registry.RegistryConstants;
import org.jkiss.dbeaver.ui.controls.resultset.IResultSetPresentation;
import org.jkiss.dbeaver.ui.controls.resultset.panel.IResultSetPanel;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
......@@ -48,7 +50,7 @@ public class ResultSetPanelDescriptor extends AbstractContextDescriptor {
private final List<String> supportedPresentations = new ArrayList<>();
private final List<String> supportedDataSources = new ArrayList<>();
protected ResultSetPanelDescriptor(IConfigurationElement config) {
public ResultSetPanelDescriptor(IConfigurationElement config) {
super(config);
this.id = config.getAttribute(RegistryConstants.ATTR_ID);
......
......@@ -38,6 +38,7 @@ import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.resultset.*;
import org.jkiss.dbeaver.ui.controls.resultset.panel.IResultSetPanel;
import java.math.BigDecimal;
import java.text.DecimalFormat;
......
......@@ -21,7 +21,6 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
......@@ -37,6 +36,7 @@ import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.resultset.*;
import org.jkiss.dbeaver.ui.controls.resultset.panel.IResultSetPanel;
import org.jkiss.utils.CommonUtils;
import java.util.Collections;
......
......@@ -39,7 +39,7 @@ import org.jkiss.dbeaver.ui.LoadingJob;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.TreeContentProvider;
import org.jkiss.dbeaver.ui.controls.itemlist.DatabaseObjectListControl;
import org.jkiss.dbeaver.ui.controls.resultset.IResultSetPanel;
import org.jkiss.dbeaver.ui.controls.resultset.panel.IResultSetPanel;
import org.jkiss.dbeaver.ui.controls.resultset.IResultSetPresentation;
import org.jkiss.utils.CommonUtils;
......
......@@ -23,7 +23,7 @@ import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.core.CoreCommands;
import org.jkiss.dbeaver.ui.controls.resultset.IResultSetPanel;
import org.jkiss.dbeaver.ui.controls.resultset.panel.IResultSetPanel;
import org.jkiss.dbeaver.ui.controls.resultset.ResultSetHandlerMain;
import org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer;
......
......@@ -18,7 +18,7 @@ package org.jkiss.dbeaver.ui.controls.resultset.panel.valueviewer;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.ui.IWorkbenchPart;
import org.jkiss.dbeaver.ui.controls.resultset.IResultSetPanel;
import org.jkiss.dbeaver.ui.controls.resultset.panel.IResultSetPanel;
import org.jkiss.dbeaver.ui.controls.resultset.ResultSetHandlerMain;
import org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer;
......
......@@ -45,6 +45,7 @@ import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.resultset.*;
import org.jkiss.dbeaver.ui.controls.resultset.panel.IResultSetPanel;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.data.IValueEditor;
import org.jkiss.dbeaver.ui.data.IValueManager;
......
......@@ -735,17 +735,25 @@ public abstract class SQLEditorBase extends BaseTextEditor implements IErrorVisu
isDefaultPartition(partitioner, document.getLineOffset(firstLine))) {
break;
}
} else {
}
{
for (String delim : statementDelimiters) {
final int offset = TextUtils.getOffsetOf(document, firstLine, delim);
if (offset >= 0 && isDefaultPartition(partitioner, offset)) {
break;
startPos = document.getLineOffset(firstLine) + offset;
if (currentPos > startPos) {
break;
} else {
startPos = 0;
}
}
}
}
firstLine--;
}
startPos = document.getLineOffset(firstLine);
if (startPos == 0) {
startPos = document.getLineOffset(firstLine);
}
// Move currentPos at line begin
currentPos = lineOffset;
......
......@@ -10,11 +10,15 @@
description="%dataTransfer.processor.xlsx.description"
icon="icons/excel.png"
label="%dataTransfer.processor.xlsx.name"
binary="true">
binary="true"
appFileExtension="xlsx"
appName="Excel"
order="10">
<propertyGroup label="%dataTransfer.processor.xlsx.propertyGroup.general.label">
<property id="extension" label="%dataTransfer.processor.xlsx.property.extension.label" defaultValue="xlsx"/>
<property id="rownumber" label="%dataTransfer.processor.xlsx.property.rowNumber.name" type="boolean" description="%dataTransfer.processor.xlsx.property.rowNumber.description" defaultValue="yes" required="false"/>
<property id="border" label="%dataTransfer.processor.xlsx.property.border.name" type="string" description="%dataTransfer.processor.xlsx.property.border.description" defaultValue="THIN" required="false" validValues="NONE,THIN,THICK"/>
<property id="extension" label="%dataTransfer.processor.xlsx.property.extension.label" defaultValue="xlsx"/>
<property id="nullString" label="%dataTransfer.processor.xlsx.property.nullString.name" type="string" description="%dataTransfer.processor.xlsx.property.nullString.description" defaultValue="" required="false"/>
<property id="header" label="%dataTransfer.processor.xlsx.property.header.name" type="boolean" description="%dataTransfer.processor.xlsx.property.header.description" defaultValue="true" required="true"/>
<property id="headerfont" label="%dataTransfer.processor.xlsx.property.headerFont.name" type="string" description="%dataTransfer.processor.xlsx.property.headerFont.description" defaultValue="BOLD" required="false" validValues="NONE,BOLD,ITALIC,STRIKEOUT,UNDERLINE"/>
......@@ -52,11 +56,10 @@
<!-- Results viewer status bar additions -->
<menuContribution allPopups="false" locationURI="toolbar:org.jkiss.dbeaver.ui.controls.resultset.status?after=presentations">
<command commandId="org.jkiss.dbeaver.ext.data.office.results.openSpreadsheet" style="push" mode="FORCE_TEXT" label="%command.org.jkiss.dbeaver.ext.data.office.results.openSpreadsheet.toolbar.label"/>
</menuContribution>
<menuContribution allPopups="false" locationURI="popup:org.eclipse.ui.popup.any?after=results_export">
<command commandId="org.jkiss.dbeaver.ext.data.office.results.openSpreadsheet"/>
<command commandId="org.jkiss.dbeaver.core.resultset.openWith" style="push" mode="FORCE_TEXT" label="%command.org.jkiss.dbeaver.ext.data.office.results.openSpreadsheet.toolbar.label">
<parameter name="processorId" value="stream_consumer:stream.xlsx">
</parameter>
</command>
</menuContribution>
</extension>
......
......@@ -29,10 +29,12 @@ import org.jkiss.dbeaver.model.data.DBDAttributeBinding;
import org.jkiss.dbeaver.model.data.DBDDataFilter;
import org.jkiss.dbeaver.model.runtime.AbstractJob;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.tools.transfer.database.DatabaseProducerSettings;
import org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer;
import org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings;
import org.jkiss.dbeaver.tools.transfer.stream.StreamTransferConsumer;
import org.jkiss.dbeaver.tools.transfer.stream.exporter.StreamExporterAbstract;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.resultset.*;
import org.jkiss.utils.CommonUtils;
......@@ -89,12 +91,13 @@ public class OpenSpreadsheetHandler extends AbstractHandler
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
File tempDir = DBeaverCore.getInstance().getTempFolder(monitor, "office-files");
File tempDir = DBWorkbench.getPlatform().getTempFolder(monitor, "office-files");
File tempFile = new File(tempDir,
CommonUtils.escapeFileName(CommonUtils.truncateString(dataContainer.getName(), 32)) +
"." + new SimpleDateFormat("yyyyMMdd-HHmmss").format(System.currentTimeMillis()) + ".xlsx");
tempFile.deleteOnExit();
DataExporterXLSX exporter = new DataExporterXLSX();
StreamExporterAbstract exporter = new DataExporterXLSX();
StreamTransferConsumer consumer = new StreamTransferConsumer();
StreamConsumerSettings settings = new StreamConsumerSettings();
......
......@@ -168,7 +168,10 @@
class="org.jkiss.dbeaver.tools.transfer.stream.exporter.DataExporterHTML"
description="%dataTransfer.processor.html.description"
icon="platform:/plugin/org.jkiss.dbeaver.ui/icons/misc/html.png"
label="%dataTransfer.processor.html.name">
label="%dataTransfer.processor.html.name"
appFileExtension="html"
appName="Web browser"
order="20">
<propertyGroup label="%dataTransfer.processor.html.propertyGroup.general.label">
<property id="extension" label="%dataTransfer.processor.html.property.extension.label" defaultValue="html"/>
<property id="extractImages" label="%dataTransfer.processor.html.property.images.name" type="boolean" description="%dataTransfer.processor.html.property.images.description" defaultValue="true"/>
......
......@@ -27,6 +27,7 @@ import org.jkiss.dbeaver.model.impl.AbstractDescriptor;
import org.jkiss.dbeaver.model.impl.PropertyDescriptor;
import org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor;
import org.jkiss.dbeaver.tools.transfer.IDataTransferProcessor;
import org.jkiss.dbeaver.ui.ProgramInfo;
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;
......@@ -36,21 +37,24 @@ import java.util.List;
/**
* DataTransferProcessorDescriptor
*/
public class DataTransferProcessorDescriptor extends AbstractDescriptor implements DBPRegistryDescriptor<IDataTransferProcessor>
{
public class DataTransferProcessorDescriptor extends AbstractDescriptor implements DBPRegistryDescriptor<IDataTransferProcessor> {
private final DataTransferNodeDescriptor node;
private final String id;
private final ObjectType processorType;
private final List<ObjectType> sourceTypes = new ArrayList<>();
private final String name;
private final String description;
private final String appFileExtension;
private final String appName;
private final int order;
@NotNull
private final DBPImage icon;
private final List<DBPPropertyDescriptor> properties = new ArrayList<>();
private boolean isBinary;
DataTransferProcessorDescriptor(DataTransferNodeDescriptor node, IConfigurationElement config)
{
private transient ProgramInfo program;
DataTransferProcessorDescriptor(DataTransferNodeDescriptor node, IConfigurationElement config) {
super(config);
this.node = node;
this.id = config.getAttribute("id");
......@@ -59,6 +63,9 @@ public class DataTransferProcessorDescriptor extends AbstractDescriptor implemen
this.description = config.getAttribute("description");
this.icon = iconToImage(config.getAttribute("icon"), DBIcon.TYPE_UNKNOWN);
this.isBinary = CommonUtils.getBoolean(config.getAttribute("binary"), false);
this.appFileExtension = config.getAttribute("appFileExtension");
this.appName = config.getAttribute("appName");
this.order = CommonUtils.toInt(config.getAttribute("order"));
for (IConfigurationElement typeCfg : ArrayUtils.safeArray(config.getChildren("sourceType"))) {
sourceTypes.add(new ObjectType(typeCfg.getAttribute("type")));
......@@ -69,24 +76,41 @@ public class DataTransferProcessorDescriptor extends AbstractDescriptor implemen
}
}
public String getId()
{
public String getId() {
return id;
}
public String getName()
{
public String getName() {
return name;
}
public String getDescription()
{
public String getDescription() {
return description;
}
public String getAppFileExtension() {
return appFileExtension;
}
public String getAppName() {
return appName;
}
public ProgramInfo getOpenWithApplication() {
if (program == null) {
if (!CommonUtils.isEmpty(appFileExtension)) {
program = ProgramInfo.getProgram(appFileExtension);
}
}
return program;
}
public int getOrder() {
return order;
}
@NotNull
public DBPImage getIcon()
{
public DBPImage getIcon() {
return icon;
}
......@@ -103,8 +127,7 @@ public class DataTransferProcessorDescriptor extends AbstractDescriptor implemen
return null;
}
boolean appliesToType(Class objectType)
{
boolean appliesToType(Class objectType) {
if (sourceTypes.isEmpty()) {
return true;
}
......@@ -128,8 +151,7 @@ public class DataTransferProcessorDescriptor extends AbstractDescriptor implemen
return false;
}
public IDataTransferProcessor getInstance()
{
public IDataTransferProcessor getInstance() {
try {
processorType.checkObjectClass(IDataTransferProcessor.class);
Class<? extends IDataTransferProcessor> clazz = processorType.getObjectClass(IDataTransferProcessor.class);
......@@ -139,8 +161,7 @@ public class DataTransferProcessorDescriptor extends AbstractDescriptor implemen
}
}
public DataTransferNodeDescriptor getNode()
{
public DataTransferNodeDescriptor getNode() {
return node;
}
......@@ -148,4 +169,7 @@ public class DataTransferProcessorDescriptor extends AbstractDescriptor implemen
return isBinary;
}
public String getFullId() {
return node.getId() + ":" + getId();
}
}
......@@ -109,6 +109,17 @@ public class DataTransferRegistry {
return result;
}
public List<DataTransferNodeDescriptor> getNodes(DataTransferNodeDescriptor.NodeType nodeType)
{
List<DataTransferNodeDescriptor> result = new ArrayList<>();
for (DataTransferNodeDescriptor node : nodes) {
if (node.getNodeType() == nodeType) {
result.add(node);
}
}
return result;
}
public DataTransferNodeDescriptor getNodeByType(Class<? extends IDataTransferNode> type)
{
for (DataTransferNodeDescriptor node : nodes) {
......@@ -140,4 +151,14 @@ public class DataTransferRegistry {
return null;
}
public DataTransferProcessorDescriptor getProcessor(String processorFullId) {
String[] idParts = processorFullId.split(":");
if (idParts.length == 2) {
DataTransferNodeDescriptor node = getNodeById(idParts[0]);
if (node != null) {
return node.getProcessor(idParts[1]);
}
}
return null;
}
}
......@@ -33,9 +33,11 @@ public class ProgramInfo {
private static final Map<String, ProgramInfo> programMap = new HashMap<>();
private final Program program;
private final String fileExtension;
private DBIconBinary image;
public ProgramInfo(Program program) {
public ProgramInfo(Program program, String fileExtension) {
this.fileExtension = fileExtension;
this.program = program;
}
......@@ -43,6 +45,10 @@ public class ProgramInfo {
return program;
}
public String getFileExtension() {
return fileExtension;
}
public DBPImage getImage() {
return image;
}
......@@ -52,20 +58,28 @@ public class ProgramInfo {
{
if (resource instanceof IFile) {
final String fileExtension = CommonUtils.notEmpty(resource.getFileExtension());
ProgramInfo programInfo = programMap.get(fileExtension);
if (programInfo == null) {
Program program = Program.findProgram(fileExtension);
programInfo = new ProgramInfo(program);
if (program != null) {
final ImageData imageData = program.getImageData();
if (imageData != null) {
programInfo.image = new DBIconBinary(program.getName(), imageData);
}
}
programMap.put(fileExtension, programInfo);
if (!CommonUtils.isEmpty(fileExtension)) {
return getProgram(fileExtension);
}
return programInfo.program == null ? null : programInfo;
}
return null;
}
public static ProgramInfo getProgram(String fileExtension)
{
ProgramInfo programInfo = programMap.get(fileExtension);
if (programInfo == null) {
Program program = Program.findProgram(fileExtension);
programInfo = new ProgramInfo(program, fileExtension);
if (program != null) {
final ImageData imageData = program.getImageData();
if (imageData != null) {
programInfo.image = new DBIconBinary(program.getName(), imageData);
}
}
programMap.put(fileExtension, programInfo);
}
return programInfo.program == null ? null : programInfo;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册