import javax.xml.parsers.ParserConfigurationException;
import java.util.Enumeration;
+
+import org.eclipse.ui.console.MessageConsoleStream;
+import org.tizen.common.ui.view.console.ConsoleManager;
import org.tizen.common.util.FileUtil;
import org.tizen.common.util.HostUtil;
import org.tizen.nativeplatform.password.SudoPasswdManager;
import org.tizen.nativeplatform.pkgmgr.PackageManagerOuputReceiver;
import org.tizen.nativeplatform.pkgmgr.model.Package;
import org.tizen.sdblib.IDevice;
+import org.tizen.sdblib.SyncService;
+import org.tizen.sdblib.SyncService.SyncResult;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
e.printStackTrace();
}
}
+
+ public static void InstallLocalPkgToDevice(ArrayList<String> fileList, IDevice device) {
+ actionBeforeUseZypperDevice(device);
+
+ try {
+ // copy
+ ArrayList<String> fileListOnDevice = new ArrayList<String>();
+ for (String filePath : fileList) {
+ String filename = new File(filePath).getName();
+ String pathOnDevice = "/tmp/" + filename;
+ SyncService syncService = device.getSyncService();
+ SyncResult syncResult = syncService.pushFile(filePath, pathOnDevice, SyncService.getNullProgressMonitor());
+ if (syncResult.getCode() != SyncService.RESULT_OK) {
+ continue;
+ }
+ fileListOnDevice.add(pathOnDevice);
+ }
+
+ // set update mode
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
+ rec.cleanLog();
+ if (!device.isEmulator()) {
+ RPMPackageCommander.changeUpdateModeForDevice(device, rec);
+ }
+
+ // install
+ String command = String.format("%s;%s", getResetDbCmd(), getInstallLocalPkgCmdWithRPM(fileListOnDevice));
+ device.executeShellCommand(command, rec, MAX_TIMEOUT);
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ }
+
+
public static Document InstallPkgWithZypperXmlOut(String path, String pkgs, boolean refresh, boolean force) {
String log = "";
if (refresh) {
}
}
+
+ public static void uninstallPkgFromDevice(CopyOnWriteArrayList<Package> pkgList, IDevice device) {
+ try {
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
+ String command = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(), getUninstallPkgCmd(pkgList));
+ rec.cleanLog();
+ device.executeShellCommand(command, rec, MAX_TIMEOUT);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
public static void UninstallPkgFromRootstrapNoDeps(String fileList, String path) {
String cmd = String.format("%s;%s", getResetDbCmd(), getUninstallPkgCmdNoDeps(fileList));
}
- public static void InstallPkgToDevice(String fileList, IDevice device, PackageManagerOuputReceiver rec) {
-
- if (device != null) {
- try {
- String command = String.format("%s;%s", getResetDbCmd(), getInstallLocalPkgCmdWithRPM(fileList));
- device.executeShellCommand(command, rec, MAX_TIMEOUT);
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- }
- }
-
public static String getArchForFile(String filePath) {
return HostUtil.returnExecute(getQueryInfoCmd("ARCH", filePath));
}
packageHash.put(name, new Package(name,version,"",arch));
}
else {
- // do nothing
+ pkg.setInstalledVersion(version);
+ }
+ }
+ }
+ } catch (Exception e) {
+ // do nothing
+ }
+
+ Enumeration<Package> e = packageHash.elements();
+ while(e.hasMoreElements()) {
+ packageList.add(e.nextElement());
+ }
+
+ return packageList;
+ }
+
+
+ public static ArrayList<Package> getPackageListForDevice(IDevice device) {
+ actionBeforeUseZypperDevice(device);
+
+ ArrayList<Package> packageList = new ArrayList<Package>();
+ Hashtable<String, Package> packageHash = new Hashtable<String, Package>();
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
+ rec.setPrintConsole(false);
+ try {
+ // get list using zypper
+ String command = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(), getRemotePkgListCmd());
+ rec.cleanLog();
+ device.executeShellCommand(command, rec, MAX_TIMEOUT);
+ for (String s : rec.getLog() ) {
+ s = s.replaceAll(" ", "");
+ String[] part = s.split("\\|");
+ if ( part.length == 5 && !part[1].equals("Repository")) {
+ String name = part[2];
+ String version = part[3];
+ String arch = part[4];
+ if ( part[0].equals("i") ) {
+ packageHash.put(name, new Package(name,version,version,arch) );
+ }
+ else if ( part[0].equals("v") ) {
+ Package p = packageHash.get(name);
+ if ( p != null && version.compareTo( p.getNewVersion() ) > 0 ) {
+ p.setNewVersion(version);
+ }
+ else {
+ packageHash.put(name, new Package(name,"",version,arch) );
+ }
+ }
+ else {
+ packageHash.put(name, new Package(name,"",version,arch) );
+ }
+ }
+ }
+
+ // get installed packages using rpm
+ command = String.format("%s;%s", getResetDbCmd(), getInstalledPkgListCmdDevice());
+ rec.cleanLog();
+ device.executeShellCommand(command, rec, MAX_TIMEOUT);
+ for (String s : rec.getLog()) {
+ s = s.replaceAll(" ", "").trim();
+ String[] part = s.split(",");
+ if ( part.length == 3 ) {
+ String name = part[0];
+ String version = part[1];
+ String arch = part[2];
+ Package pkg = packageHash.get(name);
+ if ( pkg == null ) {
+ packageHash.put(name, new Package(name,version,"",arch));
+ }
+ else {
+ pkg.setInstalledVersion(version);
}
}
}
}
- public static String getRepositoryListForDevice(IDevice device, PackageManagerOuputReceiver rec) {
-
- String result = "";
+ public static Hashtable<String, String> getRepositoryListForDevice(IDevice device) {
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
+ Hashtable<String, String> reposHash = new Hashtable<String, String>();
try {
String command = String.format("%s;%s", getResetDbCmd(), getRepoListCmd());
e.printStackTrace();
}
- for (String l : rec.getLog()) {
- result = result.concat(l + "\n");
+ for (String reposStr : rec.getLog()) {
+ reposStr = reposStr.replaceAll(" ", "");
+ String[] part = reposStr.split("\\|");
+ if ( part.length == 6 && !part[0].equals("#") ) {
+ reposHash.put(part[1], part[5]);
+ }
}
-
- return result;
+
+ return reposHash;
}
+
public static String refreshRepositoryForRootstrap(String path) {
return result;
}
- public static String refreshRepositoryForDevice(IDevice device, PackageManagerOuputReceiver rec) {
-
- String result = "";
-
+ public static void refreshRepositoryForDevice(IDevice device) {
try {
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
String command = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(), getRefreshCmd());
rec.cleanLog();
device.executeShellCommand(command, rec, MAX_TIMEOUT);
} catch (Exception e) {
e.printStackTrace();
}
-
- for (String l : rec.getLog()) {
- result = result.concat(l + "\n");
- }
-
- return result;
}
+
public static String addRepositoryForRootstrap(String name, String uri, String path) {
return result;
}
- public static String addRepositoryForDevice(String name, String uri, IDevice device, PackageManagerOuputReceiver rec) {
-
- String result = "";
-
+
+ public static void addRepositoryForDevice(String name, String uri, IDevice device) {
try {
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
String command = String.format("%s;%s", getResetDbCmd(), getAddRepoCmd(uri, name));
rec.cleanLog();
device.executeShellCommand(command, rec, MAX_TIMEOUT);
} catch (Exception e) {
e.printStackTrace();
}
-
- for (String l : rec.getLog()) {
- result = result.concat(l + "\n");
- }
-
- return result;
}
+
public static String removeRepositoryForRootstrap(String name, String path) {
String result = "";
- String cmd = String.format("%s;%s", getResetDbCmd(), getRemoteRepoCmd(name));
+ String cmd = String.format("%s;%s", getResetDbCmd(), getRemoveRepoCmd(name));
String command = getCommand(path, cmd);
try {
return result;
}
- public static String removeRepositoryForDevice(String name, IDevice device, PackageManagerOuputReceiver rec) {
-
- String result = "";
+
+ public static void removeRepositoryForDevice(String name, IDevice device) {
try {
- String command = String.format("%s;%s", getResetDbCmd(), getRemoteRepoCmd(name));
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
+ String command = String.format("%s;%s", getResetDbCmd(), getRemoveRepoCmd(name));
rec.cleanLog();
device.executeShellCommand(command, rec, MAX_TIMEOUT);
} catch (Exception e) {
e.printStackTrace();
}
-
- for (String l : rec.getLog()) {
- result = result.concat(l + "\n");
- }
-
- return result;
}
- public static String installRemotePkgForRootstrap(CopyOnWriteArrayList<Package> selectedList, String path) {
+
+
+
+ public static void installRemotePkgForRootstrap(CopyOnWriteArrayList<Package> selectedList, String path) {
actionBeforeUseZypper(path);
- String result = "";
String cmd = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(), getInstallPkgCmd(selectedList));
String command = getCommand(path, cmd);
} catch (Exception e) {
e.printStackTrace();
}
-
- return result;
}
- public static String installRemotePkgForDevice(String pkgList, IDevice device, PackageManagerOuputReceiver rec) {
-
- String result = "";
+
+ public static void installRemotePkgForDevice(CopyOnWriteArrayList<Package> selectedList, IDevice device) {
try {
- String command = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(), getInstallPkgCmdOld(pkgList));
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
+ String command = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(), getInstallPkgCmd(selectedList));
rec.cleanLog();
device.executeShellCommand(command, rec, MAX_TIMEOUT);
} catch (Exception e) {
e.printStackTrace();
}
-
- for (String l : rec.getLog()) {
- result = result.concat(l + "\n");
- }
-
- return result;
}
- public static void changeUpdateModeForDevice(IDevice device, PackageManagerOuputReceiver rec) {
+
+ private static void changeUpdateModeForDevice(IDevice device, PackageManagerOuputReceiver rec) {
try {
String command = resources.getString("Command.Change.Updatemode");
}
}
+
private static void actionBeforeUseZypper(String path) {
if (pkgInstalledSuccessfullyForRootstrap(REMOVE_PKGS, path)) {
UninstallPkgFromRootstrapNoDeps(REMOVE_PKGS, path);
}
}
+
+
+ private static void actionBeforeUseZypperDevice(IDevice device) {
+ if ( device.isEmulator() ) {
+ try {
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
+ rec.cleanLog();
+ String command = String.format("sed -i \"s/# arch = s390/arch = i686/g\" /etc/zypp/zypp.conf");
+ device.executeShellCommand(command, rec, MAX_TIMEOUT);
+ return;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
private static String getProxyCmd() {
return String.format(resources.getString("Command.Export.Proxy"), http_proxy);
}
+
private static String getResetDbCmd() {
return String.format(resources.getString("Command.Reset.Db"));
}
+
private static String getDistUpgradeCmd() {
return String.format(resources.getString("Command.DistUpgrade"));
}
+
private static String getInstallPkgCmd(CopyOnWriteArrayList<Package> pkgList) {
String pkgListStr = "";
for( Package pkg: pkgList) {
return String.format(resources.getString("Command.Install.Remote.Pkg"), pkgListStr);
}
- private static String getInstallPkgCmdOld(String pkgList) {
- return String.format(resources.getString("Command.Install.Remote.Pkg"), pkgList);
- }
-
private static String getInstallLocalPkgCmd(ArrayList<String> fileList) {
String pkgListStr = "";
for( String filePath: fileList) {
return String.format(resources.getString("Command.Install.Local.Pkg"), pkgListStr);
}
- private static String getInstallLocalPkgCmdWithRPM(String pkgList) {
- return String.format(resources.getString("Command.Install.Local.Pkg.RPM"), pkgList);
+ private static String getInstallLocalPkgCmdWithRPM(ArrayList<String> fileList) {
+ String pkgListStr = "";
+ for( String filePath: fileList) {
+ pkgListStr = pkgListStr.isEmpty() ? filePath : pkgListStr + " " + filePath;
+ }
+ return String.format(resources.getString("Command.Install.Local.Pkg.RPM"), pkgListStr);
}
private static String getUninstallPkgCmd(CopyOnWriteArrayList<Package> pkgList) {
return String.format(resources.getString("Command.Uninstall.Pkg.NoDeps"), pkgList);
}
- private static String getRemoteRepoCmd(String name) {
+ private static String getRemoveRepoCmd(String name) {
return String.format(resources.getString("Command.Remove.Repo"), name);
}
return resources.getString("Command.List.Installed.Pkg");
}
+ private static String getInstalledPkgListCmdDevice() {
+ return resources.getString("Command.List.Installed.Pkg.Device");
+ }
+
private static String getShowPkgCmd(String name) {
return String.format(resources.getString("Command.Show.Pkg"), name);
}
return result;
}
+
+ static private PackageManagerOuputReceiver getNewOuputReceiver() {
+ ConsoleManager cm = new ConsoleManager("Platform Internal", true);
+ cm.clear();
+ //MessageConsoleStream mcsError = cm.getMessageConsoleStream();
+ MessageConsoleStream mcs = cm.getMessageConsoleStream();
+ PackageManagerOuputReceiver rec = new PackageManagerOuputReceiver();
+ rec.setMessageConsoleStream(mcs);
+
+ return rec;
+ }
+
}
package org.tizen.nativeplatform.pkgmgr.ui;
import java.io.File;
-import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
-import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Hashtable;
import java.util.ResourceBundle;
import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ICheckStateProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.ui.console.MessageConsoleStream;
-import org.tizen.common.ui.view.console.ConsoleManager;
+import org.eclipse.swt.widgets.Text;
import org.tizen.common.util.DialogUtil;
-import org.tizen.nativecommon.build.SmartBuildInterface;
-import org.tizen.nativecommon.build.exception.SBIException;
-import org.tizen.nativeplatform.pkgmgr.PackageManagerOuputReceiver;
import org.tizen.nativeplatform.pkgmgr.RPMPackageCommander;
-import org.tizen.nativeplatform.pkgmgr.model.LocalPackage;
import org.tizen.nativeplatform.pkgmgr.model.Package;
import org.tizen.nativeplatform.pkgmgr.model.PackageProvider;
-import org.tizen.nativeplatform.pkgmgr.model.RemotePackage;
-import org.tizen.nativeplatform.pkgmgr.model.RemotePkgProvider;
import org.tizen.nativeplatform.pkgmgr.model.Repository;
import org.tizen.nativeplatform.pkgmgr.model.RepositoryProvider;
import org.tizen.sdblib.IDevice;
-import org.tizen.sdblib.SyncService;
-import org.tizen.sdblib.SyncService.SyncResult;
+
public class DeviceTab {
+ private final Shell shell;
private TabFolder folder = null;
- private String targetId = null;
+
private TableViewer repoViewer = null;
- private TableViewer pkgViewer = null;
- private final Shell shell;
- private FileDialog fd;
- private String previousFilterPath = null;
- private String selectedFileList;
- private final IDevice device;
- private CopyOnWriteArrayList<Package> pkgs;
- private final SmartBuildInterface sbi = SmartBuildInterface.getInstance();
+ private Combo categoryCombo;
+ private Text filterText;
+ private CheckboxTableViewer pkgViewer = null;
- private final String TMP_PATH= "/tmp";
+ private final IDevice device;
private final String BUNDLE_NAME = DeviceTab.class.getPackage().getName() + ".PkgMgrUIMessages";//$NON-NLS-1$
private final ResourceBundle resources = ResourceBundle.getBundle(BUNDLE_NAME);
- public DeviceTab(Shell shell, TabFolder folder, String targetId, IDevice dev) {
+ public DeviceTab(Shell shell, TabFolder folder, IDevice dev) {
this.shell = shell;
this.folder = folder;
- this.targetId = targetId;
this.device = dev;
}
+
public void createTab() {
- initialize();
createDeivceTab(folder);
}
- private void initialize() {
+
+ public void updateRepositoryInfo() {
+ initializeRepositoryInfo(device);
+ }
+
+
+ public static void initializeRepositoryInfo(IDevice device) {
RepositoryProvider.INSTANCE.getDeviceRepos().clear();
- PackageProvider.INSTANCE.getDevicePkgs().clear();
-
- PackageManagerOuputReceiver rec = getNewOuputReceiver();
- String result = RPMPackageCommander.getRepositoryListForDevice(device, rec);
- String[] splitStr = result.split("\n");
- for (int i = 2 ; i < splitStr.length ; i++) {
- String s = splitStr[i];
- s = s.replaceAll(" ", "");
- String[] part = s.split("\\|");
- String name = part[1];
- String uri = part[5];
-
- Repository repo = new Repository();
- repo.setName(name);
- repo.setUri(uri);
-
- RepositoryProvider.INSTANCE.getDeviceRepos().add(repo);
+ Hashtable<String,String> reposHash = RPMPackageCommander.getRepositoryListForDevice(device);
+ Enumeration<String> e = reposHash.keys();
+ while(e.hasMoreElements()) {
+ String name = e.nextElement();
+ String url = reposHash.get(name);
+ RepositoryProvider.INSTANCE.getDeviceRepos()
+ .add(new Repository(name, url ));
}
}
+
+ public static void initializePackageInfo(IDevice device) {
+ PackageProvider.INSTANCE.getDevicePkgs().clear();
+ PackageProvider.INSTANCE.getDevicePkgs()
+ .addAll(RPMPackageCommander.getPackageListForDevice(device));
+ }
+
+
+
private void createDeivceTab( TabFolder parent )
{
TabItem deviceTab = new TabItem( parent, SWT.NULL );
- deviceTab.setText(resources.getString("PkgMgr.Tab.Device"));
+ deviceTab.setText(resources.getString("PkgMgr.Tab.Device")+" ["+device.getSerialNumber()+"]");
Composite composite = new Composite(folder, SWT.NONE);
deviceTab.setControl(composite);
- composite.setLayout(new GridLayout(1, false));
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ composite.setLayout(new GridLayout(1, false));
- createInfoComposite( composite );
createRepositoryGroup( composite );
createPackageGroup( composite );
}
-
- private void createInfoComposite( Composite parent )
- {
- Composite info_comp = new Composite( parent, SWT.NONE );
- info_comp.setLayoutData(new GridData(GridData.BEGINNING));
- info_comp.setLayout(new GridLayout(1, false));
-
- Label configurationLabel = new Label(info_comp, SWT.LEFT);
- configurationLabel.setText(String.format("%s %s", resources.getString("PkgMgr.Label.Connection"), device.getSerialNumber()));
- }
+
private void createRepositoryGroup( Composite parent )
{
Group grpRepo = new Group(parent, SWT.NONE);
grpRepo.setText(resources.getString("PkgMgr.Frame.Respository"));
- grpRepo.setLayout(new GridLayout(1, false));
- GridData repo_gd = new GridData(GridData.FILL_BOTH);
+ GridData repo_gd = new GridData(GridData.FILL_HORIZONTAL);
+ repo_gd.heightHint = 110;
grpRepo.setLayoutData(repo_gd);
+ grpRepo.setLayout(new GridLayout(2, false));
- Composite repo_comp = new Composite( grpRepo, SWT.NONE );
- repo_comp.setLayoutData(new GridData(GridData.FILL_BOTH));
- repo_comp.setLayout(new GridLayout(2, false));
-
- Composite repo_comp_table = new Composite( repo_comp, SWT.NONE );
- repo_comp_table.setLayoutData(new GridData(GridData.FILL_BOTH));
- repo_comp_table.setLayout(new FillLayout());
-
- Composite repo_comp_buttons = new Composite( repo_comp, SWT.NONE );
- repo_comp_buttons.setLayoutData(new GridData(GridData.FILL_BOTH));
- repo_comp_buttons.setLayout(new GridLayout(1, false));
-
- createRepositoryTable( repo_comp_table );
- createRepositoryButtons( repo_comp_buttons );
+ createRepositoryTable( grpRepo );
+ createRepositoryButtons( grpRepo );
}
- private void createPackageGroup( Composite parent )
+
+ private void createRepositoryTable( Composite parent)
{
- Group grpPkg = new Group(parent, SWT.NONE);
- grpPkg.setText(resources.getString("PkgMgr.Frame.Package"));
- grpPkg.setLayout(new GridLayout(1, false));
- GridData pkgs_gd = new GridData(GridData.FILL_BOTH);
- pkgs_gd.heightHint = shell.getBounds().height / 3;
- grpPkg.setLayoutData(pkgs_gd);
-
- Composite pkg_comp = new Composite( grpPkg, SWT.NONE );
- pkg_comp.setLayoutData(new GridData(GridData.FILL_BOTH));
- pkg_comp.setLayout(new GridLayout(2, false));
-
- Composite pkg_comp_table = new Composite( pkg_comp, SWT.NONE );
- pkg_comp_table.setLayoutData(new GridData(GridData.FILL_BOTH));
- pkg_comp_table.setLayout(new FillLayout());
-
- Composite pkg_comp_buttons = new Composite( pkg_comp, SWT.NONE );
- pkg_comp_buttons.setLayoutData(new GridData(GridData.FILL_BOTH));
- pkg_comp_buttons.setLayout(new GridLayout(1, false));
-
- createPackageTable( pkg_comp_table );
- createPackageButtons( pkg_comp_buttons );
+ Composite composite = new Composite( parent, SWT.NONE );
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ composite.setLayoutData(gridData);
+ composite.setLayout(new FillLayout());
+
+ repoViewer = new TableViewer( composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL );
+ createColumnsForRepoTable( composite );
+ Table reposTable = repoViewer.getTable();
+ reposTable.setHeaderVisible(true);
+ reposTable.setLinesVisible(true);
+ repoViewer.setContentProvider(new ArrayContentProvider());
+ repoViewer.setInput(RepositoryProvider.INSTANCE.getDeviceRepos());
}
- private void createRepositoryTable( Composite parent)
+
+ private void createColumnsForRepoTable( Composite parent )
{
- // Build System Tab
- repoViewer = new TableViewer( parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CHECK );
- createColumnsForRepoTable( parent );
- Table tableForRepository = repoViewer.getTable();
- tableForRepository.addListener( SWT.Selection, new Listener(){
+ String[] titles = {resources.getString("PkgMgr.Repo.Table.Column.1"),
+ resources.getString("PkgMgr.Repo.Table.Column.2")};
+ int[] bounds = { 100, 600 };
+ TableViewerColumn colName = createTableViewerColumn( repoViewer, titles[0], bounds[0], SWT.NONE);
+ colName.setLabelProvider(new ColumnLabelProvider() {
@Override
- public void handleEvent(Event event) {
- if( event.detail == SWT.CHECK )
- {
- Repository repo = (Repository)event.item.getData();
- repo.setCheckColumn( !repo.getCheckColumn() );
- }
+ public String getText(Object element) {
+ Repository repo = (Repository)element;
+ return repo.getName();
+ }
+ });
+
+ TableViewerColumn colUrl = createTableViewerColumn( repoViewer, titles[1], bounds[1], SWT.NONE);
+ colUrl.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ Repository repo = (Repository)element;
+ return repo.getUri();
}
});
- tableForRepository.setHeaderVisible(true);
- tableForRepository.setLinesVisible(true);
- repoViewer.setContentProvider(new ArrayContentProvider());
- repoViewer.setInput(RepositoryProvider.INSTANCE.getDeviceRepos());
}
+
private void createRepositoryButtons( Composite parent )
{
- Button add_bt = new Button( parent, SWT.PUSH );
+ Composite composite = new Composite( parent, SWT.NONE );
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ RowLayout layout = new RowLayout(SWT.VERTICAL);
+ layout.pack = false;
+ composite.setLayout(layout);
+
+
+ Button add_bt = new Button( composite, SWT.PUSH );
add_bt.setText(resources.getString("PkgMgr.Button.AddRepo"));
add_bt.setToolTipText(resources.getString("PkgMgr.Button.AddRepo.Tooltip"));
add_bt.addMouseListener(new MouseListener(){
@Override
public void mouseDown(MouseEvent e) {
- AddRepoDialog dialog = new AddRepoDialog(shell, resources.getString("PkgMgr.Tab.Device"));
- dialog.open();
- repoViewer.refresh();
-
- int recentTableIndex = 0;
- recentTableIndex = repoViewer.getTable().getItemCount();
-
- for (int i = 0; i < recentTableIndex; i++) {
- TableItem item = null;
- item = repoViewer.getTable().getItem(i);
- Repository repo = (Repository)item.getData();
- item.setChecked(repo.getCheckColumn());
-
- if (repo.getCheckDirty()) {
- PackageManagerOuputReceiver rec = getNewOuputReceiver();
- RPMPackageCommander.addRepositoryForDevice(repo.getName(), repo.getUri(), device, rec);
- repo.setCheckDirty(false);
- }
+ ModifyRepoDialog dialog = new ModifyRepoDialog(shell, resources.getString("PkgMgr.Tab.Device"));
+ if ( dialog.open() != ModifyRepoDialog.OK ) {
+ return;
}
+ String name = dialog.getRepositoryName();
+ String url = dialog.getRepositoryURL();
+ RPMPackageCommander.addRepositoryForDevice(name, url, device);
+
+ updateRepositoryInfo();
+ repoViewer.refresh();
}
@Override
});
- Button modify_bt = new Button( parent, SWT.PUSH );
+ Button modify_bt = new Button( composite, SWT.PUSH );
modify_bt.setText(resources.getString("PkgMgr.Button.ModifyRepo"));
modify_bt.setToolTipText(resources.getString("PkgMgr.Button.ModifyRepo.Tooltip"));
modify_bt.addMouseListener(new MouseListener(){
@Override
public void mouseDown(MouseEvent e) {
-
- CopyOnWriteArrayList<Repository> list = RepositoryProvider.INSTANCE.getDeviceRepos();
-
- Repository selectedRepo = null;
- int count = 0;
-
- for( Repository repo : list) {
- if (repo.getCheckColumn()) {
- count++;
- selectedRepo = repo;
- }
- }
-
- if (count != 1 ) {
+ int selectedIdx = repoViewer.getTable().getSelectionIndex();
+ if ( selectedIdx == -1 ) {
DialogUtil.openMessageDialog(resources.getString("PkgMgr.Message.Select.OnePackage"));
return;
}
+ Repository repos = (Repository)repoViewer.getTable().getItem(selectedIdx).getData();
ModifyRepoDialog dialog = new ModifyRepoDialog(shell, resources.getString("PkgMgr.Tab.Device"),
- selectedRepo.getUri());
- dialog.open();
-
- repoViewer.refresh();
-
- int recentTableIndex = 0;
- recentTableIndex = repoViewer.getTable().getItemCount();
-
- for (int i = 0; i < recentTableIndex; i++) {
- TableItem item = null;
- item = repoViewer.getTable().getItem(i);
- Repository repo = (Repository)item.getData();
- item.setChecked(repo.getCheckColumn());
-
- if (repo.getCheckDirty()) {
- list.remove(selectedRepo);
- PackageManagerOuputReceiver rec = getNewOuputReceiver();
- RPMPackageCommander.removeRepositoryForDevice(selectedRepo.getName(), device, rec);
-
- rec.cleanLog();
- RPMPackageCommander.addRepositoryForDevice(repo.getName(), repo.getUri(), device, rec);
- repo.setCheckDirty(false);
- }
+ repos.getName(), repos.getUri(), true);
+ if ( dialog.open() != ModifyRepoDialog.OK ) {
+ return;
}
-
+ RPMPackageCommander.removeRepositoryForDevice(repos.getName(), device);
+ RPMPackageCommander.addRepositoryForDevice(dialog.getRepositoryName(), dialog.getRepositoryURL(), device);
+ updateRepositoryInfo();
repoViewer.refresh();
- recentTableIndex = repoViewer.getTable().getItemCount();
-
- for (int i = 0; i < recentTableIndex; i++) {
- TableItem item = repoViewer.getTable().getItem(i);
- Repository repo = (Repository)item.getData();
- item.setChecked(repo.getCheckColumn());
- }
}
@Override
}
});
-
- Button remove_bt = new Button( parent, SWT.PUSH );
+
+ Button remove_bt = new Button( composite, SWT.PUSH );
remove_bt.setText(resources.getString("PkgMgr.Button.RemoveRepo"));
remove_bt.setToolTipText(resources.getString("PkgMgr.Button.RemoveRepo.Tooltip"));
remove_bt.addMouseListener(new MouseListener() {
@Override
public void mouseDown(MouseEvent e) {
- CopyOnWriteArrayList<Repository> list = RepositoryProvider.INSTANCE.getDeviceRepos();
-
- for( Repository repo : list)
- {
- boolean selected = false;
- selected = repo.getCheckColumn();
-
- if (selected) {
- list.remove(repo);
- PackageManagerOuputReceiver rec = getNewOuputReceiver();
- RPMPackageCommander.removeRepositoryForDevice(repo.getName(), device, rec);
- }
- }
-
+ int selectedIdx = repoViewer.getTable().getSelectionIndex();
+ if ( selectedIdx == -1 ) {
+ DialogUtil.openMessageDialog(resources.getString("PkgMgr.Message.Select.OnePackage"));
+ return;
+ }
+ Repository repos = (Repository)repoViewer.getTable().getItem(selectedIdx).getData();
+ RPMPackageCommander.removeRepositoryForDevice(repos.getName(), device);
+ updateRepositoryInfo();
repoViewer.refresh();
- int recentTableIndex = repoViewer.getTable().getItemCount();
-
- for (int i = 0; i < recentTableIndex; i++) {
- TableItem item = repoViewer.getTable().getItem(i);
- Repository repo = (Repository)item.getData();
- item.setChecked(repo.getCheckColumn());
- }
-
}
@Override
public void mouseUp(MouseEvent e) {
}
});
+ }
+
+
+ private void createPackageGroup( Composite parent )
+ {
+ Group grpPkg = new Group(parent, SWT.NONE);
+ grpPkg.setText(resources.getString("PkgMgr.Frame.Package"));
+ GridData pkgs_gd = new GridData(GridData.FILL_BOTH|GridData.GRAB_VERTICAL);
+ grpPkg.setLayoutData(pkgs_gd);
+ grpPkg.setLayout(new GridLayout(1, false));
+
+ createPackageButtonsAndFilter( grpPkg );
+ createPackageTable( grpPkg );
+ }
+
+
+ private void createPackageButtonsAndFilter( Composite parent ) {
+ Composite composite = new Composite( parent, SWT.NONE );
+ composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ composite.setLayout(new GridLayout(2, false));
+
+ createPackageButtons( composite );
+ createPackageFilter( composite );
+ }
+
+
+ private void createPackageButtons( Composite parent )
+ {
+ Composite composite = new Composite( parent, SWT.NONE );
+ RowLayout layout = new RowLayout(SWT.HORIZONTAL);
+ layout.pack = false;
+ composite.setLayout(layout);
- Button refresh_bt = new Button( parent, SWT.PUSH );
+ Button refresh_bt = new Button( composite, SWT.PUSH );
refresh_bt.setText(resources.getString("PkgMgr.Button.RefreshRepo"));
refresh_bt.setToolTipText(resources.getString("PkgMgr.Button.RefreshRepo.Tooltip"));
refresh_bt.addMouseListener(new MouseListener(){
@Override
public void mouseDown(MouseEvent e) {
+
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
try {
- dialog.run(true, true, new IRunnableWithProgress() {
+ dialog.run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
- monitor.beginTask(resources.getString("PkgMgr.Message.Refreshing"), -1);
- PackageManagerOuputReceiver rec = getNewOuputReceiver();
- RPMPackageCommander.refreshRepositoryForDevice(device, rec);
+ monitor.beginTask(resources.getString("PkgMgr.Message.Refreshing"), -1);
+ RPMPackageCommander.refreshRepositoryForDevice(device);
+ monitor.done();
}
});
} catch (Exception e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
+ DialogUtil.openErrorDialog(
+ resources.getString("PkgMgr.Msg.Error.RefreshFailed")+
+ "("+e1.toString()+")");
}
}
@Override
public void mouseUp(MouseEvent e) {
}
- });
- }
-
- private void createPackageTable( Composite parent )
- {
- pkgViewer = new TableViewer( parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CHECK );
- createColumns( parent );
- Table packageTable = pkgViewer.getTable();
- packageTable.addListener( SWT.Selection, new Listener(){
-
- @Override
- public void handleEvent(Event event) {
- if( event.detail == SWT.CHECK )
- {
- Package pkg = (Package)event.item.getData();
- pkg.setCheckColumn( !pkg.getCheckColumn() );
- }
- }
- });
-
- packageTable.setHeaderVisible(true);
- packageTable.setLinesVisible(true);
-
- pkgViewer.setContentProvider(new ArrayContentProvider());
- pkgViewer.setInput(PackageProvider.INSTANCE.getDevicePkgs());
- }
-
- private void createPackageButtons( Composite parent )
- {
- Button add_rtpkg_bt = new Button( parent, SWT.PUSH );
- add_rtpkg_bt.setText(resources.getString("PkgMgr.Button.AddRPackage"));
- add_rtpkg_bt.setToolTipText(resources.getString("PkgMgr.Button.AddRPackage.Tooltip"));
- add_rtpkg_bt.addMouseListener(new MouseListener(){
+ });
+
+
+ Button upgrade_bt = new Button( composite, SWT.PUSH );
+ upgrade_bt.setText(resources.getString("PkgMgr.Button.Upgrade"));
+ upgrade_bt.setToolTipText(resources.getString("PkgMgr.Button.Upgrade.Tooltip"));
+ upgrade_bt.setEnabled(false);
+
+ Button install_bt = new Button( composite, SWT.PUSH );
+ install_bt.setText(resources.getString("PkgMgr.Button.Install"));
+ install_bt.setToolTipText(resources.getString("PkgMgr.Button.Install.Tooltip"));
+ install_bt.addMouseListener(new MouseListener(){
@Override
public void mouseDoubleClick(MouseEvent e) {
@Override
public void mouseDown(MouseEvent e) {
-
- RemotePkgProvider.INSTANCE.getPkgs().clear();
- RemotePkgProvider.INSTANCE.getSelectedPkgs().clear();
-
+ final CopyOnWriteArrayList<Package> selectedList =
+ PackageProvider.INSTANCE.getSelectedDevicePkgs(false);
+
+ if(selectedList.isEmpty()) {
+ DialogUtil.openErrorDialog( resources.getString("PkgMgr.Error.Noselected.Package"));
+ return;
+ }
+
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
-
try {
- dialog.run(true, true, new IRunnableWithProgress() {
+ dialog.run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
- monitor.beginTask(resources.getString("PkgMgr.Message.Getting.RemotePackage"), -1);
- genRemotePkgList();
+
+ monitor.beginTask(resources.getString("PkgMgr.Message.Installing.Package"), -1);
+ RPMPackageCommander.installRemotePkgForDevice(selectedList, device);
+ monitor.done();
}
});
- } catch (Exception e1) {
- e1.printStackTrace();
}
-
- AddRemotePackageDialog dlg = new AddRemotePackageDialog(shell);
- dlg.open();
+ catch (Exception e1) {
+ DialogUtil.openErrorDialog(
+ resources.getString("PkgMgr.Msg.Error.InstallFailed")+
+ "("+e1.toString()+")");
+ }
- dialog = new ProgressMonitorDialog(shell);
- try {
- dialog.run(true, true, new IRunnableWithProgress() {
- @Override
- public void run(IProgressMonitor monitor) throws InvocationTargetException,
- InterruptedException {
- monitor.beginTask(resources.getString("PkgMgr.Message.Adding.Package"), -1);
- for (RemotePackage p : RemotePkgProvider.INSTANCE.getSelectedPkgs()) {
- addRemotePackage(p);
- }
- }
- });
- } catch (Exception e1) {
- e1.printStackTrace();
- }
-
+ // update package list
+ updatePackageInfo(null);
pkgViewer.refresh();
- int recentTableIndex = pkgViewer.getTable().getItemCount();
-
- for (int i = 0; i < recentTableIndex; i++) {
- TableItem item = pkgViewer.getTable().getItem(i);
- Package pkg = (Package)item.getData();
- item.setChecked(pkg.getCheckColumn());
- }
}
@Override
}
});
-
-
- Button add_lcpkg_bt = new Button( parent, SWT.PUSH );
- add_lcpkg_bt.setText(resources.getString("PkgMgr.Button.AddLPackage"));
- add_lcpkg_bt.setToolTipText(resources.getString("PkgMgr.Button.AddLPackage.Tooltip"));
- add_lcpkg_bt.addMouseListener(new MouseListener()
- {
+
+ Button installLocal_bt = new Button( composite, SWT.PUSH );
+ installLocal_bt.setText(resources.getString("PkgMgr.Button.InstallLocal"));
+ installLocal_bt.setToolTipText(resources.getString("PkgMgr.Button.InstallLocal.Tooltip"));
+ installLocal_bt.addMouseListener(new MouseListener() {
@Override
public void mouseDoubleClick(MouseEvent e) {
@Override
public void mouseDown(MouseEvent e) {
-
- int oldTableIndex = pkgViewer.getTable().getItemCount();
-
- fd = new FileDialog( shell, SWT.OPEN|SWT.MULTI);
+ FileDialog fd = new FileDialog( shell, SWT.OPEN|SWT.MULTI);
fd.setText(resources.getString("FileDlg.Title"));
- if (previousFilterPath == null)
- fd.setFilterPath(null);
- else
- fd.setFilterPath(previousFilterPath);
String[] filterExt = { resources.getString("FileDlg.Filter.Ext") };
fd.setFilterExtensions(filterExt);
-
- try {
- String arch = sbi.getArchitectureFromToolchainID(sbi.getToolchainIDFromTargetID(targetId));
- String _arch = "";
- if ("armel".equals(arch)) {
- _arch = "armv7l";
- } else if ("i386".equals(arch)) {
- _arch = "i586";
- } else {
- _arch = arch;
- }
- String rootstrapPath = sbi.getRootstrapPath(targetId);
- String defaultPath = rootstrapPath + resources.getString("FileDlg.Default.Path") + _arch;
- fd.setFilterPath(defaultPath);
- } catch (SBIException e2) {
- e2.printStackTrace();
- }
-
- selectedFileList = fd.open();
-
+ String firstFilePath = fd.open();
+ if ( firstFilePath == null ) { return; }
+
+ String[] fileNames = fd.getFileNames();
+ final ArrayList<String> selectedFiles = new ArrayList<String>();
+ for( String fileName : fileNames ) {
+ selectedFiles.add(new File(firstFilePath).getParent()+"/"+fileName);
+ }
+
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
-
try {
dialog.run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
- monitor.beginTask(resources.getString("PkgMgr.Message.Adding.Package"), -1);
- if( selectedFileList != null )
- {
- String[] files = fd.getFileNames();
- previousFilterPath = fd.getFilterPath();
- for (int i=0, n = files.length; i<n; i++) {
- monitor.subTask(String.format("Adding %s", files[i]));
- StringBuffer buf = new StringBuffer();
- buf.append(fd.getFilterPath());
- if (buf.charAt(buf.length() -1) != File.separatorChar) {
- buf.append(File.separatorChar);
- }
- buf.append(files[i]);
- addLocalPackage( buf.toString());
- }
- }
+
+ monitor.beginTask(resources.getString("PkgMgr.Message.Installing.LocalPackage"), -1);
+ RPMPackageCommander.InstallLocalPkgToDevice(selectedFiles, device);
+ monitor.done();
}
});
} catch (Exception e1) {
- e1.printStackTrace();
+ DialogUtil.openErrorDialog(
+ resources.getString("PkgMgr.Msg.Error.InstallFailed")+
+ "("+e1.toString()+")");
}
+ // update package list
+ updatePackageInfo(selectedFiles);
pkgViewer.refresh();
-
- int recentTableIndex = pkgViewer.getTable().getItemCount();
-
- for (int i = oldTableIndex; i < recentTableIndex; i++) {
- TableItem item = null;
-
- item = pkgViewer.getTable().getItem(i);
- Package pkg = (Package)item.getData();
- item.setChecked(pkg.getCheckColumn());
- }
}
@Override
public void mouseUp(MouseEvent e) {
}
-
- });
-
- Button remove_bt = new Button( parent, SWT.PUSH );
- remove_bt.setText(resources.getString("PkgMgr.Button.RemoveList"));
- remove_bt.setToolTipText(resources.getString("PkgMgr.Button.RemoveList.Tooltip"));
- remove_bt.addMouseListener(new MouseListener() {
-
- @Override
- public void mouseDoubleClick(MouseEvent e) {
- }
-
- @Override
- public void mouseDown(MouseEvent e) {
- CopyOnWriteArrayList<Package> pkgList = PackageProvider.INSTANCE.getDevicePkgs();
- for( Package pkg: pkgList)
- {
- boolean selected = false;
- selected = pkg.getCheckColumn();
- if (selected) {
- pkgList.remove(pkg);
- }
- }
- pkgViewer.refresh();
-
- int recentTableIndex = pkgViewer.getTable().getItemCount();
- for (int i = 0; i < recentTableIndex; i++) {
- TableItem item = null;
- item = pkgViewer.getTable().getItem(i);
- Package pkg = (Package)item.getData();
- item.setChecked(pkg.getCheckColumn());
- }
- }
-
- @Override
- public void mouseUp(MouseEvent e) {
- }
- });
-
- Label space = new Label(parent, SWT.NONE);
-
- Button install_bt = new Button( parent, SWT.PUSH );
- install_bt.setText(resources.getString("PkgMgr.Button.Install"));
- install_bt.setToolTipText(resources.getString("PkgMgr.Button.Install.Tooltip"));
- install_bt.addMouseListener(new MouseListener(){
+ });
+
+ Button removeBt = new Button( composite, SWT.PUSH );
+ removeBt.setText(resources.getString("PkgMgr.Button.Uninstall"));
+ removeBt.setToolTipText(resources.getString("PkgMgr.Button.Uninstall.Tooltip"));
+ removeBt.addMouseListener(new MouseListener(){
@Override
public void mouseDoubleClick(MouseEvent e) {
@Override
public void mouseDown(MouseEvent e) {
-
- pkgs = getSelectedPkg(PackageProvider.INSTANCE.getDevicePkgs());
-
- if(pkgs.isEmpty()) {
- MessageDialog.openError(shell, "Error", resources.getString("PkgMgr.Error.Noselected.Package"));
+ final CopyOnWriteArrayList<Package> selectedList =
+ PackageProvider.INSTANCE.getSelectedDevicePkgs(true);
+ if(selectedList.isEmpty()) {
+ DialogUtil.openErrorDialog( resources.getString("PkgMgr.Error.Noselected.Package"));
return;
}
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
-
try {
- dialog.run(true, true, new IRunnableWithProgress() {
+ dialog.run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
- monitor.beginTask(resources.getString("PkgMgr.Message.Installing.Package"), -1);
-
- try {
- String newPath = null;
- ConsoleManager cm = new ConsoleManager(resources.getString("PkgMgr.Console.Name"), true);
- cm.clear();
- MessageConsoleStream mcsError = cm.getMessageConsoleStream();
- MessageConsoleStream mcs = cm.getMessageConsoleStream();
- PackageManagerOuputReceiver rec = new PackageManagerOuputReceiver();
- rec.setMessageConsoleStream(mcs);
- String localPkgList = "";
- String remotePkgList = "";
-
- // Step 1: transfer pkg and make pkg list
- for (Package pkg : pkgs)
- {
- if (pkg instanceof LocalPackage) {
- LocalPackage p = (LocalPackage)pkg;
- String file = new File(p.getPath()).getName();
- newPath = TMP_PATH + "/" + file;
- monitor.subTask(String.format(resources.getString("PkgMgr.Message.Transfer.File"), p.getPath(), newPath));
- if (monitor.isCanceled()) {
- throw new OperationCanceledException();
- }
- SyncService syncService = device.getSyncService();
- SyncResult syncResult = syncService.pushFile(p.getPath(), newPath, SyncService.getNullProgressMonitor());
- if (syncResult.getCode() != SyncService.RESULT_OK) {
- mcsError.println(String.format(resources.getString("PkgMgr.Error.Failtransfer.File"), p.getPath(), newPath));
- p.setInstallInfo( Package.INSTALLINFO.NOT_INSTALLED);
- continue;
- }
- if (monitor.isCanceled()) {
- throw new OperationCanceledException();
- }
- if (localPkgList == "") {
- localPkgList = newPath;
- } else {
- localPkgList = localPkgList + " " + newPath;
- }
-
- } else if (pkg instanceof RemotePackage) {
- if (remotePkgList == "") {
- remotePkgList = pkg.getName();
- } else {
- remotePkgList = remotePkgList + " " + pkg.getName();
- }
- }
- }
-
-
- // Step 2: set update mode on device
- if (!device.isEmulator()) {
- RPMPackageCommander.changeUpdateModeForDevice(device, rec);
- }
-
- if (remotePkgList != "") {
- monitor.subTask(String.format("%s %s", resources.getString("PkgMgr.Message.Installing.Package"), remotePkgList));
- RPMPackageCommander.installRemotePkgForDevice(remotePkgList, device, rec);
- }
-
- if (monitor.isCanceled()) {
- throw new OperationCanceledException();
- }
-
- if (localPkgList != "") {
- monitor.subTask(String.format("%s %s", resources.getString("PkgMgr.Message.Installing.Package"), localPkgList));
- RPMPackageCommander.InstallPkgToDevice(localPkgList, device, rec);
- }
-
- if (monitor.isCanceled())
- throw new OperationCanceledException();
-
- Thread.sleep(500);
-
- for (Package pkg : pkgs) {
- if (monitor.isCanceled()) {
- throw new OperationCanceledException();
- }
- // update status
- rec.setPrintConsole(false);
- String installedVer = RPMPackageCommander.getPkgInstalledVerForDevice(pkg.getName(), device, rec);
- pkg.setInstalledVersion(installedVer);
-
- if ("".equals(installedVer)) {
- pkg.setInstallInfo(Package.INSTALLINFO.NOT_INSTALLED);
- } else if (installedVer.equals(pkg.getNewVersion())) {
- if (RPMPackageCommander.pkgInstalledSuccessfullyForDevice(pkg.getName(), device, rec)) {
- pkg.setInstallInfo(Package.INSTALLINFO.INSTALLED);
- } else {
- pkg.setInstallInfo(Package.INSTALLINFO.NOT_INSTALLED);
- }
- } else {
- pkg.setInstallInfo(Package.INSTALLINFO.DIFFERENT_VERSION);
- }
- if (monitor.isCanceled()) {
- throw new OperationCanceledException();
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- monitor.done();
+
+ monitor.beginTask(resources.getString("PkgMgr.Message.Uninstalling.Package"), -1);
+ RPMPackageCommander.uninstallPkgFromDevice(selectedList, device);
+ monitor.done();
}
});
} catch (Exception e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
+ DialogUtil.openErrorDialog(
+ resources.getString("PkgMgr.Msg.Error.UninstallFailed")+
+ "("+e1.toString()+")");
}
-
+
+ // update package list
+ updatePackageInfo(null);
pkgViewer.refresh();
}
@Override
public void mouseUp(MouseEvent e) {
}
+ });
+ }
+
+ private void updatePackageInfo(ArrayList<String> localPackageFileList ) {
+ ArrayList<Package> fullList = RPMPackageCommander.getPackageListForDevice(device);
+ ArrayList<Package> removeList = new ArrayList<Package>();
+ for( Package pkg: PackageProvider.INSTANCE.getDevicePkgs()) {
+ boolean found = false;
+ for( Package currPkg: fullList ) {
+ if ( currPkg.getName().equals(pkg.getName())) {
+ // check newly install
+ if( !pkg.getInstalledVersion().equals(currPkg.getInstalledVersion())) {
+ pkg.setNewlyChanged(true);
+ }
+
+ pkg.setInstalledVersion(currPkg.getInstalledVersion());
+ found = true;
+ break;
+ }
+ }
+ if ( !found ) {
+ removeList.add(pkg);
+ }
+ pkg.setChecked(false);
+ }
+
+ // remove
+ for( Package pkg: removeList ) {
+ PackageProvider.INSTANCE.getDevicePkgs().remove(pkg);
+ }
+
+ // add if there is new package
+ for( Package currPkg: fullList ) {
+ boolean found = false;
+ for( Package pkg: PackageProvider.INSTANCE.getDevicePkgs()) {
+ if ( currPkg.getName().equals(pkg.getName())) {
+ found = true;
+ break;
+ }
+ }
+
+ if ( !found ) {
+ PackageProvider.INSTANCE.getDevicePkgs().add(currPkg);
+ currPkg.setNewlyChanged(true);
+ }
+ }
+
+ // check local package update
+ if ( localPackageFileList != null ) {
+ ArrayList<String> localPackageNameList = new ArrayList<String>();
+ for( String filePath: localPackageFileList) {
+ localPackageNameList.add(RPMPackageCommander.getPkgNameForFile(filePath));
+ }
+ for( Package pkg: PackageProvider.INSTANCE.getDevicePkgs()) {
+ if( localPackageNameList.contains( pkg.getName() ) ) {
+ pkg.setNewlyChanged(true);
+ }
+ }
+ }
+ }
+
+
+ private void createPackageFilter( Composite parent ) {
+ Composite composite = new Composite( parent, SWT.NONE );
+ composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL));
+ composite.setLayout(new GridLayout(3,false));
+
+ Label filterTextLabel = new Label(composite, SWT.NONE);
+ filterTextLabel.setText(resources.getString("PkgMgr.Label.Filter"));
+
+ categoryCombo = new Combo(composite, SWT.READ_ONLY);
+ String[] items = {"All","Installed","Upgradable"};
+ categoryCombo.setItems(items);
+ categoryCombo.addSelectionListener( new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ pkgViewer.refresh();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // do nothing
+ }
+ });
+ categoryCombo.select(0);
+
+
+ filterText = new Text( composite, SWT.SINGLE | SWT.BORDER | SWT.SEARCH);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
+ filterText.setLayoutData(gridData);
+ filterText.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ pkgViewer.refresh();
+ }
});
}
+
+
- private void createColumnsForRepoTable( Composite parent )
+ private void createPackageTable( Composite parent )
{
- String[] titles = {resources.getString("PkgMgr.Repo.Table.Column.1"),
- resources.getString("PkgMgr.Repo.Table.Column.2")};
- int[] bounds = { 200, 600 };
+ Composite composite = new Composite( parent, SWT.NONE );
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ composite.setLayout(new FillLayout());
- TableViewerColumn colName = createTableViewerColumn( repoViewer, titles[0], bounds[0], SWT.NONE);
- TableColumn column = colName.getColumn();
- column.addSelectionListener(new RepoTableSelectionAdapter(repoViewer));
+ pkgViewer = CheckboxTableViewer.newCheckList( composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CHECK );
+ createColumns( composite );
+ Table packageTable = pkgViewer.getTable();
+ packageTable.addListener( SWT.Selection, new Listener(){
- colName.setLabelProvider(new ColumnLabelProvider() {
@Override
- public String getText(Object element) {
- Repository repo = (Repository)element;
- return repo.getName();
+ public void handleEvent(Event event) {
+ if( event.detail == SWT.CHECK )
+ {
+ Package pkg = (Package)event.item.getData();
+ pkg.setCheckColumn( !pkg.getCheckColumn() );
+ }
}
});
- TableViewerColumn colUrl = createTableViewerColumn( repoViewer, titles[1], bounds[1], SWT.NONE);
- column = colUrl.getColumn();
- column.addSelectionListener(new RepoTableSelectionAdapter(repoViewer));
+ packageTable.setHeaderVisible(true);
+ packageTable.setLinesVisible(true);
+
+ pkgViewer.setContentProvider(new ArrayContentProvider());
+ pkgViewer.setCheckStateProvider(new ICheckStateProvider() {
- colUrl.setLabelProvider(new ColumnLabelProvider() {
@Override
- public String getText(Object element) {
- Repository repo = (Repository)element;
- return repo.getUri();
+ public boolean isChecked(Object element) {
+ Package pkg = (Package) element;
+ return pkg.isChecked();
}
- });
+
+ @Override
+ public boolean isGrayed(Object element) {
+ return false;
+ }
+ });
+ pkgViewer.addFilter( new ViewerFilter() {
+
+ @Override
+ public boolean select(Viewer viewer, Object parentElement,
+ Object element) {
+ Package pkg = (Package) element;
+ if ( categoryCombo != null ) {
+ if ( categoryCombo.getText().equals("Installed") &&
+ pkg.getInstalledVersion().isEmpty() ) {
+ return false;
+ }
+ if ( categoryCombo.getText().equals("Upgradable") &&
+ ( pkg.getInstalledVersion().isEmpty() ||
+ pkg.getNewVersion().isEmpty() ||
+ RPMPackageCommander.compareVersion(pkg.getInstalledVersion(),pkg.getNewVersion()) >= 0 )) {
+ return false;
+ }
+ }
+ if ( filterText != null && !pkg.getName().contains(filterText.getText()) ) {
+ return false;
+ }
+ return true;
+ }
+
+ });
+ pkgViewer.addCheckStateListener( new ICheckStateListener() {
+
+ @Override
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ Package pkg = (Package)event.getElement();
+ pkg.setChecked(true);
+ }
+ });
+ pkgViewer.setInput(PackageProvider.INSTANCE.getDevicePkgs());
}
+
+
private TableViewerColumn createTableViewerColumn(TableViewer viewer, String title, int bound, int Style) {
final TableViewerColumn viewerColumn = new TableViewerColumn( viewer, Style);
- final TableColumn column = viewerColumn.getColumn();
+ final TableColumn column = viewerColumn.getColumn();
column.addSelectionListener(new PackageTableSelectionAdapter(pkgViewer));
column.setText(title);
column.setWidth(bound);
private void createColumns( Composite parent )
{
- String[] titles = {"Install Type", "Package Name", "Arch", "New Version", "Installed Version", "Status"};
- int[] bounds = { 120, 250, 60, 150, 150, 150};
+ String[] titles = {"S", "Package Name", "Installed Version", "New Version", "Arch", "Description"};
+ int[] bounds = { 24, 200, 150, 150, 60, 150};
- TableViewerColumn colInstallType = createTableViewerColumn( pkgViewer, titles[0], bounds[0], SWT.NONE);
-
- colInstallType.setLabelProvider(new ColumnLabelProvider() {
+ TableViewerColumn colSelection = createTableViewerColumn( pkgViewer, titles[0], bounds[0], SWT.NONE);
+ colSelection.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
- Package pkg = (Package)element;
- return pkg.getPkgType().toString();
+ return "";
}
});
-
+
TableViewerColumn colPackage = createTableViewerColumn( pkgViewer, titles[1], bounds[1], SWT.NONE);
-
colPackage.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Package pkg = (Package)element;
- return pkg.getName();
+ if ( pkg.isNewlyChanged() ) {
+ return "*"+pkg.getName();
+ }
+ else {
+ return pkg.getName();
+ }
}
});
- TableViewerColumn colArch = createTableViewerColumn( pkgViewer, titles[2], bounds[2], SWT.NONE);
-
- colArch.setLabelProvider(new ColumnLabelProvider() {
+ TableViewerColumn colInsVer = createTableViewerColumn( pkgViewer, titles[2], bounds[2], SWT.NONE);
+ colInsVer.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Package pkg = (Package)element;
- String arch = pkg.getArch();
- return arch;
+ String installedVer = pkg.getInstalledVersion();
+ return installedVer;
}
});
+
TableViewerColumn colNewVer = createTableViewerColumn( pkgViewer, titles[3], bounds[3], SWT.NONE);
colNewVer.setLabelProvider(new ColumnLabelProvider() {
}
});
- TableViewerColumn colInsVer = createTableViewerColumn( pkgViewer, titles[4], bounds[4], SWT.NONE);
- colInsVer.setLabelProvider(new ColumnLabelProvider() {
+ TableViewerColumn colArch = createTableViewerColumn( pkgViewer, titles[4], bounds[4], SWT.NONE);
+
+ colArch.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Package pkg = (Package)element;
- String installedVer = pkg.getInstalledVersion();
- return installedVer;
+ String arch = pkg.getArch();
+ return arch;
}
});
- TableViewerColumn colStatus = createTableViewerColumn( pkgViewer, titles[5], bounds[5], SWT.NONE);
-
- colStatus.setLabelProvider(new ColumnLabelProvider() {
+ TableViewerColumn colDescription = createTableViewerColumn( pkgViewer, titles[5], bounds[5], SWT.NONE);
+ colDescription.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
- Package pkg = (Package)element;
- String status = pkg.getInstallInfo().toString();
- return status;
+ return "";
}
});
}
-
- private void genRemotePkgList() {
-
- PackageManagerOuputReceiver rec = getNewOuputReceiver();
- String list = RPMPackageCommander.getRemotePackageListForDevice(device, rec);
-
- String[] splitStr = list.split("\n");
-
- for (int i = 4 ; i < splitStr.length ; i++) {
- String s = splitStr[i];
- s = s.replaceAll(" ", "");
- String[] part = s.split("\\|");
- String status = part[0];
- String repo = part[1];
- String name = part[2];
- String version = part[3];
- String arch = part[4];
-
- RemotePackage pkg = new RemotePackage();
- pkg.setName(name);
- pkg.setArch(arch);
- pkg.setNewVersion(version);
- pkg.setRepo(repo);
- if ("i".equals(status)) {
- pkg.setCheckColumn(true);
- pkg.setInstallInfo(Package.INSTALLINFO.INSTALLED);
- } else if ("v".equals(status)) {
- pkg.setCheckColumn(false);
- pkg.setInstallInfo(Package.INSTALLINFO.DIFFERENT_VERSION);
- } else {
- pkg.setCheckColumn(false);
- }
-
- RemotePkgProvider.INSTANCE.getPkgs().add(pkg);
- }
- }
-
- private void addRemotePackage( RemotePackage p ) {
- CopyOnWriteArrayList<Package> pkgs = PackageProvider.INSTANCE.getDevicePkgs();
- Iterator<Package> debIter = pkgs.iterator();
-
- while( debIter.hasNext() ) {
- Package pkg = debIter.next();
- if( pkg.getName().equals(p.getName()) &&
- pkg.getNewVersion().equals(p.getNewVersion()) ) {
- return;
- }
- }
-
- PackageManagerOuputReceiver rec = getNewOuputReceiver();
- String installedVer = RPMPackageCommander.getPkgInstalledVerForDevice(p.getName(), device, rec);
-
- p.setInstalledVersion(installedVer);
- p.setCheckColumn(true);
- p.setPkgType(Package.PKGTYPE.REMOTE);
- PackageProvider.INSTANCE.getDevicePkgs().add(p);
- }
-
- private void addLocalPackage( String rpmPath )
- {
- CopyOnWriteArrayList<Package> pkgs = PackageProvider.INSTANCE.getDevicePkgs();
- Iterator<Package> debIter = pkgs.iterator();
-
- String pkgName = RPMPackageCommander.getPkgNameForFile(rpmPath);
- String newVer = RPMPackageCommander.getPkgVerForFile(rpmPath);
-
- while( debIter.hasNext() ) {
- Package pkg = debIter.next();
- if( pkg.getName().equals(pkgName) && pkg.getNewVersion().equals(newVer)) {
- return;
- }
- }
-
- LocalPackage pkg = new LocalPackage();
- pkg.setName(pkgName);
- pkg.setPath(rpmPath);
- pkg.setPkgType(Package.PKGTYPE.LOCAL);
- pkg.setArch(RPMPackageCommander.getArchForFile(rpmPath));
- pkg.setNewVersion(newVer);
-
- PackageManagerOuputReceiver rec = getNewOuputReceiver();
- String installedVerForRootstrap = RPMPackageCommander.getPkgInstalledVerForDevice(pkg.getName(), device, rec);
- pkg.setInstalledVersion(installedVerForRootstrap);
-
- if ("".equals(newVer)) {
- pkg.setCheckColumn(false);
- } else if (!"".equals(installedVerForRootstrap)) {
- if (!installedVerForRootstrap.equals(newVer)) {
- pkg.setInstallInfo(Package.INSTALLINFO.DIFFERENT_VERSION);
- } else {
- if (RPMPackageCommander.pkgInstalledSuccessfullyForDevice(pkgName, device, rec)) {
- pkg.setInstallInfo(Package.INSTALLINFO.INSTALLED);
- }
- }
- }
-
- PackageProvider.INSTANCE.getDevicePkgs().add(pkg);
- }
-
- private CopyOnWriteArrayList<Package> getSelectedPkg(CopyOnWriteArrayList<Package> pkgs) {
- CopyOnWriteArrayList<Package> _pkgs = new CopyOnWriteArrayList<Package>();
- for (Package pkg : pkgs) {
- if(pkg.getCheckColumn()) {
- _pkgs.add(pkg);
- }
- }
-
- return _pkgs;
- }
-
- private PackageManagerOuputReceiver getNewOuputReceiver() {
- ConsoleManager cm = new ConsoleManager(resources.getString("PkgMgr.Console.Name"), true);
- cm.clear();
- MessageConsoleStream mcsError = cm.getMessageConsoleStream();
- MessageConsoleStream mcs = cm.getMessageConsoleStream();
- PackageManagerOuputReceiver rec = new PackageManagerOuputReceiver();
- rec.setMessageConsoleStream(mcs);
-
- return rec;
- }
}