Skip to content

Commit

Permalink
[eclipse] Add menu item for submitting issues.
Browse files Browse the repository at this point in the history
close #577

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Feb 11, 2017
1 parent c10be5d commit 013d7ab
Show file tree
Hide file tree
Showing 15 changed files with 816 additions and 14 deletions.
2 changes: 2 additions & 0 deletions eclipse-sarl/features/io.sarl.ide/feature.xml
Expand Up @@ -231,6 +231,7 @@ tools upon the Eclipse IDE.
<import plugin="org.eclipse.core.filesystem" version="1.6.1" match="greaterOrEqual"/>
<import plugin="org.eclipse.equinox.bidi" version="1.0.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.variables" version="3.3.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.net" version="1.3.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.debug.ui" version="3.11.202" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui.navigator" version="3.6.101" match="greaterOrEqual"/>
<import plugin="org.eclipse.jdt.core" version="3.12.2" match="greaterOrEqual"/>
Expand All @@ -244,6 +245,7 @@ tools upon the Eclipse IDE.
<import plugin="org.eclipse.ui.intro.quicklinks" version="1.0.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui.intro.universal" version="3.3.1" match="greaterOrEqual"/>
<import plugin="org.arakhne.afc.core.vmutils" version="14.0.0" match="greaterOrEqual"/>
<import plugin="com.google.code.gson" version="2.8.0" match="greaterOrEqual"/>
<import plugin="io.sarl.eclipse" version="0.5.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.runtime" version="3.12.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.resources" version="3.11.1" match="greaterOrEqual"/>
Expand Down
5 changes: 4 additions & 1 deletion eclipse-sarl/plugins/io.sarl.eclipse/META-INF/MANIFEST.MF
Expand Up @@ -15,6 +15,7 @@ Require-Bundle: io.sarl.lang.ui;bundle-version="0.5.0";visibility:=reexport,
org.eclipse.core.filesystem;bundle-version="1.6.1",
org.eclipse.equinox.bidi;bundle-version="1.0.0",
org.eclipse.core.variables;bundle-version="3.3.0",
org.eclipse.core.net;bundle-version="1.3.0",
org.eclipse.debug.ui;bundle-version="3.11.202",
org.eclipse.ui.navigator;bundle-version="3.6.101",
org.eclipse.jdt.core;bundle-version="3.12.2",
Expand All @@ -27,7 +28,8 @@ Require-Bundle: io.sarl.lang.ui;bundle-version="0.5.0";visibility:=reexport,
org.eclipse.ui.intro;bundle-version="3.5.2",
org.eclipse.ui.intro.quicklinks;bundle-version="1.0.0",
org.eclipse.ui.intro.universal;bundle-version="3.3.1",
org.arakhne.afc.core.vmutils;bundle-version="14.0.0"
org.arakhne.afc.core.vmutils;bundle-version="14.0.0",
com.google.code.gson;bundle-version="2.8.0"
Bundle-Activator: io.sarl.eclipse.SARLEclipsePlugin
Export-Package: io.sarl.eclipse,
io.sarl.eclipse.buildpath,
Expand All @@ -36,6 +38,7 @@ Export-Package: io.sarl.eclipse,
io.sarl.eclipse.launching.runner,
io.sarl.eclipse.launching.shortcuts,
io.sarl.eclipse.launching.sreproviding;x-friends:="io.sarl.eclipse.tests",
io.sarl.eclipse.log,
io.sarl.eclipse.natures;x-friends:="io.sarl.eclipse.tests",
io.sarl.eclipse.navigator;x-friends:="io.sarl.eclipse.tests",
io.sarl.eclipse.navigator.node;x-friends:="io.sarl.eclipse.tests",
Expand Down
Expand Up @@ -81,3 +81,4 @@ the Eclipse Foundation http://www.eclipse.org, the Xtext library https://eclipse
the Guava Libraries https://code.google.com/p/guava-libraries, and \
the Apache Software Foundation https://www.apache.org.

