use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class DockerConnectionWatcher method selectionChanged.
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
final ITreeSelection treeSelection = (ITreeSelection) selection;
if (treeSelection.isEmpty()) {
setConnection(null);
return;
}
final Object firstSegment = treeSelection.getPaths()[0].getFirstSegment();
if (firstSegment instanceof IDockerConnection) {
setConnection((IDockerConnection) firstSegment);
}
}
use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class DockerConnectionWatcher method loadConnection.
// Load the previously selected connection at start-up
private IDockerConnection loadConnection() {
IDockerConnection connection = null;
final IPath stateLocation = Activator.getDefault().getStateLocation();
final File connectionFile = stateLocation.append(CONNECTION_FILE_NAME).toFile();
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
if (connectionFile.exists()) {
Document d = db.parse(connectionFile);
Element e = d.getDocumentElement();
// Get the stored configuration data
// $NON-NLS-1$
NodeList connectionNodes = e.getElementsByTagName("connection");
if (connectionNodes == null || connectionNodes.getLength() == 0) {
return null;
}
Node n = connectionNodes.item(0);
NamedNodeMap attrs = n.getAttributes();
// $NON-NLS-1$
Node nameNode = attrs.getNamedItem("name");
// $NON-NLS-1$
Node uriNode = attrs.getNamedItem("uri");
// $NON-NLS-1$
Node usernameNode = attrs.getNamedItem("username");
if (uriNode != null) {
String uri = uriNode.getNodeValue();
String name = nameNode.getNodeValue();
String username = null;
if (usernameNode != null) {
username = usernameNode.getNodeValue();
}
IDockerConnection[] connections = DockerConnectionManager.getInstance().getConnections();
for (IDockerConnection c : connections) {
if (c.getUri().equals(uri)) {
if (c.getName().equals(name)) {
if (c.getUsername() == null || c.getUsername().equals(username)) {
connection = c;
break;
}
}
}
}
}
}
} catch (ParserConfigurationException | SAXException | IOException e) {
Activator.log(e);
}
return connection;
}
use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class BaseImagesCommandHandler method execute.
@Override
public Object execute(ExecutionEvent event) {
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
final List<IDockerImage> selectedImages = getSelectedImages(activePart);
final IDockerConnection connection = getCurrentConnection(activePart);
if (connection == null || selectedImages.isEmpty()) {
Activator.log(new DockerException(CommandMessages.getString(// $NON-NLS-1$
"Command.missing.selection.failure")));
return null;
}
final Job job = new Job(getJobName(selectedImages)) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
if (confirmed(selectedImages)) {
monitor.beginTask(getJobName(selectedImages), selectedImages.size());
for (final IDockerImage image : selectedImages) {
monitor.setTaskName(getTaskName(image));
executeInJob(image, connection);
monitor.worked(1);
}
}
monitor.done();
return Status.OK_STATUS;
}
};
job.setPriority(Job.LONG);
job.setUser(true);
job.schedule();
return null;
}
use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class CommitContainerCommandHandler method performCommitContainer.
private void performCommitContainer(final ContainerCommit wizard, final IDockerConnection connection, final IDockerContainer container) {
final Job commitContainerJob = new Job(DVMessages.getString(COMMIT_CONTAINER_JOB_TITLE)) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
final String tag = wizard.getTag();
final String repo = wizard.getRepo();
final String author = wizard.getAuthor();
final String comment = wizard.getComment();
monitor.beginTask(DVMessages.getString(COMMIT_CONTAINER_MSG), 1);
// commit the Container and then update the list of Images
try {
((DockerConnection) connection).commitContainer(container.id(), repo, tag, comment, author);
monitor.worked(1);
} catch (DockerException e) {
Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getFormattedString(ERROR_COMMITTING_CONTAINER, tag), e.getMessage()));
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
commitContainerJob.schedule();
}
use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class ConfigureLabelsCommandHandler method execute.
@SuppressWarnings("unused")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ConfigureLabels wizard = new ConfigureLabels();
final boolean configureLabels = CommandUtils.openWizard(wizard, HandlerUtil.getActiveShell(event));
if (configureLabels) {
Map<String, String> labels = wizard.getConfigureLabels();
StringBuffer buffer = new StringBuffer();
for (Entry<String, String> entry : labels.entrySet()) {
buffer.append(entry.getKey());
// $NON-NLS-1$
buffer.append('=');
buffer.append(entry.getValue());
buffer.append('\u00a0');
}
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
preferences.put(CONTAINER_FILTER_LABELS, buffer.toString());
IDockerConnection connection = CommandUtils.getCurrentConnection(null);
// force refresh
connection.getContainers(true);
}
return null;
}
Aggregations