-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f04b08
commit 91d19f9
Showing
9 changed files
with
128 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.control.Button?> | ||
<?import javafx.scene.control.Tooltip?> | ||
<?import javafx.scene.layout.HBox?> | ||
<?import org.jabref.gui.fieldeditors.EditorTextArea?> | ||
<?import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView?> | ||
<fx:root xmlns:fx="http://javafx.com/fxml/1" type="HBox" xmlns="http://javafx.com/javafx/8.0.112"> | ||
<EditorTextArea fx:id="textArea" prefHeight="0.0" HBox.hgrow="ALWAYS"/> | ||
<Button disable="${controller.viewModel.validUrlIsNotPresent}" onAction="#openExternalLink" | ||
styleClass="flatButton"> | ||
<graphic> | ||
<MaterialDesignIconView glyphName="OPEN_IN_NEW"/> | ||
</graphic> | ||
<tooltip> | ||
<Tooltip text="%Open"/> | ||
</tooltip> | ||
</Button> | ||
</fx:root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.jabref.gui.fieldeditors; | ||
|
||
import java.util.Optional; | ||
|
||
import javafx.event.ActionEvent; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.Parent; | ||
import javafx.scene.layout.HBox; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.util.ControlHelper; | ||
import org.jabref.model.entry.BibEntry; | ||
|
||
|
||
public class UrlEditor extends HBox implements FieldEditorFX { | ||
|
||
private final String fieldName; | ||
@FXML private UrlEditorViewModel viewModel; | ||
@FXML private EditorTextArea textArea; | ||
private Optional<BibEntry> entry; | ||
|
||
public UrlEditor(String fieldName, DialogService dialogService) { | ||
this.fieldName = fieldName; | ||
this.viewModel = new UrlEditorViewModel(dialogService); | ||
|
||
ControlHelper.loadFXMLForControl(this); | ||
|
||
viewModel.textProperty().bindBidirectional(textArea.textProperty()); | ||
} | ||
|
||
public UrlEditorViewModel getViewModel() { | ||
return viewModel; | ||
} | ||
|
||
@Override | ||
public void bindToEntry(BibEntry entry) { | ||
this.entry = Optional.of(entry); | ||
textArea.bindToEntry(fieldName, entry); | ||
} | ||
|
||
@Override | ||
public Parent getNode() { | ||
return this; | ||
} | ||
|
||
@FXML | ||
private void openExternalLink(ActionEvent event) { | ||
viewModel.openExternalLink(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.jabref.gui.fieldeditors; | ||
|
||
import java.io.IOException; | ||
|
||
import javafx.beans.property.BooleanProperty; | ||
import javafx.beans.property.SimpleBooleanProperty; | ||
import javafx.beans.property.SimpleStringProperty; | ||
import javafx.beans.property.StringProperty; | ||
|
||
import org.jabref.gui.AbstractViewModel; | ||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.desktop.JabRefDesktop; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.logic.net.URLUtil; | ||
import org.jabref.model.strings.StringUtil; | ||
|
||
import org.fxmisc.easybind.EasyBind; | ||
|
||
public class UrlEditorViewModel extends AbstractViewModel { | ||
private StringProperty text = new SimpleStringProperty(""); | ||
private DialogService dialogService; | ||
private BooleanProperty validUrlIsNotPresent = new SimpleBooleanProperty(true); | ||
|
||
public UrlEditorViewModel(DialogService dialogService) { | ||
this.dialogService = dialogService; | ||
|
||
validUrlIsNotPresent.bind( | ||
EasyBind.map(text, input -> StringUtil.isBlank(input) || !URLUtil.isURL(input)) | ||
); | ||
} | ||
|
||
public boolean isValidUrlIsNotPresent() { | ||
return validUrlIsNotPresent.get(); | ||
} | ||
|
||
public BooleanProperty validUrlIsNotPresentProperty() { | ||
return validUrlIsNotPresent; | ||
} | ||
|
||
public StringProperty textProperty() { | ||
return text; | ||
} | ||
|
||
public void openExternalLink() { | ||
if (StringUtil.isBlank(text.get())) { | ||
return; | ||
} | ||
|
||
try { | ||
JabRefDesktop.openBrowser(text.get()); | ||
} catch (IOException ex) { | ||
dialogService.notify(Localization.lang("Unable to open link.")); | ||
} | ||
} | ||
} |