Skip to content

Commit 951d4da

Browse files
committed
New ui for settings, use oauth (in progress)
1 parent ff32d3d commit 951d4da

23 files changed

+1508
-772
lines changed

maven-wrapper/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
<publicPackage>org.yaml.snakeyaml</publicPackage>
142142
<publicPackage>org.apache.http.*</publicPackage>
143143
<publicPackage>org.apache.commons.*</publicPackage>
144+
<publicPackage>org.apache.oltu.oauth2.common.*</publicPackage>
144145
<publicPackage>fi.helsinki.cs.tmc.core.*</publicPackage>
145146
<publicPackage>fi.helsinki.cs.tmc.spyware.*</publicPackage>
146147
<publicPackage>fi.helsinki.cs.tmc.langs.abstraction.*</publicPackage>

tmc-plugin/nbproject/genfiles.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ build.xml.script.CRC32=84aa6cb9
33
build.xml.stylesheet.CRC32=[email protected]
44
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
55
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6-
nbproject/build-impl.xml.data.CRC32=71dc5f8e
6+
nbproject/build-impl.xml.data.CRC32=15b85191
77
nbproject/build-impl.xml.script.CRC32=72a9c69e
88
nbproject/build-impl.xml.stylesheet.CRC32=[email protected]

tmc-plugin/nbproject/project.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@
155155
<specification-version>1.83.1.9</specification-version>
156156
</run-dependency>
157157
</dependency>
158+
<dependency>
159+
<code-name-base>org.netbeans.modules.settings</code-name-base>
160+
<build-prerequisite/>
161+
<compile-dependency/>
162+
<run-dependency>
163+
<release-version>1</release-version>
164+
<specification-version>1.49.1</specification-version>
165+
</run-dependency>
166+
</dependency>
158167
<dependency>
159168
<code-name-base>org.openide.awt</code-name-base>
160169
<build-prerequisite/>

