Example usage for com.intellij.openapi.vfs VirtualFileWrapper getFile

List of usage examples for com.intellij.openapi.vfs VirtualFileWrapper getFile

Introduction

In this page you can find the example usage for com.intellij.openapi.vfs VirtualFileWrapper getFile.

Prototype

@NotNull
public File getFile() 

Source Link

Document

Returns original java.io.File

Usage

From source file:com.android.tools.idea.actions.ConvertToNinePatchAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    final VirtualFile pngFile = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
    if (!isPngFile(pngFile)) {
        return;/*from ww  w  .  j a va  2s.  c  om*/
    }

    FileSaverDescriptor descriptor = new FileSaverDescriptor(
            AndroidBundle.message("android.9patch.creator.save.title"), "", SdkConstants.EXT_PNG);
    FileSaverDialog saveFileDialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor,
            (Project) null);
    VirtualFileWrapper fileWrapper = saveFileDialog.save(pngFile.getParent(),
            pngFile.getNameWithoutExtension().concat(SdkConstants.DOT_9PNG));
    if (fileWrapper == null) {
        return;
    }

    final File patchFile = fileWrapper.getFile();
    new Task.Modal(null, "Creating 9-Patch File", false) {
        private IOException myException;

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            try {
                BufferedImage pngImage = ImageIO.read(VfsUtilCore.virtualToIoFile(pngFile));
                BufferedImage patchImage = ImageUtils.addMargin(pngImage, 1);
                ImageIO.write(patchImage, SdkConstants.EXT_PNG, patchFile);
                LocalFileSystem.getInstance().refreshAndFindFileByIoFile(patchFile);
            } catch (IOException e) {
                myException = e;
            }
        }

        @Override
        public void onSuccess() {
            if (myException != null) {
                Messages.showErrorDialog(
                        AndroidBundle.message("android.9patch.creator.error", myException.getMessage()),
                        AndroidBundle.message("android.9patch.creator.error.title"));
            }
        }
    }.queue();
}

From source file:com.android.tools.idea.avdmanager.ExportDeviceAction.java

License:Apache License

@Override
public void actionPerformed(ActionEvent e) {
    FileSaverDescriptor descriptor = new FileSaverDescriptor("Export Location",
            "Select a location for the exported device", "xml");
    String homePath = System.getProperty("user.home");
    File parentPath = homePath == null ? new File("/") : new File(homePath);
    VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath);
    VirtualFileWrapper fileWrapper = FileChooserFactory.getInstance()
            .createSaveFileDialog(descriptor, (Project) null).save(parent, "device.xml");
    Device device = myProvider.getDevice();
    if (device != null && fileWrapper != null) {
        DeviceManagerConnection.writeDevicesToFile(ImmutableList.of(device), fileWrapper.getFile());
    }//  ww w  .ja  v  a2  s . c  o m
}

From source file:com.android.tools.idea.ddms.screenshot.ScreenshotViewer.java

License:Apache License

@Override
protected void doOKAction() {
    FileSaverDescriptor descriptor = new FileSaverDescriptor(
            AndroidBundle.message("android.ddms.screenshot.save.title"), "", SdkConstants.EXT_PNG);
    FileSaverDialog saveFileDialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor,
            myProject);/*from www.  j  ava  2s. c o m*/
    VirtualFile baseDir = ourLastSavedFolder != null ? ourLastSavedFolder : myProject.getBaseDir();
    VirtualFileWrapper fileWrapper = saveFileDialog.save(baseDir, getDefaultFileName());
    if (fileWrapper == null) {
        return;
    }

    myScreenshotFile = fileWrapper.getFile();
    try {
        ImageIO.write(myDisplayedImageRef.get(), SdkConstants.EXT_PNG, myScreenshotFile);
    } catch (IOException e) {
        Messages.showErrorDialog(myProject, AndroidBundle.message("android.ddms.screenshot.save.error", e),
                AndroidBundle.message("android.ddms.actions.screenshot"));
        return;
    }

    VirtualFile virtualFile = fileWrapper.getVirtualFile();
    if (virtualFile != null) {
        //noinspection AssignmentToStaticFieldFromInstanceMethod
        ourLastSavedFolder = virtualFile.getParent();
    }

    super.doOKAction();
}

From source file:com.android.tools.idea.npw.deprecated.ConfigureAndroidProjectStep.java

License:Apache License

