Skip to content

Commit 9613ddd

Browse files
committed
Improved reloading dirty views, still kind of hacked
1 parent 2e91620 commit 9613ddd

File tree

5 files changed

+123
-23
lines changed

5 files changed

+123
-23
lines changed

visualvm/core/src/org/graalvm/visualvm/core/ui/Bundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ LBL_Opening=Opening {0}...
2626

2727
DataSourceCaption_LBL_Reload=The view is not up to date, click to reload obsolete data\:
2828
DataSourceCaption_BTN_Reload=Reload
29+
DataSourceCaption_MSG_Reloading=Reloading view...

visualvm/core/src/org/graalvm/visualvm/core/ui/DataSourceCaption.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ public Dimension getMinimumSize() {
316316
dim.height = super.getPreferredSize().height;
317317
return dim;
318318
}
319+
// protected void fireActionPerformed(ActionEvent e) {
320+
// super.fireActionPerformed(e);
321+
// DataSourceWindowManager.sharedInstance().reopenDataSource(dataSource);
322+
// }
319323
};
320324
c = new GridBagConstraints();
321325
c.gridx = 3;

visualvm/core/src/org/graalvm/visualvm/core/ui/DataSourceWindow.java

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ public void selectView(DataSourceView view) {
100100
}
101101
}
102102

