Skip to content

Commit 1757211

Browse files
committed
repairing the vitamins add feature
1 parent 67e5ab7 commit 1757211

File tree

3 files changed

+67
-23
lines changed

3 files changed

+67
-23
lines changed

src/main/java/com/neuronrobotics/bowlerstudio/BowlerStudio.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public void open(URI toOpe) {
351351
}
352352
new Thread(() -> {
353353
boolean wasState = ScriptingEngine.isPrintProgress();
354-
ScriptingEngine.setPrintProgress(false);
354+
//ScriptingEngine.setPrintProgress(false);
355355
for (Iterator<String> iterator = urls.iterator(); iterator.hasNext();) {
356356
String url = iterator.next();
357357

src/main/java/com/neuronrobotics/bowlerstudio/NewVitaminWizardController.java

+65-21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Sample Skeleton for 'newVitaminWizard.fxml' Controller Class
44
*/
55

6+
import java.io.IOException;
7+
import java.net.URISyntaxException;
68
import java.net.URL;
79
import java.util.ArrayList;
810
import java.util.Collections;
@@ -15,6 +17,8 @@
1517
import java.util.stream.Collectors;
1618

1719
import org.kohsuke.github.GHCreateRepositoryBuilder;
20+
import org.kohsuke.github.GHIssueState;
21+
import org.kohsuke.github.GHPullRequest;
1822
import org.kohsuke.github.GHRepository;
1923
import org.kohsuke.github.GitHub;
2024

@@ -178,17 +182,24 @@ void onConfirmAndCreate(ActionEvent event) {
178182
Vitamins.setIsShaft(typeOfVitaminString);
179183
if(isMotor.isSelected())
180184
Vitamins.setIsActuator(typeOfVitaminString);
181-
Vitamins.saveDatabaseForkIfMissing(typeOfVitaminString);
185+
//Vitamins.saveDatabaseForkIfMissing(typeOfVitaminString);
182186

183187
if(newTypeRadio.isSelected()) {
184188
callback.addVitaminType(typeOfVitaminString);
185189
}else
186-
if(!editExisting.isSelected())
190+
if(!editExisting.isSelected()) {
187191
callback.addSizesToMenu(sizeOfVitaminString, typeOfVitaminString);
192+
}
188193
} catch (Exception e1) {
189194
// Auto-generated catch block
190195
new IssueReportingExceptionHandler().uncaughtException(Thread.currentThread(), e1);
191196
}
197+
try {
198+
Vitamins.saveDatabase(typeOfVitaminString);
199+
} catch (Exception e) {
200+
// TODO Auto-generated catch block
201+
e.printStackTrace();
202+
}
192203
try {
193204
BowlerStudio.runLater(() -> {
194205
this.primaryStage.close();
@@ -200,11 +211,47 @@ void onConfirmAndCreate(ActionEvent event) {
200211
new IssueReportingExceptionHandler().uncaughtException(Thread.currentThread(), e);
201212

202213
}
203-
Vitamins.clear();
214+
org.kohsuke.github.GitHub github = PasswordManager.getGithub();
215+
216+
GHRepository repo;
217+
try {
218+
repo = github.getRepository(Vitamins.getSourcerepo()+ "/Hardware-Dimensions");
219+
String head = PasswordManager.getUsername() + ":master";
220+
List<GHPullRequest> asList = repo.queryPullRequests().state(GHIssueState.OPEN).head(head).list().asList();
221+
if (asList.size() == 0) {
222+
com.neuronrobotics.sdk.common.Log.error("Creating PR for " + head);
223+
GHPullRequest request = repo.createPullRequest("User Added vitamins to " + typeOfVitaminString, head, "master",
224+
"## User added vitamins", true, true);
225+
try {
226+
BowlerKernel.upenURL(request.getHtmlUrl().toURI());
227+
} catch (URISyntaxException e) {
228+
// Auto-generated catch block
229+
e.printStackTrace();
230+
}
231+
} else {
232+
233+
}
234+
} catch (Exception e) {
235+
// TODO Auto-generated catch block
236+
e.printStackTrace();
237+
}
238+
204239
}).start();
205240

206241
}
242+
private void saveAndFork() {
243+
244+
try {
245+
Vitamins.saveDatabaseForkIfMissing(typeOfVitaminString,PasswordManager.getUsername() );
246+
247+
} catch (Exception e) {
248+
// Auto-generated catch block
249+
new IssueReportingExceptionHandler().uncaughtException(Thread.currentThread(), e);
250+
251+
}
252+
207253

254+
}
208255
@FXML
209256
void onConfirmSize(ActionEvent event) {
210257
if(!editExisting.isSelected()) {
@@ -318,6 +365,10 @@ void onConfirmSize(ActionEvent event) {
318365
) {
319366
setUpVitaminDefaults();
320367
}
368+
BowlerStudio.runLater(()->{
369+
sizePane.setDisable(true);
370+
typePane.setDisable(true);
371+
});
321372
//new Thread(() -> {
322373
HashMap<String, Object> required = new HashMap<String, Object>();
323374
required.put("massKg", 0.001);
@@ -327,10 +378,11 @@ void onConfirmSize(ActionEvent event) {
327378
required.put("massCentroidY", 0.0);
328379
required.put("massCentroidZ", 0.0);
329380
setRequiredFields(required);
381+
BowlerStudio.runLater(()->{
382+
measurmentPane.setDisable(false);
383+
});
330384
//}).start();
331-
sizePane.setDisable(true);
332-
measurmentPane.setDisable(false);
333-
typePane.setDisable(true);
385+
334386
}
335387

336388
private void setUpVitaminDefaults() {
@@ -423,10 +475,10 @@ void onConfirmType(ActionEvent event) {
423475
typeOfVitaminString=slug;
424476
sizeComboBox.setDisable(true);
425477
editExisting.setDisable(true);
426-
saveAndFork();
478+
sizePane.setDisable(false);//saveAndFork();
427479
}else {
428480
typeOfVitaminString=typeComboBox.getSelectionModel().getSelectedItem();
429-
saveAndFork();
481+
sizePane.setDisable(false);//saveAndFork();
430482
ArrayList<String> sizes = Vitamins.listVitaminSizes(typeOfVitaminString);
431483
boolean hasSize=false;
432484

@@ -457,19 +509,7 @@ void onConfirmType(ActionEvent event) {
457509

458510
}
459511

460-
private void saveAndFork() {
461-
new Thread(() -> {
462-
try {
463-
Vitamins.saveDatabaseForkIfMissing(typeOfVitaminString);
464-
sizePane.setDisable(false);
465-
} catch (Exception e) {
466-
// Auto-generated catch block
467-
new IssueReportingExceptionHandler().uncaughtException(Thread.currentThread(), e);
468-
469-
}
470-
}).start();
471512

472-
}
473513

474514

475515
@FXML
@@ -574,6 +614,7 @@ void initialize() {
574614
typeComboBox.getSelectionModel().select(typeOfVitaminString);
575615
isShaft.setDisable(false);
576616
isMotor.setDisable(false);
617+
577618
}
578619

579620
public static void launchWizard(INewVitaminCallback callback) throws Exception {
@@ -583,11 +624,14 @@ public static void launchWizard(INewVitaminCallback callback) throws Exception {
583624
primaryStage = s;
584625
new Thread(() -> {
585626
NewVitaminWizardController controller = new NewVitaminWizardController();
586-
587627
try {
628+
SplashManager.renderSplashFrame(0, "Creating personal Fork Of Vitamins");
629+
controller.saveAndFork();
630+
SplashManager.closeSplash();
588631
controller.start(s);
589632
} catch (Exception e) {
590633
e.printStackTrace();
634+
SplashManager.closeSplash();
591635
}
592636
}).start();
593637
});

0 commit comments

Comments
 (0)