Search in sources :

Example 11 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.

the class ServerExplorerToolWindowFactory method createToolWindowContent.

@Override
@AzureOperation(name = "common|explorer.initialize", type = AzureOperation.Type.SERVICE)
public void createToolWindowContent(@NotNull final Project project, @NotNull final ToolWindow toolWindow) {
    // initialize azure service module
    AzureModule azureModule = new AzureModuleImpl(project);
    HDInsightUtil.setHDInsightRootModule(azureModule);
    azureModule.setSparkServerlessModule(new CosmosSparkClusterRootModuleImpl(azureModule));
    azureModule.setArcadiaModule(new ArcadiaSparkClusterRootModuleImpl(azureModule));
    // initialize aris service module
    SqlBigDataClusterModule arisModule = new SqlBigDataClusterModule(project);
    // initialize with all the service modules
    DefaultTreeModel treeModel = new DefaultTreeModel(initRoot(project, ImmutableList.of(azureModule, arisModule)));
    treeModelMap.put(project, treeModel);
    // initialize tree
    final JTree tree = new Tree(treeModel);
    tree.setRootVisible(false);
    tree.setCellRenderer(new NodeTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    new TreeSpeedSearch(tree);
    final DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot();
    final DefaultMutableTreeNode azureRoot = (DefaultMutableTreeNode) root.getChildAt(0);
    final List<? extends com.microsoft.azure.toolkit.intellij.common.component.Tree.TreeNode<?>> modules = AzureExplorer.getModules().stream().map(m -> new com.microsoft.azure.toolkit.intellij.common.component.Tree.TreeNode<>(m, tree)).collect(Collectors.toList());
    modules.forEach(azureRoot::add);
    azureModule.setClearResourcesListener(() -> modules.forEach(m -> m.clearChildren()));
    com.microsoft.azure.toolkit.intellij.common.component.Tree.installPopupMenu(tree);
    treeModel.reload();
    DataManager.registerDataProvider(tree, dataId -> {
        if (StringUtils.equals(dataId, Action.SOURCE)) {
            final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            if (Objects.nonNull(selectedNode)) {
                return selectedNode.getUserObject();
            }
        }
        return null;
    });
    // add a click handler for the tree
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
                treeNodeDblClicked(e, tree, project);
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            treeMousePressed(e, tree);
        }
    });
    // add keyboard handler for the tree
    tree.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            TreePath treePath = tree.getAnchorSelectionPath();
            if (treePath == null) {
                return;
            }
            final Object raw = treePath.getLastPathComponent();
            if (raw instanceof com.microsoft.azure.toolkit.intellij.common.component.Tree.TreeNode || raw instanceof LoadingNode) {
                return;
            }
            SortableTreeNode treeNode = (SortableTreeNode) raw;
            Node node = (Node) treeNode.getUserObject();
            Rectangle rectangle = tree.getRowBounds(tree.getRowForPath(treePath));
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                if (!node.isLoading()) {
                    node.getClickAction().fireNodeActionEvent();
                }
            } else if (e.getKeyCode() == KeyEvent.VK_CONTEXT_MENU) {
                if (node.hasNodeActions()) {
                    JPopupMenu menu = createPopupMenuForNode(node);
                    menu.show(e.getComponent(), (int) rectangle.getX(), (int) rectangle.getY());
                }
            }
        }
    });
    // add the tree to the window
    toolWindow.getComponent().add(new JBScrollPane(tree));
    // set tree and tree path to expand the node later
    azureModule.setTree(tree);
    azureModule.setTreePath(tree.getPathForRow(0));
    // setup toolbar icons
    addToolbarItems(toolWindow, project, azureModule);
}
Also used : AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager) ObservableList(com.microsoft.tooling.msservices.helpers.collections.ObservableList) ListChangedEvent(com.microsoft.tooling.msservices.helpers.collections.ListChangedEvent) NodeAction(com.microsoft.tooling.msservices.serviceexplorer.NodeAction) StringUtils(org.apache.commons.lang3.StringUtils) AzureModule(com.microsoft.tooling.msservices.serviceexplorer.azure.AzureModule) SqlBigDataClusterModule(com.microsoft.azure.sqlbigdata.serverexplore.SqlBigDataClusterModule) AzureIconSymbol(com.microsoft.tooling.msservices.serviceexplorer.AzureIconSymbol) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) UIHelperImpl(com.microsoft.intellij.helpers.UIHelperImpl) StorageModule(com.microsoft.tooling.msservices.serviceexplorer.azure.storage.StorageModule) ProjectManager(com.intellij.openapi.project.ProjectManager) Map(java.util.Map) MouseAdapter(java.awt.event.MouseAdapter) RefreshableNode(com.microsoft.tooling.msservices.serviceexplorer.RefreshableNode) AzureExplorer(com.microsoft.azure.toolkit.intellij.explorer.AzureExplorer) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) ToolWindow(com.intellij.openapi.wm.ToolWindow) LoadingNode(com.intellij.ui.LoadingNode) AzureModuleImpl(com.microsoft.intellij.serviceexplorer.azure.AzureModuleImpl) TreePath(javax.swing.tree.TreePath) Collection(java.util.Collection) KeyEvent(java.awt.event.KeyEvent) Collectors(java.util.stream.Collectors) MutableTreeNode(javax.swing.tree.MutableTreeNode) JBScrollPane(com.intellij.ui.components.JBScrollPane) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) CosmosSparkClusterRootModuleImpl(com.microsoft.azure.cosmosspark.serverexplore.cosmossparknode.CosmosSparkClusterRootModuleImpl) Action(com.microsoft.azure.toolkit.lib.common.action.Action) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) KeyListener(java.awt.event.KeyListener) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) TreeNode(javax.swing.tree.TreeNode) AzureIconLoader(com.microsoft.intellij.helpers.AzureIconLoader) Node(com.microsoft.tooling.msservices.serviceexplorer.Node) HDInsightUtil(com.microsoft.azure.hdinsight.common.HDInsightUtil) HashMap(java.util.HashMap) ToolWindowFactory(com.intellij.openapi.wm.ToolWindowFactory) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) LinkedHashMap(java.util.LinkedHashMap) ImmutableList(com.google.common.collect.ImmutableList) ArcadiaSparkClusterRootModuleImpl(com.microsoft.azure.arcadia.serverexplore.ArcadiaSparkClusterRootModuleImpl) Project(com.intellij.openapi.project.Project) Tree(com.intellij.ui.treeStructure.Tree) DefaultLoader(com.microsoft.tooling.msservices.components.DefaultLoader) DataManager(com.intellij.ide.DataManager) PropertyChangeEvent(java.beans.PropertyChangeEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) AzurePlugin(com.microsoft.intellij.AzurePlugin) AzureSignInAction(com.microsoft.intellij.actions.AzureSignInAction) SelectSubscriptionsAction(com.microsoft.intellij.actions.SelectSubscriptionsAction) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) ListChangeListener(com.microsoft.tooling.msservices.helpers.collections.ListChangeListener) VMArmModule(com.microsoft.tooling.msservices.serviceexplorer.azure.vmarm.VMArmModule) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) ToolWindowEx(com.intellij.openapi.wm.ex.ToolWindowEx) Comparator(java.util.Comparator) javax.swing(javax.swing) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) RefreshableNode(com.microsoft.tooling.msservices.serviceexplorer.RefreshableNode) LoadingNode(com.intellij.ui.LoadingNode) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) Node(com.microsoft.tooling.msservices.serviceexplorer.Node) KeyEvent(java.awt.event.KeyEvent) ArcadiaSparkClusterRootModuleImpl(com.microsoft.azure.arcadia.serverexplore.ArcadiaSparkClusterRootModuleImpl) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) AzureModule(com.microsoft.tooling.msservices.serviceexplorer.azure.AzureModule) Tree(com.intellij.ui.treeStructure.Tree) MouseEvent(java.awt.event.MouseEvent) CosmosSparkClusterRootModuleImpl(com.microsoft.azure.cosmosspark.serverexplore.cosmossparknode.CosmosSparkClusterRootModuleImpl) MouseAdapter(java.awt.event.MouseAdapter) LoadingNode(com.intellij.ui.LoadingNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) SqlBigDataClusterModule(com.microsoft.azure.sqlbigdata.serverexplore.SqlBigDataClusterModule) AzureModuleImpl(com.microsoft.intellij.serviceexplorer.azure.AzureModuleImpl) TreePath(javax.swing.tree.TreePath) KeyListener(java.awt.event.KeyListener) JBScrollPane(com.intellij.ui.components.JBScrollPane) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 12 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.

