-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #786 from eclipse/785-1
Improvements for org.eclipse.birt.report.designer.ui.preview.web #785
- Loading branch information
Showing
10 changed files
with
205 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...ew.web/src/org/eclipse/birt/report/designer/internal/ui/handlers/AbstractFileHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...eb/src/org/eclipse/birt/report/designer/internal/ui/handlers/GenerateDocumentHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...eview.web/src/org/eclipse/birt/report/designer/internal/ui/handlers/RunReportHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...ew.web/src/org/eclipse/birt/report/designer/internal/ui/handlers/ViewDocumentHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
54 changes: 0 additions & 54 deletions
54
...iew.web/src/org/eclipse/birt/report/designer/ui/ide/explorer/GenerateDocumentHandler.java
This file was deleted.
Oops, something went wrong.
63 changes: 0 additions & 63 deletions
63
...ui.preview.web/src/org/eclipse/birt/report/designer/ui/ide/explorer/RunReportHandler.java
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
...preview.web/src/org/eclipse/birt/report/designer/ui/ide/explorer/ViewDocumentHandler.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.