103-
boolean reloadingView;
104-
105103
public void removeView(final DataSourceView view) {
106104
if (viewsCount == 1) {
107105
if (view != singleViewContainer.getView()) throw new RuntimeException("View " + view + " not present in DataSourceWindow " + this); // NOI18N
@@ -128,7 +126,49 @@ public void removeView(final DataSourceView view) {
128126

129127
DataSourceWindowManager.sharedInstance().unregisterClosedView(view);
130128
viewsCount--;
131-
if (!reloadingView && viewsCount == 0 && isOpened()) close();
129+
if (viewsCount == 0 && isOpened()) close();
130+
}
131+
132+
void clearView(final DataSourceView view) {
133+
if (viewsCount == 1) {
134+
singleViewContainer.removeAll();
135+
if (singleViewContainer.getCaption() != null) singleViewContainer.getCaption().finish();
136+
singleViewContainer.setReloading();
137+
singleViewContainer.doLayout();
138+
singleViewContainer.repaint();
139+
} else {
140+
int viewIndex = indexOf(view);
141+
if (viewIndex == -1) return;
142+
143+
tabbedContainer.clearView(viewIndex);
144+
}
145+
146+
PROCESSOR.post(new Runnable() {
147+
public void run() { view.viewRemoved(); }
148+
});
149+
}
150+
151+
void setView(final DataSourceView view) {
152+
if (viewsCount == 1) {
153+
singleViewContainer.removeAll();
154+
singleViewContainer.setCaption(new DataSourceCaption(view.getDataSource()));
155+
singleViewContainer.setView(view);
156+
singleViewContainer.doLayout();
157+
singleViewContainer.repaint();
158+
} else {
159+
DataSourceWindowTabbedPane.ViewContainer container = tabbedContainer.getContainer(view);
160+
if (container != null) {
161+
container.removeAll();
162+
container.setCaption(new DataSourceCaption(view.getDataSource()));
163+
container.setView(view);
164+
container.doLayout();
165+
container.repaint();
166+
}
167+
}
168+
169+
PROCESSOR.post(new Runnable() {
170+
public void run() { view.viewAdded(); }
171+
});
132172
}
133173

134174
public void removeAllViews() {

visualvm/core/src/org/graalvm/visualvm/core/ui/DataSourceWindowManager.java

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -374,20 +374,39 @@ void reopenDataSource(final DataSource dataSource) {
374374
processor.post(new Runnable() {
375375
public void run() {
376376
DataSource viewMaster = getViewMaster(dataSource);
377-
DataSourceWindow window = viewMaster == null ? null : openedWindows.get(viewMaster);
377+
final DataSourceWindow window = viewMaster == null ? null : openedWindows.get(viewMaster);
378378

379379
if (window == null) return;
380380

381-
Set<DataSourceView> views = new HashSet(openedViews.get(dataSource));
382-
try {
383-
window.reloadingView = true;
384-
for (DataSourceView view : views) window.removeView(view);
385-
} finally {
386-
window.reloadingView = false;
387-
}
381+
Set<DataSourceView> _views = openedViews.get(dataSource);
382+
if (_views == null) return;
388383

389-
reloadingView = true;
390-
openDataSource(dataSource);
384+
final Set<DataSourceView> oldViews = new HashSet(_views);
385+
SwingUtilities.invokeLater(new Runnable () {
386+
public void run() {
387+
final Set<DataSourceView> opened = openedViews.get(dataSource);
388+
for (DataSourceView view : oldViews) {
389+
window.clearView(view);
390+
opened.remove(view);
391+
}
392+
393+
processor.post(new Runnable() {
394+
public void run() {
395+
final List<? extends DataSourceView> newViews = DataSourceViewsManager.sharedInstance().getViews(dataSource);
396+
for (DataSourceView view : newViews) {
397+
opened.add(view);
398+
view.viewWillBeAdded();
399+
}
400+
401+
SwingUtilities.invokeLater(new Runnable() {
402+
public void run() {
403+
for (DataSourceView view : newViews) window.setView(view);
404+
}
405+
});
406+
}
407+
});
408+
}
409+
});
391410
}
392411
});
393412
}

visualvm/core/src/org/graalvm/visualvm/core/ui/DataSourceWindowTabbedPane.java

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
import java.util.ArrayList;
3737
import java.util.List;
3838
import javax.swing.BorderFactory;
39+
import javax.swing.JLabel;
3940
import javax.swing.JPanel;
4041
import javax.swing.UIManager;
4142
import org.graalvm.visualvm.uisupport.ProfilerTabbedPane;
43+
import org.openide.util.NbBundle;
4244

4345
/**
4446
* TabbedPane container allowing to control if tabs can be closed or not
@@ -132,6 +134,26 @@ public void removeView(int index) {
132134
container.getCaption().finish();
133135
}
134136

137+
void clearView(int index) {
138+
ViewContainer container = (ViewContainer)tabpane.getComponentAt(index);
139+
container.removeAll();
140+
if (container.caption != null) container.caption.finish();
141+
container.setReloading();
142+
container.doLayout();
143+
container.repaint();
144+
}
145+
146+
ViewContainer getContainer(DataSourceView view) {
147+
String name = view.getName();
148+
// int position = view.getPreferredPosition();
149+
150+
for (int i = 0; i < tabpane.getTabCount(); i++)
151+
if (tabpane.getTitleAt(i).equals(name))
152+
return (ViewContainer)tabpane.getComponentAt(i);
153+
154+
return null;
155+
}
156+
135157
public DataSourceView getView(ViewContainer container) {
136158
return container.getView();
137159
}
@@ -179,32 +201,46 @@ static class ViewContainer extends JPanel {
179201

180202
public ViewContainer(DataSourceCaption caption, DataSourceView view) {
181203
Color backgroundColor = UISupport.getDefaultBackground();
182-
183-
this.caption = caption;
184-
this.view = view;
185-
this.viewComponent = view.getView();
204+
186205
setLayout(new BorderLayout());
187206
setBorder(BorderFactory.createMatteBorder(0, 5, 5, 5, backgroundColor));
188207
setBackground(backgroundColor);
189208
setFocusable(false);
190-
191-
add(viewComponent, BorderLayout.CENTER);
192-
if (caption != null) {
193-
caption.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
194-
add(caption, BorderLayout.NORTH);
195-
}
209+
210+
setView(view);
211+
setCaption(caption);
196212
}
197213

198214
public final boolean requestFocusInWindow() {
199215
if (getComponentCount() > 0) return getComponent(0).requestFocusInWindow();
200216
else return super.requestFocusInWindow();
201217
}
202218

219+
final void setCaption(DataSourceCaption caption) {
220+
this.caption = caption;
221+
if (caption != null) {
222+
caption.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
223+
add(caption, BorderLayout.NORTH);
224+
}
225+
}
226+
203227
public DataSourceCaption getCaption() { return caption; }
204228

229+
final void setView(DataSourceView view) {
230+
this.view = view;
231+
this.viewComponent = view.getView();
232+
add(viewComponent, BorderLayout.CENTER);
233+
}
234+
205235
public DataSourceView getView() { return view; }
206236

207237
public DataViewComponent getViewComponent() { return viewComponent; }
238+
239+
final void setReloading() {
240+
JLabel l = new JLabel(NbBundle.getMessage(DataSourceWindowTabbedPane.class, "DataSourceCaption_MSG_Reloading"), JLabel.CENTER); // NOI18N
241+
l.setEnabled(false);
242+
add(l, BorderLayout.CENTER);
243+
}
208244
}
209245

210246
}

0 commit comments

Comments
 (0)