Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* DataCleaner (community edition)
* Copyright (C) 2014 Free Software Foundation, Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.datacleaner.panels;
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.io.File;
import java.util.Arrays;
import javax.inject.Inject;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;
import org.datacleaner.configuration.DataCleanerConfiguration;
import org.datacleaner.extensions.ExtensionPackage;
import org.datacleaner.extensions.ExtensionReader;
import org.datacleaner.user.UserPreferences;
import org.datacleaner.util.ExtensionFilter;
import org.datacleaner.util.IconUtils;
import org.datacleaner.util.ImageManager;
import org.datacleaner.util.WidgetFactory;
import org.datacleaner.util.WidgetUtils;
import org.datacleaner.widgets.Alignment;
import org.datacleaner.widgets.DCFileChooser;
import org.datacleaner.widgets.DCLabel;
import org.datacleaner.widgets.PopupButton;
import org.jdesktop.swingx.VerticalLayout;
import org.jdesktop.swingx.action.OpenBrowserAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Panel for configuring extension packages.
*/
public class ExtensionPackagesPanel extends DCPanel {
private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.getLogger(ExtensionPackagesPanel.class);
private static final ImageManager imageManager = ImageManager.get();
private static final ImageIcon ICON_PLUGIN = imageManager.getImageIcon(IconUtils.PLUGIN);
private static final ImageIcon ICON_ERROR = imageManager.getImageIcon(IconUtils.STATUS_ERROR);
private final UserPreferences _userPreferences;
private final DataCleanerConfiguration _configuration;
@Inject
protected ExtensionPackagesPanel(final DataCleanerConfiguration configuration,
final UserPreferences userPreferences) {
super(WidgetUtils.COLOR_DEFAULT_BACKGROUND);
_configuration = configuration;
_userPreferences = userPreferences;
setLayout(new BorderLayout());
updateComponents();
}
private void updateComponents() {
removeAll();
final PopupButton addExtensionButton =
WidgetFactory.createDefaultPopupButton("Add extension package", IconUtils.ACTION_ADD_DARK);
final JPopupMenu addExtensionMenu = addExtensionButton.getMenu();
final JMenuItem manualInstallMenuItem =
new JMenuItem("Manually install JAR file", imageManager.getImageIcon("images/filetypes/archive.png"));
manualInstallMenuItem.addActionListener(e -> {
final DCFileChooser fileChooser = new DCFileChooser(_userPreferences.getConfiguredFileDirectory());
fileChooser.setMultiSelectionEnabled(true);
fileChooser.setFileFilter(new ExtensionFilter("DataCleaner extension JAR file (.jar)", ".jar"));
final int result = fileChooser.showOpenDialog(ExtensionPackagesPanel.this);
if (result == DCFileChooser.APPROVE_OPTION) {
final File[] files = fileChooser.getSelectedFiles();
final ExtensionReader extensionReader = new ExtensionReader();
final ExtensionPackage extensionPackage = extensionReader.readExternalExtension(files);
extensionPackage.loadDescriptors(_configuration.getEnvironment().getDescriptorProvider());
_userPreferences.addExtensionPackage(extensionPackage);
updateComponents();
}
});
addExtensionMenu.add(manualInstallMenuItem);
final DCPanel listPanel = new DCPanel();
listPanel.setLayout(new VerticalLayout(4));
listPanel.setBorder(new EmptyBorder(0, 10, 10, 0));
for (final ExtensionPackage extensionPackage : _userPreferences.getExtensionPackages()) {
final DCPanel extensionPanel = createExtensionPanel(extensionPackage);
listPanel.add(extensionPanel);
}
listPanel.add(Box.createVerticalStrut(20));
for (final ExtensionPackage extensionPackage : new ExtensionReader().getInternalExtensions()) {
final DCPanel extensionPanel = createExtensionPanel(extensionPackage);
listPanel.add(extensionPanel);
}
final JScrollPane scrollArea = WidgetUtils.scrolleable(listPanel);
scrollArea.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
add(DCPanel.flow(Alignment.RIGHT, addExtensionButton), BorderLayout.NORTH);
add(scrollArea, BorderLayout.CENTER);
updateUI();
}
private DCPanel createExtensionPanel(final ExtensionPackage extensionPackage) {
boolean valid = true;
final File[] files = extensionPackage.getFiles();
if (extensionPackage.isExternal()) {
for (final File file : files) {
if (!file.exists()) {
valid = false;
}
}
}
final DCLabel extensionLabel;
if (valid) {
final ImageIcon extensionIcon = getExtensionIcon(extensionPackage);
final StringBuilder labelBuilder = new StringBuilder();
labelBuilder.append("
");
labelBuilder.append(extensionPackage.getName());
labelBuilder.append("");
final String author = extensionPackage.getAuthor();
if (author != null) {
labelBuilder.append(" By ");
labelBuilder.append(author);
}
final String description = extensionPackage.getDescription();
if (description != null) {
labelBuilder.append(" ");
labelBuilder.append(description);
}
final String version = extensionPackage.getVersion();
if (version != null) {
labelBuilder.append(" Version ");
labelBuilder.append(version);
}
labelBuilder.append("