use internal help browser

This commit is contained in:
Eyck Jentzsch 2022-01-08 18:31:27 +01:00
parent 8119c1a4f3
commit c474ca33d8
7 changed files with 61 additions and 224 deletions

View File

@ -121,7 +121,7 @@
<bindings xmi:id="_95Pfv3NmEeWBq8z1Dv39LA" elementId="com.minres.scviewer.e4.application.keybinding.quit" keySequence="M1+Q" command="_95PfvHNmEeWBq8z1Dv39LA">
<tags>type:user</tags>
</bindings>
<bindings xmi:id="_2-008EhnEeyp3vLifEzGbQ" elementId="com.minres.scviewer.e4.application.keybinding.help" keySequence="F1" command="_lqjIYEYEEeyPM8G0E2EYww"/>
<bindings xmi:id="_2-008EhnEeyp3vLifEzGbQ" elementId="com.minres.scviewer.e4.application.keybinding.help" keySequence="F1" command="_RdUMoHCOEeyub8CfGE1sGA"/>
</bindingTables>
<bindingTables xmi:id="_XullMGVOEeqSQM-A6dw9ig" elementId="com.minres.scviewer.e4.application.bindingtable.window" bindingContext="_95PfunNmEeWBq8z1Dv39LA">
<bindings xmi:id="_95PfwnNmEeWBq8z1Dv39LA" elementId="com.minres.scviewer.e4.application.keybinding.load" keySequence="M1+L" command="_7-AIMJebEeW09eyIbHsdvg">
@ -253,6 +253,9 @@
<snippets xsi:type="basic:Window" xmi:id="_R8mJUEhwEeyp3vLifEzGbQ" elementId="com.minres.scviewer.e4.application.window.web_help" selectedElement="_R8mJUUhwEeyp3vLifEzGbQ" label="SCViewer Web Help" width="800" height="600">
<children xsi:type="basic:Part" xmi:id="_R8mJUUhwEeyp3vLifEzGbQ" elementId="com.minres.scviewer.e4.application.part.container" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.parts.help.HelpBrowser"/>
</snippets>
<snippets xsi:type="basic:Window" xmi:id="_cg-28HClEeyNn6bZ9_VasA" elementId="com.minres.scviewer.e4.application.window.help_content" selectedElement="_cg-28XClEeyNn6bZ9_VasA" label="SCViewer Help Content" width="800" height="600">
<children xsi:type="basic:Part" xmi:id="_cg-28XClEeyNn6bZ9_VasA" elementId="com.minres.scviewer.e4.application.part.container" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.parts.help.HelpBrowser"/>
</snippets>
<commands xmi:id="_95PfvHNmEeWBq8z1Dv39LA" elementId="org.eclipse.ui.file.exit" commandName="Quit Command"/>
<commands xmi:id="_95PfwHNmEeWBq8z1Dv39LA" elementId="com.minres.scviewer.e4.application.open" commandName="Open Command"/>
<commands xmi:id="_95Pfw3NmEeWBq8z1Dv39LA" elementId="org.eclipse.ui.file.save" commandName="Save Command"/>

View File

