Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
package com.owlplug.core.components;

import com.owlplug.core.tasks.AbstractTask;
import com.owlplug.core.tasks.SimpleEventListener;
import com.owlplug.core.tasks.TaskExecutionContext;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;

public class BaseTaskFactory {
Expand All @@ -36,11 +34,5 @@ public TaskExecutionContext create(AbstractTask task) {
protected TaskExecutionContext buildContext(AbstractTask task) {
return new TaskExecutionContext(task, taskRunner);
}

protected void notifyListeners(List<SimpleEventListener> listeners) {
for (SimpleEventListener listener : listeners) {
listener.onAction();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@

import com.owlplug.core.components.ApplicationDefaults;
import com.owlplug.core.components.BaseTaskFactory;
import com.owlplug.core.tasks.SimpleEventListener;
import com.owlplug.core.tasks.TaskExecutionContext;
import com.owlplug.core.utils.FileUtils;
import com.owlplug.explore.events.SourceSyncEvent;
import com.owlplug.explore.model.PackageBundle;
import com.owlplug.explore.repositories.RemotePackageRepository;
import com.owlplug.explore.repositories.RemoteSourceRepository;
import com.owlplug.explore.tasks.BundleInstallTask;
import com.owlplug.explore.tasks.SourceSyncTask;
import com.owlplug.plugin.components.PluginTaskFactory;
import java.io.File;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -45,20 +45,20 @@ public class ExploreTaskFactory extends BaseTaskFactory {
private RemoteSourceRepository remoteSourceRepository;
@Autowired
private RemotePackageRepository remotePackageRepository;

private ArrayList<SimpleEventListener> syncSourcesListeners = new ArrayList<>();
@Autowired
private ApplicationEventPublisher publisher;


/**
* Creates a {@link SourceSyncTask} and binds listeners to the success callback.
*
*
* @return
*/
public TaskExecutionContext createSourceSyncTask() {

SourceSyncTask task = new SourceSyncTask(remoteSourceRepository, remotePackageRepository);
task.setOnSucceeded(e -> {
notifyListeners(syncSourcesListeners);
publisher.publishEvent(new SourceSyncEvent());
});
return create(task);
}
Expand All @@ -78,12 +78,4 @@ public TaskExecutionContext createBundleInstallTask(PackageBundle bundle, File t



public void addSyncSourcesListener(SimpleEventListener eventListener) {
syncSourcesListeners.add(eventListener);
}

public void removeSyncSourcesListener(SimpleEventListener eventListener) {
syncSourcesListeners.remove(eventListener);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.owlplug.explore.components.ExploreTaskFactory;
import com.owlplug.explore.controllers.dialogs.InstallStepDialogController;
import com.owlplug.explore.events.RemoteSourceUpdatedEvent;
import com.owlplug.explore.events.SourceSyncEvent;
import com.owlplug.explore.model.PackageBundle;
import com.owlplug.explore.model.RemotePackage;
import com.owlplug.explore.model.search.ExploreFilterCriteria;
Expand Down Expand Up @@ -229,7 +230,6 @@ public void initialize() {
});
lazyLoadBar.setVisible(false);

exploreTaskFactory.addSyncSourcesListener(() -> performPackageSearch());
performPackageSearch();

masonryPane.setHSpacing(5);
Expand Down Expand Up @@ -401,6 +401,11 @@ public void requestLayout() {
scrollPane.requestLayout();
}

@EventListener
private void handle(SourceSyncEvent event) {
FX.run(this::performPackageSearch);
}

@EventListener
private void handle(RemoteSourceUpdatedEvent event) {
FX.run(this::performPackageSearch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
* You should have received a copy of the GNU General Public License
* along with OwlPlug. If not, see <https://www.gnu.org/licenses/>.
*/

package com.owlplug.core.tasks;

import java.util.EventListener;

@FunctionalInterface
public interface SimpleEventListener extends EventListener {
void onAction();
package com.owlplug.explore.events;

/**
* Remote source sync task has completed successfully.
*/
public record SourceSyncEvent() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import com.owlplug.core.components.ApplicationDefaults;
import com.owlplug.core.components.ApplicationPreferences;
import com.owlplug.core.components.BaseTaskFactory;
import com.owlplug.core.tasks.SimpleEventListener;
import com.owlplug.core.tasks.TaskExecutionContext;
import com.owlplug.core.utils.FileUtils;
import com.owlplug.plugin.events.PluginScanEvent;
import com.owlplug.plugin.model.Plugin;
import com.owlplug.plugin.repositories.FileStatRepository;
import com.owlplug.plugin.repositories.PluginFootprintRepository;
Expand All @@ -36,9 +36,9 @@
import com.owlplug.plugin.tasks.PluginScanTask;
import com.owlplug.plugin.tasks.discovery.PluginScanTaskParameters;
import com.owlplug.project.components.ProjectTaskFactory;
import java.util.ArrayList;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

Expand All @@ -64,9 +64,8 @@ public class PluginTaskFactory extends BaseTaskFactory {
private ProjectTaskFactory projectTaskFactory;
@Autowired
private FileStatRepository fileStatRepository;


private ArrayList<SimpleEventListener> scanPluginsListeners = new ArrayList<>();
@Autowired
private ApplicationEventPublisher publisher;

/**
* Creates a {@link PluginScanTask} and binds listeners to the success callback.
Expand Down Expand Up @@ -122,7 +121,7 @@ public TaskExecutionContext createPluginScanTask(String directoryScope, boolean
nativeHostService);

scanTask.setOnSucceeded(scanEvent -> {
notifyListeners(scanPluginsListeners);
publisher.publishEvent(new PluginScanEvent());
TaskExecutionContext lookupTask = projectTaskFactory.createLookupTask();

if (prefs.getBoolean(ApplicationDefaults.SYNC_FILE_STAT_KEY, true)
Expand Down Expand Up @@ -164,12 +163,4 @@ public TaskExecutionContext createPluginRemoveTask(Plugin plugin) {
return create(task);
}

public void addScanPluginsListener(SimpleEventListener eventListener) {
scanPluginsListeners.add(eventListener);
}

public void removeScanPluginsListener(SimpleEventListener eventListener) {
scanPluginsListeners.remove(eventListener);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.owlplug.plugin.controllers.dialogs.ExportDialogController;
import com.owlplug.plugin.controllers.dialogs.NewLinkController;
import com.owlplug.plugin.events.PluginRefreshEvent;
import com.owlplug.plugin.events.PluginScanEvent;
import com.owlplug.plugin.events.PluginUpdateEvent;
import com.owlplug.plugin.model.Plugin;
import com.owlplug.plugin.repositories.PluginRepository;
Expand Down Expand Up @@ -194,8 +195,6 @@ public void initialize() {
pluginService.scanPlugins(false);
});

taskFactory.addScanPluginsListener(this::displayPlugins);

exportButton.setOnAction(e -> {
this.getTelemetryService().event("/Plugins/Export");
exportDialogController.show();
Expand Down Expand Up @@ -234,6 +233,11 @@ public void toggleInfoPaneDisplay() {
pluginInfoPane.setVisible(!pluginInfoPane.isVisible());
}

@EventListener
private void handle(PluginScanEvent event) {
FX.run(this::displayPlugins);
}

@EventListener
private void handle(PluginRefreshEvent event) {
FX.run(this::refresh);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* OwlPlug
* Copyright (C) 2021 Arthur <dropsnorz@gmail.com>
*
* This file is part of OwlPlug.
*
* OwlPlug is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* OwlPlug is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OwlPlug. If not, see <https://www.gnu.org/licenses/>.
*/

package com.owlplug.plugin.events;

/**
* Plugin scan task has completed successfully.
*/
public record PluginScanEvent() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
import com.owlplug.core.components.ApplicationDefaults;
import com.owlplug.core.components.ApplicationPreferences;
import com.owlplug.core.components.BaseTaskFactory;
import com.owlplug.core.tasks.SimpleEventListener;
import com.owlplug.core.tasks.TaskExecutionContext;
import com.owlplug.project.events.ProjectSyncEvent;
import com.owlplug.project.repositories.DawPluginRepository;
import com.owlplug.project.repositories.DawProjectRepository;
import com.owlplug.project.services.PluginLookupService;
import com.owlplug.project.tasks.PluginLookupTask;
import com.owlplug.project.tasks.ProjectSyncTask;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -46,8 +46,8 @@ public class ProjectTaskFactory extends BaseTaskFactory {
private DawProjectRepository projectRepository;
@Autowired
private DawPluginRepository dawPluginRepository;

private ArrayList<SimpleEventListener> syncProjectsListeners = new ArrayList<>();
@Autowired
private ApplicationEventPublisher publisher;

public TaskExecutionContext createSyncTask() {

Expand All @@ -56,7 +56,7 @@ public TaskExecutionContext createSyncTask() {
ProjectSyncTask task = new ProjectSyncTask(projectRepository, directories);
task.setOnSucceeded(e -> {
createLookupTask().scheduleNow();
notifyListeners(syncProjectsListeners);
publisher.publishEvent(new ProjectSyncEvent());
});
return create(task);
}
Expand All @@ -65,16 +65,8 @@ public TaskExecutionContext createLookupTask() {

PluginLookupTask task = new PluginLookupTask(dawPluginRepository, lookupService);
task.setOnSucceeded(e -> {
notifyListeners(syncProjectsListeners);
publisher.publishEvent(new ProjectSyncEvent());
});
return create(task);
}

public void addSyncProjectsListener(SimpleEventListener eventListener) {
syncProjectsListeners.add(eventListener);
}

public void removeSyncProjectsListener(SimpleEventListener eventListener) {
syncProjectsListeners.remove(eventListener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import com.owlplug.core.controllers.BaseController;
import com.owlplug.core.controllers.dialogs.ListDirectoryDialogController;
import com.owlplug.core.ui.FilterableTreeItem;
import com.owlplug.project.components.ProjectTaskFactory;
import com.owlplug.core.utils.FX;
import com.owlplug.project.events.ProjectSyncEvent;
import com.owlplug.project.model.DawProject;
import com.owlplug.project.services.ProjectService;
import com.owlplug.project.ui.ProjectTreeCell;
Expand All @@ -37,6 +38,7 @@
import javafx.util.Callback;
import jfxtras.styles.jmetro.JMetroStyleClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Controller;

@Controller
Expand All @@ -45,8 +47,6 @@ public class ProjectsController extends BaseController {
@Autowired
private ProjectService projectService;
@Autowired
private ProjectTaskFactory projectTaskFactory;
@Autowired
private ListDirectoryDialogController listDirectoryDialogController;
@Autowired
private ProjectInfoController projectInfoController;
Expand All @@ -71,10 +71,6 @@ public void initialize() {
projectService.syncProjects();
});

projectTaskFactory.addSyncProjectsListener(() -> {
refresh();
});

projectTreeViewTabPane.getStyleClass().add(JMetroStyleClass.UNDERLINE_TAB_PANE);

projectTreeView.setCellFactory((Callback<TreeView<Object>, TreeCell<Object>>)
Expand Down Expand Up @@ -125,4 +121,9 @@ public void refresh() {
projectTreeNode.setExpanded(true);

}

@EventListener
private void handle(ProjectSyncEvent event) {
FX.run(this::refresh);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* OwlPlug
* Copyright (C) 2021 Arthur <dropsnorz@gmail.com>
*
* This file is part of OwlPlug.
*
* OwlPlug is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* OwlPlug is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OwlPlug. If not, see <https://www.gnu.org/licenses/>.
*/

package com.owlplug.project.events;

/**
* Project sync or plugin lookup task has completed successfully.
*/
public record ProjectSyncEvent() {
}