This repository has been archived by the owner on Apr 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
with support for additional help message with links.
- Loading branch information
1 parent
1965575
commit 3292780
Showing
19 changed files
with
315 additions
and
81 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
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
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
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
130 changes: 130 additions & 0 deletions
130
plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/StatusMessageDialog2.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,130 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 Bruno Medeiros and other Contributors. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Bruno Medeiros - initial API and implementation | ||
*******************************************************************************/ | ||
package melnorme.lang.ide.ui.utils; | ||
|
||
|
||
import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull; | ||
|
||
import org.eclipse.jface.dialogs.Dialog; | ||
import org.eclipse.jface.dialogs.IDialogConstants; | ||
import org.eclipse.jface.layout.GridDataFactory; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.graphics.Image; | ||
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.Shell; | ||
|
||
import melnorme.util.swt.SWTFactoryUtil; | ||
import melnorme.util.swt.SWTUtil; | ||
import melnorme.util.swt.components.AbstractWidget; | ||
import melnorme.utilbox.status.StatusException; | ||
|
||
public class StatusMessageDialog2 extends Dialog { | ||
|
||
protected final String title; | ||
|
||
protected final IconAndMessageWidget iconAndMessageWidget; | ||
|
||
public StatusMessageDialog2(Shell shell, String title, StatusException statusMessage) { | ||
super(shell); | ||
assertNotNull(statusMessage); | ||
this.title = title; | ||
this.iconAndMessageWidget = createIconAndMessageWidget(); | ||
this.iconAndMessageWidget.setStatusMessage(statusMessage); | ||
} | ||
|
||
@Override | ||
protected void configureShell(Shell shell) { | ||
super.configureShell(shell); | ||
shell.setText(title); | ||
} | ||
|
||
@Override | ||
protected Control createContents(Composite parent) { | ||
return super.createContents(parent); | ||
} | ||
|
||
@Override | ||
protected Control createDialogArea(Composite parent) { | ||
Composite topControl = (Composite) super.createDialogArea(parent); | ||
GridLayout gridLayout = (GridLayout) topControl.getLayout(); | ||
gridLayout.numColumns = 2; | ||
iconAndMessageWidget.createComponentInlined(topControl); | ||
iconAndMessageWidget.messageControlLayoutData().widthHint = | ||
convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); | ||
|
||
return topControl; | ||
} | ||
|
||
protected IconAndMessageWidget createIconAndMessageWidget() { | ||
return new IconAndMessageWidget(); | ||
} | ||
|
||
public static class IconAndMessageWidget extends AbstractWidget { | ||
|
||
protected StatusException statusMessage; | ||
|
||
protected Label imageControl; | ||
protected Label messageControl; | ||
|
||
public IconAndMessageWidget() { | ||
} | ||
|
||
@Override | ||
public int getPreferredLayoutColumns() { | ||
return 2; | ||
} | ||
|
||
public void setStatusMessage(StatusException statusMessage) { | ||
this.statusMessage = assertNotNull(statusMessage); | ||
} | ||
|
||
@Override | ||
protected void createContents(Composite topControl) { | ||
imageControl = createImageControl(topControl); | ||
createMessageControl(topControl); | ||
} | ||
|
||
protected Label createImageControl(Composite topControl) { | ||
return SWTFactoryUtil.createIconLabel(topControl, getImage(), | ||
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING).create() | ||
); | ||
} | ||
|
||
protected Image getImage() { | ||
return SWTUtil.getImageForSeverity(statusMessage.getSeverity()); | ||
} | ||
|
||
protected void createMessageControl(Composite topControl) { | ||
String message = statusMessage.getMultiLineRender(); | ||
messageControl = SWTFactoryUtil.createLabel(topControl, SWT.WRAP, message, gdGrabAll()); | ||
} | ||
|
||
public GridData messageControlLayoutData() { | ||
assertNotNull(messageControl); | ||
return (GridData) messageControl.getLayoutData(); | ||
} | ||
|
||
@Override | ||
protected void updateWidgetFromInput() { | ||
// immutable widget | ||
} | ||
} | ||
|
||
@Override | ||
protected void createButtonsForButtonBar(Composite parent) { | ||
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); | ||
} | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
plugin_ide.ui/src-lang/melnorme/lang/ide/ui/utils/StatusMessageDialogExt.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,84 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 Bruno Medeiros and other Contributors. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Bruno Medeiros - initial API and implementation | ||
*******************************************************************************/ | ||
package melnorme.lang.ide.ui.utils; | ||
|
||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.events.SelectionAdapter; | ||
import org.eclipse.swt.events.SelectionEvent; | ||
import org.eclipse.swt.program.Program; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Link; | ||
import org.eclipse.swt.widgets.Shell; | ||
|
||
import melnorme.util.swt.SWTFactoryUtil; | ||
import melnorme.utilbox.fields.validation.IDetailsMessage; | ||
import melnorme.utilbox.misc.StringUtil; | ||
import melnorme.utilbox.status.StatusException; | ||
|
||
public class StatusMessageDialogExt extends StatusMessageDialog2 { | ||
|
||
public StatusMessageDialogExt(Shell shell, String title, StatusException statusMessage) { | ||
super(shell, title, statusMessage); | ||
} | ||
|
||
@Override | ||
protected IconAndMessageWidget createIconAndMessageWidget() { | ||
return new IconAndMessageWidgetExt(); | ||
} | ||
|
||
/** | ||
* Extension to {@link IconAndMessageWidget}, allows displaying additional info from {@link IDetailsMessage} | ||
* in a control with links in texts. | ||
*/ | ||
public static class IconAndMessageWidgetExt extends IconAndMessageWidget { | ||
|
||
protected Link helpControl; | ||
|
||
@Override | ||
protected void createMessageControl(Composite topControl) { | ||
super.createMessageControl(topControl); | ||
|
||
if(statusMessage instanceof IDetailsMessage) { | ||
IDetailsMessage detailsMessage = (IDetailsMessage) statusMessage; | ||
createDetailsMessage(topControl, detailsMessage); | ||
} | ||
} | ||
|
||
protected void createDetailsMessage(Composite topControl, IDetailsMessage detailsMessage) { | ||
String additionalMessage = "\n" + detailsMessage.getDetailsMessage(); | ||
|
||
helpControl = SWTFactoryUtil.createLink(topControl, SWT.WRAP, additionalMessage, | ||
gdfFillDefaults().grab(true, true).span(2, 1).create() | ||
); | ||
|
||
helpControl.addSelectionListener(new SelectionAdapter() { | ||
@Override | ||
public void widgetSelected(SelectionEvent e) { | ||
String uri = e.text; | ||
if(uri.startsWith("http")) { | ||
Program.launch(uri); | ||
} else if(uri.startsWith("pref:")) { | ||
String prefId = StringUtil.removeStart("pref:", uri); | ||
WorkbenchUtils.openPreferencePage(helpControl.getShell(), prefId); | ||
} else { | ||
UIOperationsStatusHandler.handleInternalError("Unknown link URI:\n" + uri, null); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public Link getHelpControl() { | ||
return helpControl; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.