private void browseForFile() {
    FileSaverDescriptor fileSaverDescriptor = new FileSaverDescriptor("Project location",
            "Please choose a location for your project");
    File currentPath = new File(myProjectLocation.getText());
    File parentPath = currentPath.getParentFile();
    if (parentPath == null) {
        String homePath = System.getProperty("user.home");
        parentPath = new File(homePath == null ? "/" : homePath);
    }//from   w w  w .j  a v a2  s  .  c  om
    VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath);
    String filename = currentPath.getName();
    VirtualFileWrapper fileWrapper = FileChooserFactory.getInstance()
            .createSaveFileDialog(fileSaverDescriptor, (Project) null).save(parent, filename);
    if (fileWrapper != null) {
        myProjectLocation.setText(fileWrapper.getFile().getAbsolutePath());
    }
}

From source file:com.android.tools.idea.wizard.ConfigureAndroidModuleStep.java

License:Apache License

public ConfigureAndroidModuleStep(TemplateWizardState state, @Nullable Project project,
        @Nullable Icon sidePanelIcon, UpdateListener updateListener) {
    super(state, project, sidePanelIcon, updateListener);

    IAndroidTarget[] targets = getCompilationTargets();

    if (AndroidSdkUtils.isAndroidSdkAvailable()) {
        String[] knownVersions = TemplateUtils.getKnownVersions();

        for (int i = 0; i < knownVersions.length; i++) {
            AndroidTargetComboBoxItem targetInfo = new AndroidTargetComboBoxItem(knownVersions[i], i + 1);
            myMinSdk.addItem(targetInfo);
            myTargetSdk.addItem(targetInfo);
        }//from  w  w  w .  ja  va 2s  . co m
    }
    for (IAndroidTarget target : targets) {
        AndroidTargetComboBoxItem targetInfo = new AndroidTargetComboBoxItem(target);
        myTemplateState.put(ATTR_BUILD_API, targetInfo.apiLevel);
        myCompileWith.addItem(targetInfo);
        if (target.getVersion().isPreview()) {
            myMinSdk.addItem(targetInfo);
            myTargetSdk.addItem(targetInfo);
        }
    }

    registerUiElements();

    myProjectLocation.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FileSaverDescriptor fileSaverDescriptor = new FileSaverDescriptor("Project location",
                    "Please choose a location for your project");
            File currentPath = new File(myProjectLocation.getText());
            File parentPath = currentPath.getParentFile();
            if (parentPath == null) {
                parentPath = new File("/");
            }
            VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath);
            String filename = currentPath.getName();
            VirtualFileWrapper fileWrapper = FileChooserFactory.getInstance()
                    .createSaveFileDialog(fileSaverDescriptor, (Project) null).save(parent, filename);
            if (fileWrapper != null && fileWrapper.getFile() != null) {
                myProjectLocation.setText(fileWrapper.getFile().getAbsolutePath());
            }
        }
    });
    myProjectLocation.getTextField().addFocusListener(this);
    myProjectLocation.getTextField().getDocument().addDocumentListener(this);
    if (myTemplateState.myHidden.contains(ATTR_PROJECT_LOCATION)) {
        myProjectLocation.setVisible(false);
        myProjectLocationLabel.setVisible(false);
    }
    if (myTemplateState.myHidden.contains(ATTR_IS_LIBRARY_MODULE)) {
        myLibraryCheckBox.setVisible(false);
    }
    if (myTemplateState.myHidden.contains(ATTR_MODULE_NAME)) {
        myModuleName.setVisible(false);
        myModuleNameLabel.setVisible(false);
    }
}

From source file:com.android.tools.idea.wizard.ConfigureAndroidProjectStep.java

License:Apache License

private void browseForFile() {
    FileSaverDescriptor fileSaverDescriptor = new FileSaverDescriptor("Project location",
            "Please choose a location for your project");
    File currentPath = new File(myProjectLocation.getText());
    File parentPath = currentPath.getParentFile();
    if (parentPath == null) {
        String homePath = System.getProperty("user.home");
        parentPath = homePath == null ? new File("/") : new File(homePath);
    }//w  w w .jav  a 2s  .  co  m
    VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath);
    String filename = currentPath.getName();
    VirtualFileWrapper fileWrapper = FileChooserFactory.getInstance()
            .createSaveFileDialog(fileSaverDescriptor, (Project) null).save(parent, filename);
    if (fileWrapper != null) {
        myProjectLocation.setText(fileWrapper.getFile().getAbsolutePath());
    }
}

From source file:com.android.tools.idea.wizard.GetSdkStep.java

License:Apache License