action.submitIssue=Submit issue to SARL tracker
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion eclipse-sarl/plugins/io.sarl.eclipse/plugin.xml
Expand Up @@ -469,7 +469,7 @@
<extension
point="org.eclipse.ui.intro.quicklinks">
<command
id="org.eclipse.ui.newWizard(newWizardId=io.sarl.eclipse.wizard.newSarlProject)"
id="org.eclipse.ui.newWizard(newWizardId=io.sarl.eclipse.wizard.newSarlProject)"
description="%wizard.description.newSarlProject.long"
label="%wizard.description.newSarlProject.short"
icon="platform:/plugin/org.eclipse.ui.intro.universal/themes/solstice/graphics/icons/ctool/new-project.png">
Expand All @@ -489,4 +489,24 @@
</splashHandlerProductBinding>
</extension>

<!-- Submit Eclipse logs as SARL issue -->
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="menu:help?after=helpEnd">
<command commandId="io.sarl.eclipse.logs.submitIssue"
label="%action.submitIssue"
icon="platform:/plugin/org.eclipse.jdt.ui/icons/full/eview16/errorwarning_tab.png"
style="push">
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.commands">
<command id="io.sarl.eclipse.logs.submitIssue"
name="%action.submitIssue" />
</extension>
<extension point="org.eclipse.ui.handlers">
<handler
class="io.sarl.eclipse.SARLEclipseExecutableExtensionFactory:io.sarl.eclipse.log.SubmitIssueToSarlTrackerHandler"
commandId="io.sarl.eclipse.logs.submitIssue" />
</extension>

</plugin>
Expand Up @@ -141,6 +141,11 @@ public final class SARLEclipseConfig {
*/
public static final String EXTENSION_POINT_PROJECT_SRE_PROVIDER_FACTORY = "projectSREProviderFactory"; //$NON-NLS-1$

/** Filename of the image that may be used at
* the top of the wizard dialog when submiting an issue to the SARL tracker.
*/
public static final String SUBMIT_ISSUE_WIZARD_DIALOG_IMAGE = "icons/sarl_submit_issue_dialog.png"; //$NON-NLS-1$

private SARLEclipseConfig() {
//
}
Expand Down
@@ -0,0 +1,246 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2017 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.eclipse.log;

import java.net.URL;
import java.text.MessageFormat;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.debug.internal.ui.SWTFactory;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.xtext.util.Strings;
import org.osgi.service.prefs.BackingStoreException;

import io.sarl.eclipse.SARLEclipsePlugin;

/**
* Page for entering information on an issue to submit to the SARL tracker.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.5
*/
public class IssueInformationPage extends WizardPage {

/** Preference key that stores the Github login.
*/
public static final String PREFERENCE_LOGIN = IssueInformationPage.class.getName() + ".githubLogin"; //$NON-NLS-1$

private static final char ECHO_CHAR = '*';

private final URL link;

private Text titleField;

private Text descriptionField;

private Text trackerLogin;

private Text trackerPassword;

/** Constructor.
*
* @param link the link to put in the page.
*/
protected IssueInformationPage(URL link) {
super(Messages.IssueInformationPage_0);
this.link = link;
setTitle(Messages.SubmitEclipseLogWizard_0);
}

@Override
public void createControl(Composite parent) {
// create a composite with standard margins and spacing
final Composite composite = new Composite(parent, SWT.NONE);
final GridLayout layout = new GridLayout();
layout.numColumns = 2;
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));

if (this.link != null) {
final Link linkWidget = new Link(composite, SWT.BORDER);
linkWidget.setText(MessageFormat.format(Messages.IssueInformationPage_9, this.link.toString()));
linkWidget.setFont(composite.getFont());
final GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
linkWidget.setLayoutData(gd);
linkWidget.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings("synthetic-access")
@Override
public void widgetSelected(SelectionEvent event) {
try {
final IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser();
browser.openURL(IssueInformationPage.this.link);
final IWizard wizard = IssueInformationPage.this.getWizard();
if (wizard instanceof SubmitEclipseLogWizard) {
final WizardDialog dialog = ((SubmitEclipseLogWizard) wizard).getWizardDialog();
if (dialog != null) {
dialog.close();
}
}
} catch (PartInitException e) {
//
}
}
});
}

