blob: 7270e23dda74244742f0c412f0d15e4ccd6f0904 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2016 GK Software AG, and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Stephan Herrmann - initial API and implementation
*******************************************************************************/
package org.eclipse.objectteams.otdt.internal.samples;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.internal.ui.IHelpContextIds;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.HyperlinkSettings;
import org.eclipse.ui.forms.widgets.ScrolledFormText;
public class ReviewPage extends WizardPage {
private SampleWizard wizard;
private ScrolledFormText formText;
public ReviewPage(SampleWizard wizard) {
super("last"); //$NON-NLS-1$
this.wizard = wizard;
setTitle(Messages.ReviewPage_title);
setDescription(Messages.ReviewPage_desc);
}
@Override
public void setVisible(boolean visible) {
setPageComplete(wizard.getSelection() != null);
if (formText != null)
updateContent();
super.setVisible(visible);
}
private void updateContent() {
StringBuffer buf = new StringBuffer();
buf.append("<form>"); //$NON-NLS-1$
IConfigurationElement selection = wizard.getSelection();
if (selection != null) {
setMessage(null);
IConfigurationElement[] desc = selection.getChildren("description"); //$NON-NLS-1$
if (desc.length == 1)
buf.append(NLS.bind(Messages.ReviewPage_descContent, (new String[] {selection.getAttribute("name"), desc[0].getValue()}))); //$NON-NLS-1$
else
buf.append(NLS.bind(Messages.ReviewPage_content, selection.getAttribute("name"))); //$NON-NLS-1$
} else {
setMessage(Messages.ReviewPage_noSampleFound, IMessageProvider.WARNING);
}
buf.append("</form>"); //$NON-NLS-1$
formText.setText(buf.toString());
}
@Override
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
container.setLayout(layout);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
formText = new ScrolledFormText(container, true);
formText.setBackground(parent.getBackground());
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 300;
gd.heightHint = 300;
formText.setLayoutData(gd);
HyperlinkSettings settings = new HyperlinkSettings(parent.getDisplay());
formText.getFormText().setHyperlinkSettings(settings);
setControl(container);
updateContent();
PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.REVIEW);
}
}