Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
Various fixes for fetching editorials and submissions.
Browse files Browse the repository at this point in the history
  • Loading branch information
fornwall committed Jun 2, 2014
1 parent 0b7e61f commit 5c02781
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 127 deletions.
63 changes: 11 additions & 52 deletions src/net/fornwall/eclipsecoder/archive/ArchiveListView.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package net.fornwall.eclipsecoder.archive;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;

import net.fornwall.eclipsecoder.languages.LanguageSupportFactory;
import net.fornwall.eclipsecoder.preferences.EclipseCoderPlugin;
import net.fornwall.eclipsecoder.util.Utilities;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
Expand Down Expand Up @@ -42,7 +37,6 @@
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import org.eclipse.ui.part.ViewPart;
import org.xml.sax.SAXException;

Expand Down Expand Up @@ -82,7 +76,7 @@ protected IStatus run(IProgressMonitor monitor) {
monitor.subTask(Messages.updatingTable);

PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@SuppressWarnings("synthetic-access")//$NON-NLS-1$
@Override
public void run() {
viewer.setInput(listReference.problemStats);
for (int i = 0; i < problemListTable.getColumnCount(); i++) {
Expand Down Expand Up @@ -124,54 +118,20 @@ void createTable(Composite parent) {
@Override
public void widgetSelected(SelectionEvent selectionEvent) {
ProblemStats stats = (ProblemStats) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
if (stats == null) {
return;
if (stats != null) {
new SubmissionListFetcherJob(stats).schedule();
}

Job job = new SubmissionListFetcherJob(stats);
job.setUser(true);
job.schedule();
}
});

MenuItem viewEditorialItem = new MenuItem(rightClickMenu, SWT.PUSH);
viewEditorialItem.setText(Messages.viewMatchEditorial);
viewEditorialItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
final ProblemStats stats = (ProblemStats) ((IStructuredSelection) viewer.getSelection())
.getFirstElement();
try {
// TODO: Cache a bit?
URLConnection c = new URL("http://apps.topcoder.com/wiki/display/tc/Algorithm+Problem+Set+Analysis") //$NON-NLS-1$
.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(c.getInputStream()));
try {
String line;
while ((line = reader.readLine()) != null) {
if (line.contains(stats.contestName)) {
String href = Utilities.getMatch(line, "<a href=\"(.*?)\"", 1); //$NON-NLS-1$
href = href.replaceAll("&amp;", "&");
// jump to the right place directly - older
// problem statements are not formatted this
// way, though it cannot hurt
href += "#" + stats.problemId; //$NON-NLS-1$
PlatformUI
.getWorkbench()
.getBrowserSupport()
.createBrowser(IWorkbenchBrowserSupport.AS_VIEW,
ArchiveListView.class.getCanonicalName(), "", "").openURL( //$NON-NLS-1$ //$NON-NLS-2$
new URL(href));
return;
}
}
} finally {
reader.close();
}
Utilities.showMessageDialog(Messages.noMatchEditorialFound,
Messages.noMatchEditorialFoundDescription);
} catch (Exception e1) {
Utilities.showException(e1);
public void widgetSelected(SelectionEvent event) {
ProblemStats stats = (ProblemStats) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
if (stats != null) {
new MatchEditorialOpenerJob(stats).schedule();
}
}
});
Expand Down Expand Up @@ -219,14 +179,11 @@ public void mouseDoubleClick(MouseEvent mouseEvent) {
return;
}

Job job;
if ((new File(new File(System.getProperty("user.home")), ".enablefetchmarker")).exists()) {
job = new ProblemFetcherJob(stats);
new ProblemFetcherJob(stats).schedule();
} else {
job = new SubmissionListFetcherJob(stats);
new SubmissionListFetcherJob(stats).schedule();
}
job.setUser(true);
job.schedule();
}
});