@Nullable
private String getSaveLocation(@Nullable String currentPath) {
    VirtualFile currentFile = null;/*w  w  w  .  j  a va2s.com*/
    if (currentPath != null && !currentPath.isEmpty()) {
        currentFile = VfsUtil.findFileByIoFile(new File(currentPath), false);
    }
    FileSaverDescriptor fileSaverDescriptor = new FileSaverDescriptor("SDK location",
            "Please choose an installation location for your SDK");
    VirtualFileWrapper fileWrapper = FileChooserFactory.getInstance()
            .createSaveFileDialog(fileSaverDescriptor, (Project) null).save(currentFile, "android_sdk");
    if (fileWrapper != null) {
        return fileWrapper.getFile().getPath();
    } else {
        return null;
    }
}

From source file:com.hp.alm.ali.idea.action.attachment.AttachmentDownloadAction.java

License:Apache License

@Override
protected void actionPerformed(AnActionEvent event, Project project, Entity entity) {
    String name = entity.getPropertyValue("name");
    FileSaverDescriptor desc = new FileSaverDescriptor("Download Attachment",
            "Download attachment to the local filesystem.");
    final VirtualFileWrapper file = FileChooserFactory.getInstance().createSaveFileDialog(desc, project)
            .save(lastDir, name.replaceFirst("\\.agmlink$", ""));
    if (file != null) {
        VirtualFile vf = file.getVirtualFile(true);
        if (vf == null) {
            Messages.showErrorDialog("Invalid file specified", "Error");
            return;
        }//from  www. j  a va 2 s .  c om
        lastDir = vf.getParent();
        if (!name.endsWith(".agmlink") || file.getFile().getName().endsWith(".agmlink")) {
            // either regular file or we explicitly ask for .agmlink file
            ProgressManager.getInstance()
                    .run(new AttachmentDownloadTask(project, file.getFile(), name,
                            Integer.valueOf(entity.getPropertyValue("file-size")),
                            new EntityRef(entity.getPropertyValue("parent-type"),
                                    Integer.valueOf(entity.getPropertyValue("parent-id"))),
                            null));
        } else {
            // download referenced content instead
            ProgressManager.getInstance()
                    .run(new AttachmentAgmLinkDownloadTask(project, file.getFile(), name,
                            Integer.valueOf(entity.getPropertyValue("file-size")),
                            new EntityRef(entity.getPropertyValue("parent-type"),
                                    Integer.valueOf(entity.getPropertyValue("parent-id"))),
                            null));
        }
    }
}

From source file:com.hp.alm.ali.idea.cfg.AliConfigurable.java

License:Apache License

protected Component getSouthernComponent() {
    JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final TroubleShootService troubleShootService = ApplicationManager.getApplication()
            .getComponent(TroubleShootService.class);
    final JButton troubleshoot = new JButton(
            troubleShootService.isRunning() ? "Stop Troubleshoot" : "Troubleshoot");
    troubleshoot.addActionListener(new ActionListener() {
        @Override/*www  .  j  a  va2s.c  o m*/
        public void actionPerformed(ActionEvent e) {
            if (troubleshoot.getText().equals("Troubleshoot")) {
                if (!troubleShootService.isRunning()) {
                    if (Messages.showYesNoDialog("Do you want to log complete ALM server communication?",
                            "Confirmation", null) == Messages.YES) {
                        FileSaverDescriptor desc = new FileSaverDescriptor("Log server communication",
                                "Log server communication on the local filesystem.");
                        final VirtualFileWrapper file = FileChooserFactory.getInstance()
                                .createSaveFileDialog(desc, troubleshoot).save(null, "REST_log.txt");
                        if (file == null) {
                            return;
                        }

                        troubleShootService.start(file.getFile());
                        troubleshoot.setText("Stop Troubleshoot");
                    }
                }
            } else {
                troubleShootService.stop();
                troubleshoot.setText("Troubleshoot");
            }
        }
    });
    southPanel.add(troubleshoot);
    return southPanel;
}

From source file:com.microsoft.intellij.ui.NewCertificateDialog.java

License:Open Source License

private ActionListener getFileSaverListener(final TextFieldWithBrowseButton field,
        final TextFieldWithBrowseButton fieldToUpdate, final String suffixToReplace, final String suffix) {
    return new ActionListener() {
        @Override//from ww w. j av a  2s.com
        public void actionPerformed(ActionEvent e) {
            final FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(
                    new FileSaverDescriptor(message("newCertDlgBrwFldr"), "", suffixToReplace), field);
            final VirtualFile baseDir = myProject.getBaseDir();
            final VirtualFileWrapper save = dialog.save(baseDir, "");
            if (save != null) {
                field.setText(FileUtil.toSystemDependentName(save.getFile().getAbsolutePath()));
                if (fieldToUpdate.getText().isEmpty()) {
                    fieldToUpdate.setText(Utils.replaceLastSubString(field.getText(), suffixToReplace, suffix));
                }
            }
        }
    };
}