@ -83,16 +83,14 @@ public class Messages extends NLS {
public static String cursor;
public static String cursor_drag;
public static String cursor_text;
public static String HelpBrowser_0;
public static String HelpBrowser_1;
public static String HelpBrowser_2;
public static String HelpBrowser_3;
public static String HelpBrowser_4;
public static String HelpBrowser_5;
public static String HelpBrowser_7;
public static String HelpBrowser_8;
public static String HelpDialog_0;
public static String HelpDialog_1;
public static String HelpDialog_2;
public static String HelpDialog_3;
public static String HelpDialog_4;
public static String HelpDialog_5;
public static String HelpDialog_6;
public static String HelpDialog_7;
public static String marker;
public static String marker_text;
public static String rel_arrow;

View File

@ -1,15 +1,34 @@
package com.minres.scviewer.e4.application.handlers;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.server.WebappManager;
public class HelpContentsHandler {
@Execute
public void execute() throws Exception {
static final String WINDOW_ID="com.minres.scviewer.e4.application.window.help_content"; //$NON-NLS-1$
@CanExecute
public boolean canExecute(MApplication app) {
return !app.getChildren().stream().filter(e -> e.getElementId().equals(WINDOW_ID)).findFirst().isPresent();
}
@Execute
public void execute(MApplication app, EModelService modelService /*@Named("mdialog01.dialog.0") MDialog dialog*/) {
BaseHelpSystem.ensureWebappRunning();
String helpURL = "http://" //$NON-NLS-1$
+ WebappManager.getHost() + ":" //$NON-NLS-1$
+ WebappManager.getPort() + "/help/index.jsp"; //$NON-NLS-1$
BaseHelpSystem.getHelpBrowser(false).displayURL(helpURL);
}
// BaseHelpSystem.getHelpBrowser(false).displayURL(helpURL);
MWindow newWin = (MWindow)modelService.cloneSnippet(app, WINDOW_ID, null);
final IEclipseContext ctx=app.getContext();
if(ctx.containsKey("help_url"))
ctx.remove("help_url");
ctx.modify("help_url", helpURL);
app.getChildren().add(newWin);
}
}

View File

@ -10,6 +10,7 @@
*******************************************************************************/
package com.minres.scviewer.e4.application.handlers;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.MApplication;
@ -19,15 +20,19 @@ import org.eclipse.e4.ui.workbench.modeling.EModelService;
public class HelpHandler {
static final String WINDOW_ID="com.minres.scviewer.e4.application.window.web_help"; //$NON-NLS-1$
@CanExecute
public boolean canExecute(MApplication app) {
return !app.getChildren().stream().filter(e -> e.getElementId().equals(WINDOW_ID)).findFirst().isPresent();
}
@Execute
public void execute(MApplication app, MWindow window, EModelService modelService /*@Named("mdialog01.dialog.0") MDialog dialog*/) {
public void execute(MApplication app, EModelService modelService /*@Named("mdialog01.dialog.0") MDialog dialog*/) {
MWindow newWin = (MWindow)modelService.cloneSnippet(app, WINDOW_ID, null);
final IEclipseContext ctx=app.getContext();
if(ctx.containsKey("help_url"))
ctx.remove("help_url");
ctx.modify("help_url", "https://minres.github.io/SCViewer/#key-shortcuts");
app.getChildren().add(newWin);
}
}

View File

@ -77,16 +77,14 @@ signal_nan=Signal NaN Value
cursor=Cursor
cursor_drag=dragged Cursor
cursor_text=Cursor Text
HelpBrowser_0=Back
HelpBrowser_1=Forward
HelpBrowser_2=Stop
HelpBrowser_3=Refresh
HelpBrowser_4=Go
HelpBrowser_5=Address
HelpBrowser_7=Error initializing help browser
HelpBrowser_8=An error occurred while initializing the help browser:
HelpDialog_0=Back
HelpDialog_1=Forward
HelpDialog_2=Stop
HelpDialog_3=Refresh
HelpDialog_4=Go
HelpDialog_5=Address
HelpDialog_6=https://minres.github.io/SCViewer/#key-shortcuts
HelpDialog_7=Could not instantiate Browser:
marker=Marker
marker_text=Marker TExt
rel_arrow=Relation arrow

View File

@ -1,177 +0,0 @@
package com.minres.scviewer.e4.application.parts;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import com.minres.scviewer.e4.application.Messages;
public class HelpDialog extends Dialog {
/**
* Create the dialog.
*
* @param parentShell the parent shell
*/
@Inject
public HelpDialog(Shell parentShell) {
super(parentShell);
setShellStyle(getShellStyle() | SWT.MODELESS | SWT.MAX | SWT.BORDER | SWT.TITLE);
setBlockOnOpen(false);
}
@Override
protected boolean isResizable() {
return true;
}
@Override
protected Point getInitialSize() {
return new Point(800, 600);
}
/**
* Create contents of the dialog.
*
* @param parent the parent
* @return the control
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
container.setLayout(gridLayout);
ToolBar toolbar = new ToolBar(container, SWT.NONE);
ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH);
itemBack.setText(Messages.HelpDialog_0);
ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH);
itemForward.setText(Messages.HelpDialog_1);
ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH);
itemStop.setText(Messages.HelpDialog_2);
ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH);
itemRefresh.setText(Messages.HelpDialog_3);
ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH);
itemGo.setText(Messages.HelpDialog_4);
GridData data = new GridData();
data.horizontalSpan = 3;
toolbar.setLayoutData(data);
Label labelAddress = new Label(container, SWT.NONE);
labelAddress.setText(Messages.HelpDialog_5);
final Text location = new Text(container, SWT.BORDER);
data = new GridData();
data.horizontalAlignment = GridData.FILL;
data.horizontalSpan = 2;
data.grabExcessHorizontalSpace = true;
location.setLayoutData(data);
final Browser browser;
try {
browser = new Browser(container, SWT.NONE);
data = new GridData();
// data.widthHint = 800;
// data.heightHint =600;
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.FILL;
data.horizontalSpan = 3;
data.grabExcessHorizontalSpace = true;
data.grabExcessVerticalSpace = true;
browser.setLayoutData(data);
final Label status = new Label(container, SWT.NONE);
data = new GridData(GridData.FILL_HORIZONTAL);
data.horizontalSpan = 2;
status.setLayoutData(data);
final ProgressBar progressBar = new ProgressBar(container, SWT.NONE);
data = new GridData();
data.horizontalAlignment = GridData.END;
progressBar.setLayoutData(data);
/* event handling */
Listener listener = event -> {
ToolItem item = (ToolItem) event.widget;
String string = item.getText();
if (string.equals(Messages.HelpDialog_0))
browser.back();
else if (string.equals(Messages.HelpDialog_1))
browser.forward();
else if (string.equals(Messages.HelpDialog_2))
browser.stop();
else if (string.equals(Messages.HelpDialog_3))
browser.refresh();
else if (string.equals(Messages.HelpDialog_4))
browser.setUrl(location.getText());
};
browser.addProgressListener(new ProgressListener() {
@Override
public void changed(ProgressEvent event) {
if (event.total == 0) return;
int ratio = event.current * 100 / event.total;
progressBar.setSelection(ratio);
}
@Override
public void completed(ProgressEvent event) {
progressBar.setSelection(0);
}
});
browser.addStatusTextListener(event -> status.setText(event.text));
browser.addLocationListener(LocationListener.changedAdapter(event -> {
if (event.top) location.setText(event.location);
}
));
itemBack.addListener(SWT.Selection, listener);
itemForward.addListener(SWT.Selection, listener);
itemStop.addListener(SWT.Selection, listener);
itemRefresh.addListener(SWT.Selection, listener);
itemGo.addListener(SWT.Selection, listener);
location.addListener(SWT.DefaultSelection, e -> browser.setUrl(location.getText()));
browser.setUrl(Messages.HelpDialog_6);
} catch (SWTError e) {
System.out.println(Messages.HelpDialog_7 + e.getMessage());
}
return container;
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
*/
@Override
protected void createButtonsForButtonBar(Composite parent) {
// create OK button
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, true);
}
/**
* Open the dialog.
* @return the result
*/
@PostConstruct
@Override
public int open() {
return super.open();
}
}

