}
private void makeActions() {
actionAddRepository = new Action() {
public void run() {
DirectoryDialog dialog = new DirectoryDialog(getShell());
dialog.setMessage("Choose a repository");
String directory = dialog.open();
if (directory != null) {
File repositoryDirectory = new File(directory);
BundleRepositoryPersister persister = new BundleRepositoryPersister(repositoryDirectory);
if (persister.checkRepository()) {
addRepositoryPath(directory);
contentProvider.refresh();
viewer.refresh();
} else {
if (!directoryIsEmpty(repositoryDirectory)) {
if (!MessageDialog.openQuestion(getShell(), "Directory is not empty",
"The selected directory is not empty.\nCreating a repository will delete all files in this directory.\n" +
"Are you sure to continue?")) {
return;
}
}
NewRepositoryDialog newDialog = new NewRepositoryDialog(getShell(), directory);
if (newDialog.open() == IDialogConstants.OK_ID) {
Deployer deployer = new Deployer(repositoryDirectory);
try {
deployer.create(newDialog.getProfileName());
addRepositoryPath(directory);
contentProvider.refresh();
viewer.refresh();
} catch (IOException e) {
MessageDialog.openError(getShell(), "Add repository", "Could not create repository\n" + e.getMessage());
e.printStackTrace();
}
}
}
}
}
private boolean directoryIsEmpty(File directory) {
File[] files = directory.listFiles();
return files == null || files.length == 0;
}
};
actionAddRepository.setText("Add Repository...");
actionAddRepository.setToolTipText("Add a repository to the view");
actionAddRepository.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
ISharedImages.IMG_TOOL_NEW_WIZARD));
actionAddBundle = new Action() {
public void run() {
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN | SWT.MULTI);
dialog.setFilterNames(new String[] { "OSGi Bundle (*.jar)"});
dialog.setFilterExtensions(new String[] { "*.jar" });
dialog.setText("Choose a bundle");
if (dialog.open() != null) {
ISelection selection = viewer.getSelection();
TreeObject selectedItem = (TreeObject) ((IStructuredSelection) selection).getFirstElement();
ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(getShell());
try {
String[] files = dialog.getFileNames();
String path = dialog.getFilterPath();
for (int i = 0; i < files.length; i++) {
files[i] = path + File.separatorChar + files[i];
}
progressDialog.run(true, false, new BundleDeployJob(getRepositoryLocation(selectedItem), files));
viewer.refresh();