Skip to content

Commit

Permalink
Merge pull request #786 from eclipse/785-1
Browse files Browse the repository at this point in the history
Improvements for org.eclipse.birt.report.designer.ui.preview.web #785
  • Loading branch information
ruspl-afed authored Jan 27, 2022
2 parents 1a39e91 + def5a4b commit 5249abe
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ Require-Bundle: org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
org.eclipse.birt.report.engine.emitter.config;bundle-version="2.6.0",
org.eclipse.core.expressions
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.birt.report.designer.ui.actions,
Export-Package: org.eclipse.birt.report.designer.internal.ui.handlers;x-internal:=true,
org.eclipse.birt.report.designer.ui.actions,
org.eclipse.birt.report.designer.ui.preferences,
org.eclipse.birt.report.designer.ui.preview,
org.eclipse.birt.report.designer.ui.preview.editors,
org.eclipse.birt.report.designer.ui.preferences
org.eclipse.birt.report.designer.ui.preview.editors
Bundle-Vendor: Eclipse BIRT Project
Bundle-RequiredExecutionEnvironment: JavaSE-11
Import-Package: com.ibm.icu.util;version="3.4.4"
Expand Down
6 changes: 3 additions & 3 deletions UI/org.eclipse.birt.report.designer.ui.preview.web/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@
</extension>

<extension point="org.eclipse.ui.handlers">
<handler commandId="org.eclipse.birt.report.designer.ui.ide.runReport.command" class="org.eclipse.birt.report.designer.ui.ide.explorer.RunReportHandler"/>
<handler commandId="org.eclipse.birt.report.designer.ui.ide.generateDocument.command" class="org.eclipse.birt.report.designer.ui.ide.explorer.GenerateDocumentHandler"/>
<handler commandId="org.eclipse.birt.report.designer.ui.ide.viewDocument.command" class="org.eclipse.birt.report.designer.ui.ide.explorer.ViewDocumentHandler"/>
<handler commandId="org.eclipse.birt.report.designer.ui.ide.runReport.command" class="org.eclipse.birt.report.designer.internal.ui.handlers.RunReportHandler"/>
<handler commandId="org.eclipse.birt.report.designer.ui.ide.generateDocument.command" class="org.eclipse.birt.report.designer.internal.ui.handlers.GenerateDocumentHandler"/>
<handler commandId="org.eclipse.birt.report.designer.ui.ide.viewDocument.command" class="org.eclipse.birt.report.designer.internal.ui.handlers.ViewDocumentHandler"/>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 Solme AB 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/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Claes Rosell - initial API and implementation
* Alexander Fedorov (ArSysOp) - structural improvements
*******************************************************************************/
package org.eclipse.birt.report.designer.internal.ui.handlers;

import java.util.List;
import java.util.Optional;

import org.eclipse.birt.report.designer.ui.preview.PreviewUtil;
import org.eclipse.birt.report.designer.ui.util.ExceptionUtil;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;

/**
*
* Abstract handler used for all the report file handlers
*
*/
abstract class AbstractFileHandler extends AbstractHandler {

@Override
public final Object execute(ExecutionEvent event) throws ExecutionException {
// FIXME: AF: not sure if we always need to clear properties
PreviewUtil.clearSystemProperties();
Optional<IFile> selected = selectedFile(HandlerUtil.getCurrentStructuredSelection(event));
// it is always true if we formulated the right expression in plugin.xml
if (selected.isPresent()) {
try {
execute(selected.get());
} catch (Exception e) {
ExceptionUtil.handle(e);
// FIXME:AF: do we add any value for user throwing from here?
throw new ExecutionException("Error executing handler", e); //$NON-NLS-1$
}
}
return null;
}

protected Optional<IFile> selectedFile(IStructuredSelection selection) {
List<?> list = selection.toList();
// FIXME: AF: this constraint should go to plugin.xml
if (list.size() != 1) {
return Optional.empty();
}
return list.stream()//
.filter(IFile.class::isInstance)//
.map(IFile.class::cast)//
.findFirst();
}

protected abstract void execute(IFile file) throws Exception;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2004, 2022 Actuate Corporation 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/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Actuate Corporation - initial API and implementation
* Alexander Fedorov (ArSysOp) - structural improvements
*******************************************************************************/

package org.eclipse.birt.report.designer.internal.ui.handlers;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.birt.report.designer.ui.ReportPlugin;
import org.eclipse.birt.report.viewer.utilities.WebViewer;
import org.eclipse.core.resources.IFile;

/**
* The handler to generate report document in navigator view
*/
public final class GenerateDocumentHandler extends AbstractFileHandler {

@Override
protected void execute(IFile file) throws Exception {
// FIXME: AF: this logic could go to another type to be reusable
String url = file.getLocation().toOSString();
Map<String, Object> options = new HashMap<>();
options.put(WebViewer.RESOURCE_FOLDER_KEY, ReportPlugin.getDefault().getResourceFolder(file.getProject()));
options.put(WebViewer.SERVLET_NAME_KEY, WebViewer.VIEWER_DOCUMENT);
WebViewer.display(url, options);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2004, 2022 Actuate Corporation 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/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Actuate Corporation - initial API and implementation
* Alexander Fedorov (ArSysOp) - structural improvements
*******************************************************************************/

package org.eclipse.birt.report.designer.internal.ui.handlers;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.eclipse.birt.report.designer.core.model.SessionHandleAdapter;
import org.eclipse.birt.report.designer.internal.ui.util.UIUtil;
import org.eclipse.birt.report.designer.ui.ReportPlugin;
import org.eclipse.birt.report.model.api.ModuleHandle;
import org.eclipse.birt.report.viewer.utilities.WebViewer;
import org.eclipse.core.resources.IFile;

/**
* The handler to run a report in navigator view
*/
public final class RunReportHandler extends AbstractFileHandler {

@Override
protected void execute(IFile file) throws Exception {
// FIXME: AF: this logic could go to another type to be reusable
String url = file.getLocation().toOSString();
ModuleHandle handle = null;
try {
handle = SessionHandleAdapter.getInstance().getSessionHandle().openDesign(url);
if (!UIUtil.canPreviewWithErrors(handle)) {
return;
}
Map<String, Object> options = new HashMap<>();
options.put(WebViewer.FORMAT_KEY, WebViewer.HTML);
options.put(WebViewer.RESOURCE_FOLDER_KEY,
ReportPlugin.getDefault().getResourceFolder(file.getProject()));
WebViewer.display(url, options);
} finally {
Optional.ofNullable(handle).ifPresent(ModuleHandle::close);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2004, 2022 Actuate Corporation 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/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Actuate Corporation - initial API and implementation
* Alexander Fedorov (ArSysOp) - structural improvements
*******************************************************************************/

package org.eclipse.birt.report.designer.internal.ui.handlers;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.birt.report.designer.ui.ReportPlugin;
import org.eclipse.birt.report.viewer.utilities.WebViewer;
import org.eclipse.core.resources.IFile;

/**
* The handler to view report document in navigator view
*/
public final class ViewDocumentHandler extends AbstractFileHandler {

@Override
protected void execute(IFile file) {
// FIXME: AF: this logic could go to another type to be reusable
String url = file.getLocation().toString();
Map<String, Object> options = new HashMap<>();
options.put(WebViewer.FORMAT_KEY, WebViewer.HTML);
options.put(WebViewer.RESOURCE_FOLDER_KEY, ReportPlugin.getDefault().getResourceFolder(file.getProject()));
WebViewer.display(url, options);
}

}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5249abe

Please sign in to comment.