tmc-plugin/src/fi/helsinki/cs/tmc/actions/SaveSettingsAction.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public void actionPerformed(ActionEvent e) {
4646

4747
TmcCoreSettingsImpl settings = (TmcCoreSettingsImpl) TmcSettingsHolder.get();
4848

49-
settings.setUsername(prefUi.getUsername());
50-
settings.setServerBaseUrl(prefUi.getServerBaseUrl());
5149
TmcServerAddressNormalizer.normalize();
5250
settings.setProjectRootDir(prefUi.getProjectDir());
5351
settings.setCheckingForUpdatesInTheBackground(prefUi.getCheckForUpdatesInTheBackground());

tmc-plugin/src/fi/helsinki/cs/tmc/actions/ShowSettingsAction.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@
55
import fi.helsinki.cs.tmc.model.CourseDb;
66
import fi.helsinki.cs.tmc.tailoring.SelectedTailoring;
77
import fi.helsinki.cs.tmc.tailoring.Tailoring;
8+
import fi.helsinki.cs.tmc.tasks.LoginTask;
89
import fi.helsinki.cs.tmc.ui.PreferencesUI;
910
import fi.helsinki.cs.tmc.ui.PreferencesUIFactory;
11+
import fi.helsinki.cs.tmc.utilities.BgTask;
12+
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
13+
import fi.helsinki.cs.tmc.utilities.LoginManager;
1014

1115
import java.awt.event.ActionEvent;
1216
import java.awt.event.ActionListener;
17+
import java.util.logging.Logger;
1318
import javax.swing.AbstractAction;
1419
import org.openide.DialogDescriptor;
1520
import org.openide.awt.ActionRegistration;
1621
import org.openide.awt.ActionReference;
1722
import org.openide.awt.ActionReferences;
1823
import org.openide.awt.ActionID;
24+
import org.openide.util.Exceptions;
1925
import org.openide.util.NbBundle.Messages;
2026

2127
@ActionID(category = "TMC",
@@ -31,6 +37,7 @@ public final class ShowSettingsAction extends AbstractAction {
3137
private SaveSettingsAction saveAction;
3238
private CourseDb courseDb;
3339
private Tailoring tailoring;
40+
private Logger log = Logger.getLogger(ShowSettingsAction.class.getName());
3441

3542
public ShowSettingsAction() {
3643
this.prefUiFactory = PreferencesUIFactory.getInstance();
@@ -41,26 +48,25 @@ public ShowSettingsAction() {
4148

4249
@Override
4350
public void actionPerformed(ActionEvent e) {
44-
run();
51+
if (!LoginManager.loggedIn()) {
52+
BgTask.start("Login window.", new LoginTask());
53+
} else {
54+
run();
55+
}
4556
}
4657

4758
public void run() {
4859
if (prefUiFactory.isPreferencesUiVisible()) {
4960
prefUiFactory.activateVisiblePreferencesUi();
5061
return;
5162
}
52-
63+
5364
final PreferencesUI prefUI = prefUiFactory.createCurrentPreferencesUI();
5465

5566
TmcCoreSettingsImpl settings = (TmcCoreSettingsImpl) TmcSettingsHolder.get();
56-
prefUI.setUsername(settings.getUsername());
57-
prefUI.setServerBaseUrl(settings.getServerBaseUrl());
5867
prefUI.setProjectDir(settings.getProjectRootDir());
5968
prefUI.setCheckForUpdatesInTheBackground(settings.isCheckingForUpdatesInTheBackground());
6069
prefUI.setCheckForUnopenedExercisesAtStartup(settings.isCheckingForUnopenedAtStartup());
61-
prefUI.setAvailableCourses(courseDb.getAvailableCourses());
62-
prefUI.setSelectedCourseName(courseDb.getCurrentCourseName());
63-
prefUI.setUsernameFieldName(tailoring.getUsernameFieldName());
6470
prefUI.setSpywareEnabled(settings.isSpywareEnabled());
6571
prefUI.setErrorMsgLocale(settings.getErrorMsgLocale());
6672
prefUI.setResolveProjectDependenciesEnabled(settings.getResolveDependencies());

tmc-plugin/src/fi/helsinki/cs/tmc/actions/TmcModuleInstall.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package fi.helsinki.cs.tmc.actions;
22

33
import fi.helsinki.cs.tmc.core.TmcCore;
4-
import fi.helsinki.cs.tmc.core.communication.TmcServerCommunicationTaskFactory;
54
import fi.helsinki.cs.tmc.core.configuration.TmcSettings;
65
import fi.helsinki.cs.tmc.core.domain.Course;
76
import fi.helsinki.cs.tmc.core.holders.TmcLangsHolder;
87
import fi.helsinki.cs.tmc.core.holders.TmcSettingsHolder;
98
import fi.helsinki.cs.tmc.coreimpl.TmcCoreSettingsImpl;
109
import fi.helsinki.cs.tmc.langs.util.TaskExecutorImpl;
11-
import fi.helsinki.cs.tmc.model.CourseDb;
1210
import fi.helsinki.cs.tmc.spywareLocal.SpywareFacade;
13-
import fi.helsinki.cs.tmc.ui.LoginDialog;
11+
import fi.helsinki.cs.tmc.tasks.LoginTask;
12+
import fi.helsinki.cs.tmc.utilities.BgTask;
1413
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
14+
import fi.helsinki.cs.tmc.utilities.LoginManager;
1515

1616
import java.util.ArrayList;
1717
import java.util.List;
@@ -79,27 +79,29 @@ public void run() {
7979
prefs.putBoolean(PREF_FIRST_RUN, false);
8080
} else {
8181
// Do full refresh.
82-
new RefreshCoursesAction().addDefaultListener(false, true).addListener(new BgTaskListener<List<Course>>() {
83-
@Override
84-
public void bgTaskReady(List<Course> result) {
85-
log.warning("moduleInstall refresh ready");
86-
new CheckForNewExercisesOrUpdates(true, false).run();
87-
if (CheckForUnopenedExercises.shouldRunOnStartup()) {
88-
new CheckForUnopenedExercises().run();
82+
if (LoginManager.loggedIn() && settings.getOrganization() != null && settings.getCurrentCourse().isPresent()) {
83+
new RefreshCoursesAction().addDefaultListener(false, true).addListener(new BgTaskListener<List<Course>>() {
84+
@Override
85+
public void bgTaskReady(List<Course> result) {
86+
log.warning("moduleInstall refresh ready");
87+
new CheckForNewExercisesOrUpdates(true, false).run();
88+
if (CheckForUnopenedExercises.shouldRunOnStartup()) {
89+
new CheckForUnopenedExercises().run();
90+
}
91+
new CheckProjectCount().checkAndNotifyIfOver();
8992
}
90-
new CheckProjectCount().checkAndNotifyIfOver();
91-
}
92-
93-
@Override
94-
public void bgTaskCancelled() {
95-
log.warning("moduleInstall refresh cancelled");
96-
}
97-
98-
@Override
99-
public void bgTaskFailed(Throwable ex) {
100-
log.log(Level.WARNING, "moduleInstall refresh failed ", ex);
101-
}
102-
}).run();
93+
94+
@Override
95+
public void bgTaskCancelled() {
96+
log.warning("moduleInstall refresh cancelled");
97+
}
98+
99+
@Override
100+
public void bgTaskFailed(Throwable ex) {
101+
log.log(Level.WARNING, "moduleInstall refresh failed ", ex);
102+
}
103+
}).run();
104+
}
103105
}
104106
if (!isFirstRun && settings.getSendDiagnostics()) {
105107
new SendDiagnostics().run();
@@ -123,7 +125,7 @@ public void close() {
123125
}
124126

125127
private void doFirstRun() {
126-
new ShowSettingsAction().run();
128+
BgTask.start("First run", new LoginTask());
127129
}
128130

129131
private void doUpdateFromPreviousVersion(SpecificationVersion prevVersion) {

tmc-plugin/src/fi/helsinki/cs/tmc/coreimpl/TmcCoreSettingsImpl.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import fi.helsinki.cs.tmc.tailoring.Tailoring;
1313

1414
import com.google.common.base.Optional;
15+
import fi.helsinki.cs.tmc.core.domain.Organization;
1516
import java.io.IOException;
1617
import java.net.ProxySelector;
1718
import java.nio.file.Path;
@@ -64,7 +65,7 @@ public boolean userDataExists() {
6465

6566
@Override
6667
public Optional<Course> getCurrentCourse() {
67-
return Optional.of(CourseDb.getInstance().getCurrentCourse());
68+
return Optional.fromNullable(CourseDb.getInstance().getCurrentCourse());
6869
}
6970

7071
@Override
@@ -155,15 +156,16 @@ public void setOauthCredentials(OauthCredentials credentials) {
155156
settings.put(PREF_OAUTH_APPLICATION_ID, credentials.getOauthApplicationId());
156157
settings.put(PREF_OAUTH_SECRET, credentials.getOauthSecret());
157158
}
158-
159+
160+
@Override
161+
public String getOrganization() {
162+
return settings.get(PREF_ORGANIZATION, null);
163+
}
164+
159165
@Override
160166
public void setOrganization(String organization) {
161167
settings.put(PREF_ORGANIZATION, organization);
162-
}
163168

164-
@Override
165-
public String getOrganization() {
166-
return settings.get(PREF_ORGANIZATION, null);
167169
}
168170

169171
public static class SavedEvent implements TmcEvent {}
@@ -298,8 +300,12 @@ public Optional<String> getToken() {
298300
}
299301

300302
@Override
301-
public void setToken(String token) {
302-
settings.put(PREF_OAUTH_TOKEN, token);
303+
public void setToken(Optional<String> token) {
304+
if (token.isPresent()) {
305+
settings.put(PREF_OAUTH_TOKEN, token.get());
306+
} else {
307+
settings.remove(PREF_OAUTH_TOKEN);
308+
}
303309
}
304310

305311
private Locale parseLocale(String s, Locale dflt) {

tmc-plugin/src/fi/helsinki/cs/tmc/model/CourseDb.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static class ChangedEvent implements TmcEvent {}
3333
public static final Logger logger = Logger.getLogger(CourseDb.class.getName());
3434
private static CourseDb defaultInstance;
3535

36-
public static CourseDb getInstance() {
36+
public static synchronized CourseDb getInstance() {
3737
if (defaultInstance == null) {
3838
defaultInstance = new CourseDb();
3939
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package fi.helsinki.cs.tmc.tasks;
2+
3+
import fi.helsinki.cs.tmc.core.exceptions.NotLoggedInException;
4+
import fi.helsinki.cs.tmc.utilities.LoginManager;
5+
import java.util.concurrent.Callable;
6+
import java.util.logging.Logger;
7+
import org.openide.util.Exceptions;
8+
9+
public class LoginTask implements Callable<Void> {
10+
private static final Logger log = Logger.getLogger(LoginTask.class.getName());
11+
12+
@Override
13+
public Void call() throws Exception {
14+
log.fine("Showing the login window.");
15+
try {
16+
new LoginManager().login();
17+
} catch (Exception ex) {
18+
throw new NotLoggedInException();
19+
}
20+
return null;
21+
}
22+
23+
}

tmc-plugin/src/fi/helsinki/cs/tmc/ui/Bundle.properties

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,21 @@ LabelledComboBoxPanel.jLabel.text=LabelText
1010
UtilitiesPanel.DownloadBtn.text=Download Exercise
1111
PreferencesPanel.projectFolderTextField.text=
1212
PreferencesPanel.folderChooserBtn.text=Browse
13-
PreferencesPanel.refreshCoursesBtn.text=Refresh list
1413
TestResultPanel.jButton1.text=OK
1514
UnitTestResults.jLabel1.text=Some of the tests failed. Do you want to send exercises?
1615
ProgressPanel.progressLabel.text=jLabel1
1716
ProgressPanel.cancelProgress.text=Cancel
1817
AExerciseList.jLabel1.text=Course
19-
PreferencesPanel.usernameTextField.text=
20-
PreferencesPanel.usernameLabel.text=Username
21-
PreferencesPanel.serverAddressLabel.text=Server address
22-
PreferencesPanel.serverAddressTextField.text=
2318
PreferencesPanel.coursesLabel.text=Current course
24-
PreferencesPanel.adviceLabel.text=Please set [...]
2519
PreferencesPanel.projectFolderLabel.text=Folder for projects
2620
LongTextDisplayPanel.editorPane.contentType=text/html
27-
PreferencesPanel.passwordLabel.text=Password
28-
PreferencesPanel.passwordField.text=
29-
PreferencesPanel.savePasswordCheckBox.text=Save password
30-
PreferencesPanel.courseListReloadingLabel.text=Loading...
3121
DownloadOrUpdateExercisesDialog.downloadButton.text=Download and update
3222
DownloadOrUpdateExercisesDialog.downloadableLabel.text=Exercises to download
3323
DownloadOrUpdateExercisesDialog.updateableLabel.text=Exercises that can be updated
3424
DownloadOrUpdateExercisesDialog.title=Download and update exercises
3525
DownloadOrUpdateExercisesDialog.closeButton.text=Close
3626
LoginDialog.loginButton.text=Log in
3727
LoginDialog.cancelButton.text=Cancel
38-
LoginDialog.savePasswordCheckbox.text=Save password
3928
LoginDialog.titleLabel.text=Log in to TMC
4029
LoginDialog.usernameLabel.text=Username
4130
LoginDialog.passwordLabel.text=Password
@@ -85,3 +74,25 @@ OpenClosedExercisesDialog.completedOrExpiredLabel.text=Completed / expired exerc
8574
OpenClosedExercisesDialog.openExercisesButton.text=Open exercises
8675
OpenClosedExercisesDialog.selectCompletedOrExpiredButton.text=Select all
8776
OpenClosedExercisesDialog.selectUncompletedButton.text=Select all
77+
LoginDialog.changeServerButton.text=Change
78+
LoginDialog.addressLabel.text=https://tmc.mooc.fi
79+
LoginDialog.serverLabel.text=Server
80+
UpdateServerDialog.updateButton.text=Update
81+
UpdateServerDialog.cancelButton.text=Cancel
82+
UpdateServerDialog.serverAddressLabel.text=Server address
83+
UpdateServerDialog.serverAddressField.text=
84+
PreferencesPanel.organizationLabel.text=Organization
85+
PreferencesPanel.changeOrganizationButton.text=Change
86+
OrganizationCard.logo.text=Logo
87+
OrganizationCard.organizationName.text=Name
88+
OrganizationCard.organizationSlug.text=/slug
89+
OrganizationCard.organizationInformation.text=information\nasdasdasd
90+
CourseCard.informationLabel.text=information\nasdasdasd
91+
CourseCard.titleLabel.text=Course title
92+
CourseCard.nameLabel.text=/name
93+
PreferencesPanel.changeCourseButton.text=Change
94+
OrganizationCard.jCheckBox1.text=jCheckBox1
95+
PreferencesPanel.selectedCourseLabel.text=No course selected
96+
PreferencesPanel.loginLabel.text=Not logged in!
97+
PreferencesPanel.logoutButton.text=Logout
98+
PreferencesPanel.selectedOrganizationLabel.text=No organization selected

0 commit comments

Comments
 (0)