Expand Down Expand Up @@ -315,10 +272,12 @@ public int compare(Viewer viewer, Object e1, Object e2) {

class ProblemLabelProvider extends LabelProvider implements ITableLabelProvider {

@Override
public Image getColumnImage(Object element, int columnIndex) {
return null;
}

@Override
public String getColumnText(Object element, int columnIndex) {
ProblemStats stats = (ProblemStats) element;
return stats.getFieldString(columnIndex);
Expand Down
74 changes: 74 additions & 0 deletions src/net/fornwall/eclipsecoder/archive/MatchEditorialOpenerJob.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package net.fornwall.eclipsecoder.archive;

import java.net.URL;
import java.net.UnknownHostException;

import javax.security.auth.login.LoginException;

import net.fornwall.eclipsecoder.preferences.EclipseCoderPlugin;
import net.fornwall.eclipsecoder.util.Utilities;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;

public class MatchEditorialOpenerJob extends Job {

private final ProblemStats stats;

public MatchEditorialOpenerJob(ProblemStats stats) {
super(Messages.checkingOutProblem);
this.stats = stats;
setUser(true);
}

@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask(Messages.checkingOutProblem, 100);
try {
monitor.subTask(Messages.loggingIntoProblemArchive);
monitor.worked(10);
ProblemScraper scraper = null;
try {
scraper = new ProblemScraper(EclipseCoderPlugin.tcUserName(), EclipseCoderPlugin.tcPassword());
} catch (LoginException loginProblem) {
return ProblemScraper.createLoginFailedStatus(loginProblem);
} catch (UnknownHostException e) {
return new Status(IStatus.ERROR, EclipseCoderPlugin.PLUGIN_ID, IStatus.OK,
Messages.unableToConnectToTopCoder, e);
}
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
monitor.worked(20);
monitor.subTask(Messages.downloadingPage);

final String url = scraper.getEditorialUrl(stats);
if (url == null) {
Utilities.showMessageDialog(Messages.noMatchEditorialFound, Messages.noMatchEditorialFoundDescription);
} else {
Utilities.runInDisplayThread(new Runnable() {
@Override
public void run() {
try {
PlatformUI
.getWorkbench()
.getBrowserSupport()
.createBrowser(IWorkbenchBrowserSupport.AS_VIEW,
ArchiveListView.class.getCanonicalName(), "", "").openURL( //$NON-NLS-1$ //$NON-NLS-2$
new URL(url));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
return Status.OK_STATUS;
} catch (Exception exc) {
Utilities.showException(exc);
return Status.CANCEL_STATUS;
}
}
}
60 changes: 4 additions & 56 deletions src/net/fornwall/eclipsecoder/archive/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,118 +4,66 @@

public class Messages extends NLS {

private static final String BUNDLE_NAME = "net.fornwall.eclipsecoder.archive.messages"; //$NON-NLS-1$
static {
NLS.initializeMessages("net.fornwall.eclipsecoder.archive.messages", Messages.class); //$NON-NLS-1$
}

public static String checkingOutProblem;

public static String columnNameCategories;

public static String columnNameClassName;

public static String columnNameCoder;

public static String columnNameContestName;

public static String columnNameDate;

public static String columnNameDivision;

public static String columnNameLanguage;

public static String columnNameLevel;

public static String columnNameOne;

public static String columnNamePoints;

public static String columnNameRating;

public static String columnNameSuccessRate;
public static String columnNameThree;
public static String columnNameTwo;

public static String creatingLanguageSupport;
public static String creatingXmlParser;

public static String downloadingPage;

public static String downloadingProblem;

public static String downloadingTestCases;

public static String errorInParsing;

public static String errorInParsingPleaseReport;

public static String failedRetrievingSubmission;

public static String failedToDownloadProblemStats;
public static String failedToRetrieveSubmissionList;

public static String loadingPage;

public static String loggingIn;

public static String loggingIntoProblemArchive;

public static String needToDownloadProblemArchive;

public static String noLanguageSupportFound;

public static String noMatchEditorialFound;

public static String noMatchEditorialFoundDescription;

public static String noSessionIdCheckYourCredentials;
public static String openingConnection;

public static String openingEditor;

public static String openingOutputStream;
public static String parsingDataFeed;

public static String parsingPage;

public static String parsingProblem;

public static String postProcessingSubmission;

public static String retrievingSubmission;
public static String retrievingSubmissionList;

public static String savingToDisk;

public static String selectProblemDescription;

public static String showingSubmissionsForProblem;
public static String solutionNotAvailable;

public static String sSubmission;

public static String sSubmissionToProblem;

public static String submissionNotAvailable;

public static String unableToConnectToTopCoder;

public static String unableToLoginToTopCoder;

public static String updateListActionName;

public static String updatingProblemList;

public static String updatingTable;

public static String useLanguageActionName;

public static String viewMatchEditorial;

public static String viewSubmissionList;

static {
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}

private Messages() {
//
}
}

0 comments on commit 5c02781

Please sign in to comment.