View File

@ -4,6 +4,7 @@ import java.io.File;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
@ -48,32 +49,28 @@ public class HelpBrowser {
}
@PostConstruct
protected Control createComposite(Composite container) {
// container.getShell().addListener(SWT.Close, e -> {
// e.doit= false;
// element.setVisible(false);
// });
protected Control createComposite(Composite container, @Named("help_url") String helpUrl) {
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
container.setLayout(gridLayout);
ToolBar toolbar = new ToolBar(container, SWT.NONE);
ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH);
decorateItem(itemBack, Messages.HelpDialog_0, "arrow_undo.png"); //$NON-NLS-1$
decorateItem(itemBack, Messages.HelpBrowser_0, "arrow_undo.png"); //$NON-NLS-1$
ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH);
decorateItem(itemForward, Messages.HelpDialog_1, "arrow_redo.png"); //$NON-NLS-1$
decorateItem(itemForward, Messages.HelpBrowser_1, "arrow_redo.png"); //$NON-NLS-1$
ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH);
decorateItem(itemStop, Messages.HelpDialog_2, "cross.png"); //$NON-NLS-1$
decorateItem(itemStop, Messages.HelpBrowser_2, "cross.png"); //$NON-NLS-1$
ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH);
decorateItem(itemRefresh, Messages.HelpDialog_3, "arrow_refresh.png"); //$NON-NLS-1$
decorateItem(itemRefresh, Messages.HelpBrowser_3, "arrow_refresh.png"); //$NON-NLS-1$
ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH);
decorateItem(itemGo, Messages.HelpDialog_4, "accept.png"); //$NON-NLS-1$
decorateItem(itemGo, Messages.HelpBrowser_4, "accept.png"); //$NON-NLS-1$
GridData data = new GridData();
data.horizontalSpan = 3;
toolbar.setLayoutData(data);
Label labelAddress = new Label(container, SWT.NONE);
labelAddress.setText(Messages.HelpDialog_5);
labelAddress.setText(Messages.HelpBrowser_5);
final Text location = new Text(container, SWT.BORDER);
data = new GridData();
@ -81,10 +78,8 @@ public class HelpBrowser {
data.horizontalSpan = 2;
data.grabExcessHorizontalSpace = true;
location.setLayoutData(data);
final Browser browser;
try {
browser = new Browser(container, SWT.NONE);
final Browser browser = new Browser(container, SWT.NONE);
data = new GridData();
// data.widthHint = 800;
// data.heightHint =600;
@ -109,15 +104,15 @@ public class HelpBrowser {
Listener listener = event -> {
ToolItem item = (ToolItem) event.widget;
String string = (String) item.getData();
if (string.equals(Messages.HelpDialog_0))
if (string.equals(Messages.HelpBrowser_0))
browser.back();
else if (string.equals(Messages.HelpDialog_1))
else if (string.equals(Messages.HelpBrowser_1))
browser.forward();
else if (string.equals(Messages.HelpDialog_2))
else if (string.equals(Messages.HelpBrowser_2))
browser.stop();
else if (string.equals(Messages.HelpDialog_3))
else if (string.equals(Messages.HelpBrowser_3))
browser.refresh();
else if (string.equals(Messages.HelpDialog_4))
else if (string.equals(Messages.HelpBrowser_4))
browser.setUrl(location.getText());
};
browser.addProgressListener(new ProgressListener() {
@ -140,14 +135,10 @@ public class HelpBrowser {
itemRefresh.addListener(SWT.Selection, listener);
itemGo.addListener(SWT.Selection, listener);
location.addListener(SWT.DefaultSelection, e -> browser.setUrl(location.getText()));
browser.setUrl(Messages.HelpDialog_6);
browser.setUrl(helpUrl);
} catch (SWTError e) {
MessageDialog.openWarning(container.getDisplay().getActiveShell(), Messages.HelpBrowser_7,Messages.HelpBrowser_8+e.getMessage());
}
return container;
}
void handleShellCloseEvent(){
}
}