-
Notifications
You must be signed in to change notification settings - Fork 23
/
ArchivedLibraryImportWizardPage.java
75 lines (66 loc) · 2.63 KB
/
ArchivedLibraryImportWizardPage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*******************************************************************************
* Copyright (c) 2023 Primetals Technologies Austria GmbH
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Dunja Životin - initial API and implementation and/or initial documentation
*******************************************************************************/
package org.eclipse.fordiac.ide.typemanagement.wizards;
import java.io.File;
import java.io.IOException;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.fordiac.ide.typemanagement.Messages;
import org.eclipse.fordiac.ide.typemanagement.librarylinker.ArchivedLibraryImportContentProvider;
import org.eclipse.fordiac.ide.typemanagement.librarylinker.LibraryLinker;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.TreeItem;
public class ArchivedLibraryImportWizardPage extends LibraryImportWizardPage {
private LibraryLinker libraryLinker;
private File selectedFile;
private IProject selectedProject;
protected ArchivedLibraryImportWizardPage(final String pageName, final StructuredSelection selection) {
super(pageName);
setColumnTitle(Messages.DirsWithArchives);
final StructuredSelection sel = new StructuredSelection(selection.toList());
if (!sel.isEmpty()) {
if (sel.getFirstElement() instanceof final IProject project) {
selectedProject = project;
}
if ((sel.getFirstElement() instanceof final IFolder folder)
&& (folder.getParent() instanceof final IProject project)) {
selectedProject = project;
}
}
}
public void unzipAndImportArchive() throws IOException {
libraryLinker.extractLibrary(selectedFile, selectedProject, true);
}
@Override
protected void configureSelectionListener() {
viewer.getTree().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
final TreeItem item = (TreeItem) e.item;
if (item.getData() instanceof final File file && !file.isDirectory()) {
selectedFile = file;
setPageComplete(isComplete());
}
}
});
}
@Override
public void setVisible(final boolean visible) {
libraryLinker = new LibraryLinker();
viewer.setContentProvider(new ArchivedLibraryImportContentProvider());
viewer.setInput(libraryLinker.listDirectoriesContainingArchives());
super.setVisible(visible);
}
}