private void addToggleReadOnlyAction(DefaultActionGroup actionGroup) {
    actionGroup.add(
        new ToggleAction(
            StringUtil.getMsg("idea.show_read_only.text"),
            StringUtil.getMsg("idea.show_read_only.description"),
            AllIcons.Ide.Readonly) {
          public boolean isSelected(AnActionEvent e) {
            return myShowReadOnly;
          }

          public void setSelected(AnActionEvent e, boolean state) {
            showReadOnly(state);
          }
        });
  }
 private void addRefreshAction(DefaultActionGroup actionGroup) {
   actionGroup.add(
       new AnAction(StringUtil.getMsg("refresh.file.list"), "", AllIcons.Actions.Refresh) {
         public void actionPerformed(AnActionEvent e) {
           refreshData(myUser, myUser.getProjectsData(myIdeFacade));
         }
       });
 }
 protected void outputMessage(ConsoleView consoleView) {
   if (StringUtil.isNotEmpty(getComment())) {
     printComment(consoleView);
     consoleView.print(
         "-----------------------------------------------------\n",
         ConsoleViewContentType.SYSTEM_OUTPUT);
   }
   consoleView.print(myStacktrace, ConsoleViewContentType.ERROR_OUTPUT);
   consoleView.print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
 }
  @Override
  protected void tearDown() throws Exception {
    if (myTransport != null) {
      myTransport.dispose();
      Pico.getInstance().unregisterComponentByInstance(myTransport);
    }

    StringUtil.setMyUsername(null);
    super.tearDown();
  }
 public void testFindUsers() throws Exception {
   User[] users = myTransport.findUsers(new NullProgressIndicator());
   assertTrue("At least self should be found", users.length >= 1);
   User self = null;
   for (User user : users) {
     if (user.getName().equals(StringUtil.getMyUsername())) {
       self = user;
       break;
     }
   }
   assertNotNull("Self user not found in " + Arrays.asList(users), self);
   assertTrue("Self should be online", self.isOnline());
   InetAddress address = myTransport.getAddress(self);
   assertTrue("Self address is expected:" + address, NetworkUtil.isOwnAddress(address));
   assertEquals("Projects should be set", PROJECT_NAME, self.getProjects()[0]);
 }
  public void testSetOwnPresence() throws Exception {

    registerResponseProviders(myUserModel, myIdeFacade);

    // Add self to contact list
    User self = myUserModel.createUser(StringUtil.getMyUsername(), myTransport.getName());
    myUserModel.addUser(self);

    // Wait for next cycle of user finding
    new WaitFor(1000) {
      @Override
      protected boolean condition() {
        return !myTransport.getUserMonitorThread().isFinding();
      }
    };

    // make self away
    UserPresence presence = new UserPresence(PresenceMode.AWAY);
    assert presence.isOnline();
    myTransport.setOwnPresence(presence);

    // make sure that away status will be updated
    myTransport.findUsers(new NullProgressIndicator());
    assert PresenceMode.AWAY == self.getPresence().getPresenceMode();

    // Now, test itself. We go online and want this status to be updated almost immediately.
    myEvents.clear();
    addEventListener();
    myTransport.setOwnPresence(new UserPresence(PresenceMode.AVAILABLE));

    final User self1 = self;
    new WaitFor(200) {
      @Override
      protected boolean condition() {
        return self1.getPresence().getPresenceMode() == PresenceMode.AVAILABLE;
      }
    };
    assertSame(
        "Should provide correct presence mode",
        PresenceMode.AVAILABLE,
        myTransport.getUserPresence(self).getPresenceMode());
    UserEvent.Updated event = (UserEvent.Updated) checkEvent(true);
    assertNotNull("Expect go online event", event);
    assertEquals("presence", event.getPropertyName());
  }
/** @author Kir */
class ViewFilesPanel extends JPanel implements DataProvider {
  static final String NON_PROJECT_NODE = StringUtil.getMsg("non.project.files");

  private final FileTypeManager myFileTypeManager;
  private final IDEFacade myIdeFacade;
  private final Tree myTree;

