private void loadList() { final JDialog form = this; final ReadOnlyCellTableModel model = (ReadOnlyCellTableModel) subscriptionTable.getModel(); while (model.getRowCount() > 0) model.removeRow(0); form.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Vector<String> vector = new Vector<String>(); vector.add("(loading... )"); vector.add(""); model.addRow(vector); ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { try { while (model.getRowCount() > 0) model.removeRow(0); subscriptionList = AzureRestAPIManager.getManager().getSubscriptionList(); if (subscriptionList != null && subscriptionList.size() > 0) { for (Subscription subs : subscriptionList) { Vector<String> row = new Vector<String>(); row.add(subs.getName()); row.add(subs.getId().toString()); model.addRow(row); } removeButton.setEnabled(true); } else { removeButton.setEnabled(false); } form.setCursor(Cursor.getDefaultCursor()); } catch (AzureCmdException e) { form.setCursor(Cursor.getDefaultCursor()); UIHelper.showException("Error getting subscription list", e); } } }); }
public ManageSubscriptionForm(Project project) { this.project = project; final ManageSubscriptionForm form = this; this.setTitle("Manage subscriptions"); this.setModal(true); this.setContentPane(mainPanel); this.setResizable(false); getRootPane().setDefaultButton(okButton); final ReadOnlyCellTableModel model = new ReadOnlyCellTableModel(); model.addColumn("Name"); model.addColumn("Id"); subscriptionTable.setModel(model); // initialize the popup menu for the "Add Subscription" button initSubscriptionMenu(); addSubscriptionButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { addSubscriptionMenu.pack(); addSubscriptionMenu.setPopupSize( addSubscriptionButton.getWidth(), MENU_ITEM_HEIGHT * addSubscriptionMenu.getComponentCount()); addSubscriptionMenu.show(addSubscriptionButton, 0, addSubscriptionButton.getHeight()); } }); removeButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { int res = JOptionPane.showConfirmDialog( form, "Are you sure you would like to clear all subscriptions?", "Clear Subscriptions", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE); if (res == JOptionPane.YES_OPTION) { try { AzureManager apiManager = AzureRestAPIManager.getManager(); apiManager.clearAuthenticationTokens(); apiManager.clearSubscriptions(); apiManager.setAuthenticationMode(AzureAuthenticationMode.Unknown); } catch (AzureCmdException t) { UIHelper.showException("Error clearing user subscriptions", t); } ReadOnlyCellTableModel model = (ReadOnlyCellTableModel) subscriptionTable.getModel(); while (model.getRowCount() > 0) { model.removeRow(0); } removeButton.setEnabled(false); } } }); removeButton.setEnabled(false); okButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onOk(); } }); cancelButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onCancel(); } }); // call onCancel() when cross is clicked setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { onCancel(); } }); ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { loadList(); } }); }
public AzureMobileServiceStep(final String title, final AddServiceWizardModel model) { super(title, null, null); this.model = model; this.modalityState = ModalityState.any(); ReadOnlyCellTableModel tableModel = new ReadOnlyCellTableModel(); mobileServices.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ListSelectionModel selectionModel = mobileServices.getSelectionModel(); tableModel.addColumn("Name"); tableModel.addColumn("Region"); tableModel.addColumn("Type"); tableModel.addColumn("Subscription"); mobileServices.setModel(tableModel); List<String> listServicesData = new ArrayList<String>(); int boldIndex = -1; int index = 0; for (ServiceType serviceType : this.model.getServiceTypes()) { listServicesData.add(serviceType.getDisplayName()); if (serviceType.equals(AzureMobileServiceStep.serviceType)) { boldIndex = index; } index++; } final String boldValue = listServicesData.get(boldIndex); DefaultListCellRenderer customListCellRenderer = new DefaultListCellRenderer() { public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (boldValue.equals(value)) { // <= put your logic here c.setFont(c.getFont().deriveFont(Font.BOLD)); } else { c.setFont(c.getFont().deriveFont(Font.PLAIN)); } return c; } }; this.listServices.setCellRenderer(customListCellRenderer); DefaultListSelectionModel customListSelectionModel = new DefaultListSelectionModel() { @Override public void setSelectionInterval(int index0, int index1) {} @Override public void addSelectionInterval(int index0, int index1) {} }; this.listServices.setSelectionModel(customListSelectionModel); this.listServices.setListData(listServicesData.toArray(new String[1])); selectionModel.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent listSelectionEvent) { Object sourceObj = listSelectionEvent.getSource(); if (sourceObj instanceof ListSelectionModel && !((ListSelectionModel) sourceObj).isSelectionEmpty() && listSelectionEvent.getValueIsAdjusting() && serviceList.size() > 0) { Service s = serviceList.get(mobileServices.getSelectionModel().getLeadSelectionIndex()); model.setService(s); model.getCurrentNavigationState().NEXT.setEnabled(true); } } }); buttonEdit.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { ManageSubscriptionForm form = new ManageSubscriptionForm(null); UIHelper.packAndCenterJDialog(form); form.setVisible(true); if (form.getDialogResult() == ManageSubscriptionForm.DialogResult.OK) { fillList(); } else { try { List<Subscription> subscriptionList = AzureRestAPIManager.getManager().getSubscriptionList(); if (subscriptionList == null || subscriptionList.size() == 0) { buttonAddService.setEnabled(false); // clear the mobile services list final ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel(); messageTableModel.addColumn("Message"); Vector<String> vector = new Vector<String>(); vector.add("Please sign in/import your Azure subscriptions."); messageTableModel.addRow(vector); mobileServices.setModel(messageTableModel); } else { fillList(); } } catch (AzureCmdException e) { final ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel(); messageTableModel.addColumn("Message"); Vector<String> vector = new Vector<String>(); vector.add( "There has been an error while retrieving the configured Azure subscriptions."); messageTableModel.addRow(vector); vector = new Vector<String>(); vector.add("Please retry signing in/importing your Azure subscriptions."); messageTableModel.addRow(vector); mobileServices.setModel(messageTableModel); } } } }); buttonAddService.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { CreateNewServiceForm form = new CreateNewServiceForm(); form.setServiceCreated( new Runnable() { @Override public void run() { ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { fillList(); } }); } }); form.setModal(true); UIHelper.packAndCenterJDialog(form); form.setVisible(true); } }); refreshServices(); }
private void fillList() { model.setService(null); model.getCurrentNavigationState().NEXT.setEnabled(false); serviceList = new ArrayList<Service>(); mobileServices.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); final ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel(); messageTableModel.addColumn("Message"); Vector<String> vector = new Vector<String>(); vector.add("(loading... )"); messageTableModel.addRow(vector); mobileServices.setModel(messageTableModel); ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { int selectedIndex = -1; try { List<Subscription> subscriptionList = AzureRestAPIManager.getManager().getSubscriptionList(); if (subscriptionList != null && subscriptionList.size() > 0) { buttonAddService.setEnabled(true); ReadOnlyCellTableModel serviceTableModel = new ReadOnlyCellTableModel(); serviceTableModel.addColumn("Name"); serviceTableModel.addColumn("Region"); serviceTableModel.addColumn("Type"); serviceTableModel.addColumn("Subscription"); int rowIndex = 0; for (Subscription s : subscriptionList) { List<Service> currentSubServices = AzureRestAPIManager.getManager().getServiceList(s.getId()); for (Service service : currentSubServices) { Vector<String> row = new Vector<String>(); row.add(service.getName()); row.add(service.getRegion()); row.add("Mobile service"); row.add(s.getName()); serviceTableModel.addRow(row); serviceList.add(service); if (model.getService() != null && model.getService().getName().equals(service.getName()) && model .getService() .getSubcriptionId() .toString() .equals(service.getSubcriptionId().toString())) { selectedIndex = rowIndex; } rowIndex++; } } if (rowIndex == 0) { while (messageTableModel.getRowCount() > 0) { messageTableModel.removeRow(0); } Vector<String> vector = new Vector<String>(); vector.add( "There are no Azure Mobile Services on the imported subscriptions"); messageTableModel.addRow(vector); mobileServices.setModel(messageTableModel); } else { mobileServices.setModel(serviceTableModel); } } else { buttonAddService.setEnabled(false); while (messageTableModel.getRowCount() > 0) { messageTableModel.removeRow(0); } Vector<String> vector = new Vector<String>(); vector.add("Please sign in/import your Azure subscriptions."); messageTableModel.addRow(vector); mobileServices.setModel(messageTableModel); buttonEdit.doClick(); } } catch (Throwable ex) { UIHelper.showException("Error retrieving service list", ex); serviceList.clear(); while (messageTableModel.getRowCount() > 0) { messageTableModel.removeRow(0); } Vector<String> vector = new Vector<String>(); vector.add( "There has been an error while loading the list of Azure Mobile Services"); messageTableModel.addRow(vector); mobileServices.setModel(messageTableModel); } mobileServices.getSelectionModel().clearSelection(); if (selectedIndex >= 0) { mobileServices.getSelectionModel().setLeadSelectionIndex(selectedIndex); } } }, this.modalityState); }