the class IDEHelperImpl method saveFileToAzure.

@AzureOperation(name = "appservice|file.save", params = { "appServiceFile.getName()" }, type = AzureOperation.Type.SERVICE)
private void saveFileToAzure(final AppServiceFile appServiceFile, final String content, final Project project) {
    final AzureString title = AzureOperationBundle.title("appservice|file.save", appServiceFile.getName());
    AzureTaskManager.getInstance().runInBackground(new AzureTask<>(project, title, false, () -> {
        final IAppService appService = appServiceFile.getApp();
        final AppServiceFile target = appService.getFileByPath(appServiceFile.getPath());
        final boolean deleted = target == null;
        final boolean outDated = !deleted && ZonedDateTime.parse(target.getMtime()).isAfter(ZonedDateTime.parse(appServiceFile.getMtime()));
        boolean toSave = true;
        if (deleted) {
            toSave = DefaultLoader.getUIHelper().showYesNoDialog(null, String.format(FILE_HAS_BEEN_DELETED, appServiceFile.getName()), APP_SERVICE_FILE_EDITING, Messages.getQuestionIcon());
        } else if (outDated) {
            toSave = DefaultLoader.getUIHelper().showYesNoDialog(null, String.format(FILE_HAS_BEEN_MODIFIED, appServiceFile.getName()), APP_SERVICE_FILE_EDITING, Messages.getQuestionIcon());
        }
        if (toSave) {
            appService.uploadFileToPath(content, appServiceFile.getPath());
            PluginUtil.showInfoNotification(APP_SERVICE_FILE_EDITING, String.format(FILE_HAS_BEEN_SAVED, appServiceFile.getName()));
        }
    }));
}
Also used : IAppService(com.microsoft.azure.toolkit.lib.appservice.service.IAppService) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AppServiceFile(com.microsoft.azure.toolkit.lib.appservice.model.AppServiceFile) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 13 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.