  private ProjectsData myProjectsData;
  private User myUser;

  private boolean myShowReadOnly;

  @SuppressWarnings({"HardCodedStringLiteral"})
  public static final String SHOW_READ_ONLY_KEY = "SHOW_READ_ONLY_KEY";

  private OpenFileAction myOpenFileAction;

  public ViewFilesPanel(
      FileTypeManager fileTypeManager, ActionManager actionManager, IDEFacade facade) {
    super(new BorderLayout(2, 2));
    setOpaque(false);

    myFileTypeManager = fileTypeManager;
    myIdeFacade = facade;
    myShowReadOnly = Pico.getOptions().isSet(SHOW_READ_ONLY_KEY, true);

    myTree =
        new KirTree() {
          protected void onEnter() {
            super.onEnter();
            if (myOpenFileAction.isEnabled()) {
              myOpenFileAction.actionPerformed(null);
            }
          }
        };
    IDEAFacade.installIdeaTreeActions(myTree);
    add(ScrollPaneFactory.createScrollPane(myTree));
    add(createActionsToolbar(actionManager), BorderLayout.NORTH);

    IDEAFacade.installPopupMenu(createActionGroup(), myTree, actionManager);

    myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode()));
    setMinimumSize(new Dimension(200, 0));
  }

  public Object getData(String dataId) {
    if (DiffAction.USER.equals(dataId)) {
      return myUser;
    }
    return null;
  }

  private Component createActionsToolbar(ActionManager actionManager) {
    DefaultActionGroup actionGroup = createActionGroup();

    if (actionManager != null)
      return actionManager.createActionToolbar("TOOLBAR", actionGroup, true).getComponent();

    return new JLabel();
  }

  private DefaultActionGroup createActionGroup() {
    DefaultActionGroup actionGroup = new DefaultActionGroup();
    if (ApplicationManager.getApplication() == null || Pico.isUnitTest()) return actionGroup;

    addRefreshAction(actionGroup);
    myOpenFileAction = new OpenFileAction(myTree, myIdeFacade);
    myOpenFileAction.registerCustomShortcutSet(
        new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0)), myTree);

    AnAction diffAction =
        new DiffAction(myTree) {
          protected User getUser() {
            return myUser;
          }
        };

    diffAction.registerCustomShortcutSet(CommonShortcuts.getDiff(), myTree);

    actionGroup.add(myOpenFileAction);
    actionGroup.add(diffAction);

    addToggleReadOnlyAction(actionGroup);
    return actionGroup;
  }

  private void addRefreshAction(DefaultActionGroup actionGroup) {
    actionGroup.add(
        new AnAction(StringUtil.getMsg("refresh.file.list"), "", AllIcons.Actions.Refresh) {
          public void actionPerformed(AnActionEvent e) {
            refreshData(myUser, myUser.getProjectsData(myIdeFacade));
          }
        });
  }

  private void addToggleReadOnlyAction(DefaultActionGroup actionGroup) {
    actionGroup.add(
        new ToggleAction(
            StringUtil.getMsg("idea.show_read_only.text"),
            StringUtil.getMsg("idea.show_read_only.description"),
            AllIcons.Ide.Readonly) {
          public boolean isSelected(AnActionEvent e) {
            return myShowReadOnly;
          }

          public void setSelected(AnActionEvent e, boolean state) {
            showReadOnly(state);
          }
        });
  }

  public void refreshData(User user, ProjectsData data) {
    assert data != null;
    assert user != null;

    myUser = user;
    myProjectsData = data;

    ((DefaultTreeModel) myTree.getModel()).setRoot(new MyRootNode());
    TreeUtils.expandAll(myTree);
  }

  public void showReadOnly(boolean showReadOnlyFiles) {
    if (myShowReadOnly != showReadOnlyFiles) {
      myShowReadOnly = showReadOnlyFiles;
      Pico.getOptions().setOption(SHOW_READ_ONLY_KEY, showReadOnlyFiles);
      if (myProjectsData != null) {
        refreshData(myUser, myProjectsData);
      }
    }
  }

  JTree getTree() {
    return myTree;
  }

  public boolean isReadOnlyShown() {
    return myShowReadOnly;
  }

  private class MyRootNode extends KirTreeNode {
    private List<KirTreeNode> myChildren;

    public MyRootNode() {
      super(null);
    }

    protected Component renderIn(JLabel label, boolean selected, boolean hasFocus) {
      return label;
    }

    protected List getChildNodes() {
      if (myChildren == null) {
        myChildren = new ArrayList<>();
        String[] projects = myProjectsData.getProjects();
        Arrays.sort(projects);
        for (String project : projects) {
          myChildren.add(new ProjectNode(this, project));
        }

        if (myProjectsData.getNonProjectFiles().length > 0) {
          myChildren.add(
              new ProjectNode(this, NON_PROJECT_NODE, myProjectsData.getNonProjectFiles()));
        }
      }
      return myChildren;
    }
  }

  private class ProjectNode extends KirTreeNode {
    private final String myName;
    private List<FileNode> myChildren;
    private final VFile[] myProjectFiles;

    public ProjectNode(TreeNode parent, String name, VFile[] projectFiles) {
      super(parent);
      myName = name;
      myProjectFiles = projectFiles;
    }

    public ProjectNode(TreeNode parent, String name) {
      super(parent);
      myName = name;
      myProjectFiles = myProjectsData.getProjectFiles(myName);
    }

    protected List getChildNodes() {
      if (myChildren == null) {
        myChildren = new ArrayList<>();
        VFile[] projectFiles = myProjectFiles;
        Arrays.sort(projectFiles);
        for (VFile projectFile : projectFiles) {
          if (myShowReadOnly || projectFile.isWritable()) {
            myChildren.add(new FileNode(this, projectFile));
          }
        }
      }
      return myChildren;
    }

    protected Component renderIn(JLabel label, boolean selected, boolean hasFocus) {
      if (NON_PROJECT_NODE.equals(myName)) {
        label.setIcon(IdetalkCoreIcons.Nodes.Unknown);
      } else {
        label.setIcon(AllIcons.Nodes.IdeaProject);
      }
      return label;
    }

    public String toString() {
      return myName;
    }
  }

  public class FileNode extends KirTreeNode {
    private final VFile myVFile;

    public FileNode(ProjectNode projectNode, VFile projectFile) {
      super(projectNode);
      myVFile = projectFile;
    }

    protected List getChildNodes() {
      return Collections.emptyList();
    }

    protected Component renderIn(JLabel label, boolean selected, boolean hasFocus) {
      if (myVFile.isWritable()) {
        label.setIcon(getIconByExtension());
      } else {
        LayeredIcon layeredIcon = new LayeredIcon(2);
        layeredIcon.setIcon(getIconByExtension(), 0);
        layeredIcon.setIcon(AllIcons.Nodes.Locked, 1);
        label.setIcon(layeredIcon);
      }
      return label;
    }

    private Icon getIconByExtension() {
      if (myFileTypeManager != null) {
        FileType fileType = myFileTypeManager.getFileTypeByExtension(getExtension());
        return fileType.getIcon();
      }
      return IdetalkCoreIcons.Nodes.Unknown;
    }

    private String getExtension() {
      final String contentPath = myVFile.getFullPath();
      if (contentPath != null) {
        int i = contentPath.lastIndexOf('.');
        if (i > 0) {
          return contentPath.substring(i + 1);
        }
      }
      return "none";
    }

    public String toString() {
      String path = myVFile.getContentPath();
      return path == null ? myVFile.getFullPath() : path;
    }

    public VFile getVFile() {
      return myVFile;
    }
  }
}
 public String getTitle() {
   return StringUtil.getMsg("stacktrace");
 }
 public boolean containsString(String searchString) {
   return super.containsString(searchString) || StringUtil.containedIn(myStacktrace, searchString);
 }
Exemplo n.º 10
0
 private User createSelf() throws UnknownHostException {
   return myTransport.createUser(
       StringUtil.getMyUsername(),
       new OnlineUserInfo(InetAddress.getLocalHost(), myTransport.getPort()));
 }