Search in sources :

Example 11 with BlobFile

use of com.microsoft.tooling.msservices.model.storage.BlobFile in project azure-tools-for-java by Microsoft.

the class BlobExplorerFileEditor method deleteSelectedFile.

private void deleteSelectedFile() {
    final BlobFile blobItem = getFileSelection();
    if (blobItem != null) {
        if (JOptionPane.showConfirmDialog(mainPanel, "Are you sure you want to delete this blob?", "Delete Blob", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.OK_OPTION) {
            setUIState(true);
            ProgressManager.getInstance().run(new Task.Backgroundable(project, "Deleting blob...", false) {

                @Override
                public void run(@NotNull ProgressIndicator progressIndicator) {
                    progressIndicator.setIndeterminate(true);
                    try {
                        StorageClientSDKManager.getManager().deleteBlobFile(connectionString, blobItem);
                        if (blobItems.size() <= 1) {
                            directoryQueue.clear();
                            directoryQueue.addLast(StorageClientSDKManager.getManager().getRootDirectory(connectionString, blobContainer));
                            queryTextField.setText("");
                        }
                        ApplicationManager.getApplication().invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                fillGrid();
                            }
                        });
                    } catch (AzureCmdException ex) {
                        String msg = "An error occurred while attempting to delete blob." + "\n" + String.format(message("webappExpMsg"), ex.getMessage());
                        PluginUtil.displayErrorDialogAndLog(message("errTtl"), msg, ex);
                    }
                }
            });
        }
    }
}
Also used : Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) BlobFile(com.microsoft.tooling.msservices.model.storage.BlobFile)

Example 12 with BlobFile

use of com.microsoft.tooling.msservices.model.storage.BlobFile in project azure-tools-for-java by Microsoft.

the class BlobExplorerFileEditor method saveAsSelectedFile.

private void saveAsSelectedFile() {
    BlobFile fileSelection = getFileSelection();
    assert fileSelection != null;
    JFileChooser jFileChooser = new JFileChooser(new File(fileSelection.getName()));
    jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int saveDialog = jFileChooser.showSaveDialog(this.mainPanel);
    if (saveDialog == JFileChooser.APPROVE_OPTION) {
        downloadSelectedFile(jFileChooser.getSelectedFile(), false);
    }
}
Also used : BlobFile(com.microsoft.tooling.msservices.model.storage.BlobFile) BlobFile(com.microsoft.tooling.msservices.model.storage.BlobFile)

Example 13 with BlobFile

use of com.microsoft.tooling.msservices.model.storage.BlobFile in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method getBlobItems.

@NotNull
public List<BlobItem> getBlobItems(@NotNull String connectionString, @NotNull BlobDirectory blobDirectory) throws AzureCmdException {
    List<BlobItem> biList = new ArrayList<BlobItem>();
    try {
        CloudBlobClient client = getCloudBlobClient(connectionString);
        String containerName = blobDirectory.getContainerName();
        String delimiter = client.getDirectoryDelimiter();
        CloudBlobContainer container = client.getContainerReference(containerName);
        CloudBlobDirectory directory = container.getDirectoryReference(blobDirectory.getPath());
        for (ListBlobItem item : directory.listBlobs()) {
            String uri = item.getUri() != null ? item.getUri().toString() : "";
            if (item instanceof CloudBlobDirectory) {
                CloudBlobDirectory subDirectory = (CloudBlobDirectory) item;
                String name = extractBlobItemName(subDirectory.getPrefix(), delimiter);
                String path = Strings.nullToEmpty(subDirectory.getPrefix());
                biList.add(new BlobDirectory(name, uri, containerName, path));
            } else if (item instanceof CloudBlob) {
                CloudBlob blob = (CloudBlob) item;
                String name = extractBlobItemName(blob.getName(), delimiter);
                String path = Strings.nullToEmpty(blob.getName());
                String type = "";
                String cacheControlHeader = "";
                String contentEncoding = "";
                String contentLanguage = "";
                String contentType = "";
                String contentMD5Header = "";
                String eTag = "";
                Calendar lastModified = new GregorianCalendar();
                long size = 0;
                BlobProperties properties = blob.getProperties();
                if (properties != null) {
                    if (properties.getBlobType() != null) {
                        type = properties.getBlobType().toString();
                    }
                    cacheControlHeader = Strings.nullToEmpty(properties.getCacheControl());
                    contentEncoding = Strings.nullToEmpty(properties.getContentEncoding());
                    contentLanguage = Strings.nullToEmpty(properties.getContentLanguage());
                    contentType = Strings.nullToEmpty(properties.getContentType());
                    contentMD5Header = Strings.nullToEmpty(properties.getContentMD5());
                    eTag = Strings.nullToEmpty(properties.getEtag());
                    if (properties.getLastModified() != null) {
                        lastModified.setTime(properties.getLastModified());
                    }
                    size = properties.getLength();
                }
                biList.add(new BlobFile(name, uri, containerName, path, type, cacheControlHeader, contentEncoding, contentLanguage, contentType, contentMD5Header, eTag, lastModified, size));
            }
        }
        return biList;
    } catch (Throwable t) {
        throw new AzureCmdException("Error retrieving the Blob Item list", t);
    }
}
Also used : BlobDirectory(com.microsoft.tooling.msservices.model.storage.BlobDirectory) BlobFile(com.microsoft.tooling.msservices.model.storage.BlobFile) BlobItem(com.microsoft.tooling.msservices.model.storage.BlobItem) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 14 with BlobFile

use of com.microsoft.tooling.msservices.model.storage.BlobFile in project azure-tools-for-java by Microsoft.

the class BlobExplorerFileEditor method deleteSelectedFile.

private void deleteSelectedFile() {
    final BlobFile blobItem = getFileSelection();
    if (blobItem != null) {
        if (DefaultLoader.getUIHelper().showConfirmation("Are you sure you want to delete this blob?", "Delete Blob", new String[] { "Yes", "No" }, null)) {
            setUIState(true);
            DefaultLoader.getIdeHelper().runInBackground(null, "Deleting blob...", false, true, "Deleting blob...", new Runnable() {

                @Override
                public void run() {
                    try {
                        StorageClientSDKManager.getManager().deleteBlobFile(connectionString, blobItem);
                        if (blobItems.size() <= 1) {
                            directoryQueue.clear();
                            directoryQueue.addLast(StorageClientSDKManager.getManager().getRootDirectory(connectionString, blobContainer));
                        }
                        DefaultLoader.getIdeHelper().invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                if (blobItems.size() <= 1) {
                                    queryTextField.setText("");
                                }
                                fillGrid();
                            }
                        });
                    } catch (AzureCmdException ex) {
                        DefaultLoader.getUIHelper().showException("Error deleting blob.", ex, "Error deleting blob", false, true);
                    }
                }
            });
        }
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) BlobFile(com.microsoft.tooling.msservices.model.storage.BlobFile)

Aggregations

BlobFile (com.microsoft.tooling.msservices.model.storage.BlobFile)14 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)8 BlobItem (com.microsoft.tooling.msservices.model.storage.BlobItem)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Task (com.intellij.openapi.progress.Task)3 BlobDirectory (com.microsoft.tooling.msservices.model.storage.BlobDirectory)3 SocketTimeoutException (java.net.SocketTimeoutException)3 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)2 BufferedInputStream (java.io.BufferedInputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 PartInitException (org.eclipse.ui.PartInitException)2 CallableSingleArg (com.microsoft.tooling.msservices.helpers.CallableSingleArg)1 Clipboard (java.awt.datatransfer.Clipboard)1 StringSelection (java.awt.datatransfer.StringSelection)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1