the class SelectSubscriptionsAction method onActionPerformed.

@Override
@AzureOperation(name = "account|subscription.select", type = AzureOperation.Type.ACTION)
public boolean onActionPerformed(@NotNull AnActionEvent e, @Nullable Operation operation) {
    Project project = DataKeys.PROJECT.getData(e.getDataContext());
    selectSubscriptions(project).subscribe();
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 14 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.

the class SpringCloudDeploymentConfigurationState method execute.

@AzureOperation(name = "springcloud|app.create_update", params = { "this.config.getAppConfig().getAppName()" }, type = AzureOperation.Type.ACTION)
public SpringCloudDeployment execute(IAzureMessager messager) {
    AzureMessager.getContext().setMessager(messager);
    AzureTelemetry.getContext().setProperties(getTelemetryProperties());
    final SpringCloudAppConfig appConfig = this.config.getAppConfig();
    final DeploySpringCloudAppTask task = new DeploySpringCloudAppTask(appConfig);
    final SpringCloudDeployment deployment = task.execute();
    final SpringCloudApp app = deployment.app();
    final SpringCloudCluster cluster = app.getCluster();
    if (!deployment.waitUntilReady(GET_STATUS_TIMEOUT)) {
        messager.warning(GET_DEPLOYMENT_STATUS_TIMEOUT, NOTIFICATION_TITLE);
    }
    printPublicUrl(app);
    return deployment;
}
Also used : DeploySpringCloudAppTask(com.microsoft.azure.toolkit.lib.springcloud.task.DeploySpringCloudAppTask) SpringCloudDeployment(com.microsoft.azure.toolkit.lib.springcloud.SpringCloudDeployment) SpringCloudCluster(com.microsoft.azure.toolkit.lib.springcloud.SpringCloudCluster) SpringCloudAppConfig(com.microsoft.azure.toolkit.lib.springcloud.config.SpringCloudAppConfig) SpringCloudApp(com.microsoft.azure.toolkit.lib.springcloud.SpringCloudApp) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 15 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.

the class SpringCloudClusterComboBox method loadItems.

@NotNull
@Override
@AzureOperation(name = "springcloud|cluster.list.subscription", params = { "this.subscription.getId()" }, type = AzureOperation.Type.SERVICE)
protected List<? extends SpringCloudCluster> loadItems() throws Exception {
    if (Objects.nonNull(this.subscription)) {
        final String sid = this.subscription.getId();
        final AzureSpringCloud az = Azure.az(AzureSpringCloud.class).subscription(sid);
        return az.clusters();
    }
    return Collections.emptyList();
}
Also used : AzureSpringCloud(com.microsoft.azure.toolkit.lib.springcloud.AzureSpringCloud) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)64 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)11 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)11 IOException (java.io.IOException)10 Project (com.intellij.openapi.project.Project)9 ArrayList (java.util.ArrayList)9 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)8 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)6 Path (java.nio.file.Path)6 Module (com.intellij.openapi.module.Module)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)5 Azure (com.microsoft.azure.management.Azure)4 IFunctionApp (com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp)4 AzureUIRefreshEvent (com.microsoft.azuretools.utils.AzureUIRefreshEvent)4 Action (com.microsoft.azure.toolkit.lib.common.action.Action)3 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)3 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)3 AzureTaskManager (com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager)3