SWTFactory.createLabel(composite, Messages.IssueInformationPage_1, 1);
this.titleField = SWTFactory.createSingleText(composite, 1);

SWTFactory.createLabel(composite, Messages.IssueInformationPage_2, 1);
this.descriptionField = SWTFactory.createText(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL, 1);
this.descriptionField.setLayoutData(new GridData(GridData.FILL_BOTH));

SWTFactory.createLabel(composite, Messages.IssueInformationPage_3, 1);
this.trackerLogin = SWTFactory.createSingleText(composite, 1);

SWTFactory.createLabel(composite, Messages.IssueInformationPage_4, 1);
this.trackerPassword = SWTFactory.createSingleText(composite, 1);
this.trackerPassword.setEchoChar(ECHO_CHAR);

//add the listeners now to prevent them from monkeying with initialized settings
this.titleField.addModifyListener((listeningEvent) -> {
updatePageStatus();
});
this.descriptionField.addModifyListener((listeningEvent) -> {
updatePageStatus();
});
this.trackerLogin.addModifyListener((listeningEvent) -> {
updatePageStatus();
});
this.trackerPassword.addModifyListener((listeningEvent) -> {
updatePageStatus();
});

Dialog.applyDialogFont(composite);
setControl(composite);

initFields();
updatePageStatus();
}

/** Replies the title of the issue.
*
* @return the title.
*/
public String getIssueTitle() {
return this.titleField.getText();
}

/** Replies the description of the issue.
*
* @return the description.
*/
public String getIssueDescription() {
return this.descriptionField.getText();
}

/** Replies the Github login.
*
* @return the login.
*/
public String getGithubLogin() {
return this.trackerLogin.getText();
}

/** Replies the Github password.
*
* @return the password.
*/
public String getGithubPassword() {
return this.trackerPassword.getText();
}

/** Set the initial values to the fields.
*/
protected void initFields() {
final IEclipsePreferences prefs = SARLEclipsePlugin.getDefault().getPreferences();
this.trackerLogin.setText(prefs.get(PREFERENCE_LOGIN, "")); //$NON-NLS-1$
}

/** Update the page status and change the "finish" state button.
*/
protected void updatePageStatus() {
final boolean ok;
if (Strings.isEmpty(this.titleField.getText())) {
ok = false;
setMessage(Messages.IssueInformationPage_5, IMessageProvider.ERROR);
} else if (Strings.isEmpty(this.trackerLogin.getText())) {
ok = false;
setMessage(Messages.IssueInformationPage_6, IMessageProvider.ERROR);
} else if (Strings.isEmpty(this.trackerPassword.getText())) {
ok = false;
setMessage(Messages.IssueInformationPage_7, IMessageProvider.ERROR);
} else {
ok = true;
if (Strings.isEmpty(this.descriptionField.getText())) {
setMessage(Messages.IssueInformationPage_8, IMessageProvider.WARNING);
} else {
setMessage(null, IMessageProvider.NONE);
}
}
setPageComplete(ok);
}

/** Invoked when the wizard is closed with the "Finish" button.
*
* @return {@code true} for closing the wizard; {@code false} for keeping it open.
*/
public boolean performFinish() {
final IEclipsePreferences prefs = SARLEclipsePlugin.getDefault().getPreferences();
final String login = this.trackerLogin.getText();
if (Strings.isEmpty(login)) {
prefs.remove(PREFERENCE_LOGIN);
} else {
prefs.put(PREFERENCE_LOGIN, login);
}
try {
prefs.sync();
return true;
} catch (BackingStoreException e) {
ErrorDialog.openError(getShell(), e.getLocalizedMessage(), e.getLocalizedMessage(),
SARLEclipsePlugin.getDefault().createStatus(IStatus.ERROR, e));
return false;
}
}

}

0 comments on commit 013d7ab

Please sign in to comment.