author | Eugene Ostroukhov <eugeneo@symbian.org> |
Thu, 02 Sep 2010 10:50:38 -0700 | |
changeset 483 | 109da596fa9d |
parent 480 | b6d992b9b998 |
child 484 | f5df819c1852 |
permissions | -rw-r--r-- |
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
1 |
package org.symbian.tools.tmw.previewer.preview; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
2 |
|
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
3 |
import java.net.URI; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
4 |
import java.util.Collection; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
5 |
|
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
6 |
import org.eclipse.core.resources.IFile; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
7 |
import org.eclipse.core.resources.IProject; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
8 |
import org.eclipse.core.resources.ResourcesPlugin; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
9 |
import org.eclipse.core.runtime.IPath; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
10 |
import org.eclipse.jface.action.Action; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
11 |
import org.eclipse.jface.action.IAction; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
12 |
import org.eclipse.jface.action.IToolBarManager; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
13 |
import org.eclipse.jface.viewers.ISelection; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
14 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
15 |
import org.eclipse.jface.viewers.ISelectionProvider; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
16 |
import org.eclipse.jface.viewers.StructuredSelection; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
17 |
import org.eclipse.swt.browser.Browser; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
18 |
import org.eclipse.swt.layout.GridData; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
19 |
import org.eclipse.swt.widgets.Composite; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
20 |
import org.eclipse.swt.widgets.Control; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
21 |
import org.eclipse.ui.actions.ActionFactory; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
22 |
import org.eclipse.ui.part.IPageSite; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
23 |
import org.eclipse.ui.part.Page; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
24 |
import org.symbian.tools.tmw.core.utilities.CoreUtil; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
25 |
import org.symbian.tools.tmw.previewer.Images; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
26 |
import org.symbian.tools.tmw.previewer.PreviewerPlugin; |
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
27 |
|
480 | 28 |
public abstract class AbstractPreviewPage extends Page implements IPreviewPage, ISelectionProvider { |
29 |
private final IAction refreshAction = new Action("Refresh") { |
|
30 |
public void run() { |
|
31 |
refresh(true); |
|
32 |
}; |
|
33 |
}; |
|
34 |
private final IAction toggleRefresh = new Action("Toggle Refresh", IAction.AS_RADIO_BUTTON) { |
|
35 |
public void run() { |
|
36 |
toggleRefresh(); |
|
37 |
}; |
|
38 |
}; |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
39 |
|
480 | 40 |
protected IProject project; |
41 |
private Browser browser; |
|
42 |
private boolean toggleState = true; |
|
43 |
private final PreviewView previewView; |
|
44 |
private boolean needsRefresh = false; |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
45 |
|
480 | 46 |
public AbstractPreviewPage(IProject project, PreviewView previewView) { |
47 |
this.project = project; |
|
48 |
this.previewView = previewView; |
|
49 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
50 |
|
483
109da596fa9d
Fixed relevant FindBug messages
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
480
diff
changeset
|
51 |
protected synchronized void toggleRefresh() { |
480 | 52 |
toggleState = !toggleState; |
53 |
toggleRefresh.setChecked(toggleState); |
|
54 |
previewView.setProjectAutorefresh(project, toggleState); |
|
55 |
toggleRefresh.setToolTipText(getToggleActionTooltip()); |
|
56 |
if (toggleState && needsRefresh) { |
|
57 |
refresh(true); |
|
58 |
} |
|
59 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
60 |
|
480 | 61 |
@Override |
62 |
public void createControl(Composite parent) { |
|
63 |
browser = createBrowser(parent); |
|
64 |
browser.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
65 |
browser.setUrl(getURI().toASCIIString()); |
|
66 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
67 |
|
480 | 68 |
protected abstract Browser createBrowser(Composite parent); |
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
69 |
|
480 | 70 |
private URI getURI() { |
71 |
return PreviewerPlugin.getDefault().getHttpPreviewer().previewProject(project, null); |
|
72 |
} |
|
73 |
||
74 |
@Override |
|
75 |
public Control getControl() { |
|
76 |
return browser; |
|
77 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
78 |
|
480 | 79 |
@Override |
80 |
public void setFocus() { |
|
81 |
if (browser != null && !browser.isDisposed()) { |
|
82 |
browser.setFocus(); |
|
83 |
} |
|
84 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
85 |
|
480 | 86 |
private boolean refreshScheduled = false; |
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
87 |
|
480 | 88 |
public synchronized void process(Collection<IFile> files) { |
89 |
if (!isDisposed() && !refreshScheduled && needsRefresh(files)) { |
|
90 |
asyncExec(new Runnable() { |
|
91 |
public void run() { |
|
92 |
refreshBrowser(); |
|
93 |
} |
|
94 |
}); |
|
95 |
refreshScheduled = true; |
|
96 |
} |
|
97 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
98 |
|
480 | 99 |
protected void promptIfNeeded() { |
100 |
if (toggleState) { |
|
101 |
toggleState = previewView.promptUserToToggle(project, toggleState); |
|
102 |
toggleRefresh.setChecked(toggleState); |
|
103 |
} |
|
104 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
105 |
|
480 | 106 |
private void asyncExec(Runnable runnable) { |
107 |
getControl().getDisplay().asyncExec(runnable); |
|
108 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
109 |
|
480 | 110 |
private boolean needsRefresh(Collection<IFile> files) { |
111 |
for (IFile iFile : files) { |
|
112 |
if (iFile.getProject().equals(project)) { |
|
113 |
return true; |
|
114 |
} |
|
115 |
} |
|
116 |
return false; |
|
117 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
118 |
|
480 | 119 |
protected synchronized void refresh(final boolean manual) { |
120 |
try { |
|
121 |
if (!isDisposed()) { |
|
122 |
final Control focusControl = browser.getDisplay().getFocusControl(); |
|
123 |
if (manual && CoreUtil.isMac()) { |
|
124 |
browser.getParent().forceFocus(); |
|
125 |
} |
|
126 |
browser.setUrl(getURI().toASCIIString()); |
|
127 |
refreshAction.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.GREEN_SYNC)); |
|
128 |
asyncExec(new Runnable() { |
|
129 |
public void run() { |
|
130 |
if (!manual && focusControl != null && !focusControl.isDisposed()) { |
|
131 |
focusControl.setFocus(); |
|
132 |
} else if (manual) { |
|
133 |
browser.forceFocus(); |
|
134 |
} |
|
135 |
} |
|
136 |
}); |
|
137 |
refreshAction.setToolTipText("Refresh the preview browser"); |
|
138 |
} |
|
139 |
needsRefresh = false; |
|
140 |
} finally { |
|
141 |
refreshScheduled = false; |
|
142 |
} |
|
143 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
144 |
|
480 | 145 |
@Override |
146 |
public void init(IPageSite pageSite) { |
|
147 |
super.init(pageSite); |
|
148 |
IToolBarManager toolBar = pageSite.getActionBars().getToolBarManager(); |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
149 |
|
480 | 150 |
contributeToToolbar(toolBar); |
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
151 |
|
480 | 152 |
refreshAction.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.GREEN_SYNC)); |
153 |
refreshAction.setToolTipText("Refresh the preview browser"); |
|
154 |
toolBar.add(refreshAction); |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
155 |
|
480 | 156 |
toggleState = previewView.getProjectAutorefresh(project); |
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
157 |
|
480 | 158 |
toggleRefresh.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.YELLOW_SYNC)); |
159 |
toggleRefresh.setToolTipText(getToggleActionTooltip()); |
|
160 |
toggleRefresh.setChecked(toggleState); |
|
161 |
toolBar.add(toggleRefresh); |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
162 |
|
480 | 163 |
pageSite.getActionBars().setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction); |
164 |
getSite().setSelectionProvider(this); |
|
165 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
166 |
|
480 | 167 |
protected void contributeToToolbar(IToolBarManager toolBar) { |
168 |
// Do nothing here |
|
169 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
170 |
|
480 | 171 |
private String getToggleActionTooltip() { |
172 |
return toggleState ? "Disable preview autorefresh" : "Enable preview autorefresh"; |
|
173 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
174 |
|
480 | 175 |
public void addSelectionChangedListener(ISelectionChangedListener listener) { |
176 |
// Do nothing |
|
177 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
178 |
|
480 | 179 |
public ISelection getSelection() { |
180 |
return new StructuredSelection(project); |
|
181 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
182 |
|
480 | 183 |
public void removeSelectionChangedListener(ISelectionChangedListener listener) { |
184 |
// Do nothing |
|
185 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
186 |
|
480 | 187 |
public void setSelection(ISelection selection) { |
188 |
// Do nothing |
|
189 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
190 |
|
480 | 191 |
public boolean isDisposed() { |
192 |
return browser != null && browser.isDisposed(); |
|
193 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
194 |
|
480 | 195 |
private synchronized void refreshBrowser() { |
196 |
if (toggleState) { |
|
197 |
promptIfNeeded(); |
|
198 |
} |
|
199 |
if (toggleState) { |
|
200 |
refresh(false); |
|
201 |
} else { |
|
202 |
needsRefresh = true; |
|
203 |
refreshAction.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.RED_SYNC)); |
|
204 |
refreshAction.setToolTipText("Refresh the preview browser (there are updated files)"); |
|
205 |
} |
|
206 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
207 |
|
480 | 208 |
public IProject getProject() { |
209 |
return project; |
|
210 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
211 |
|
480 | 212 |
public synchronized void projectRenamed(IPath newPath) { |
213 |
if (!isDisposed()) { |
|
214 |
project = ResourcesPlugin.getWorkspace().getRoot().getProject(newPath.lastSegment()); |
|
215 |
} |
|
216 |
} |
|
470
d4809db37847
Changed repository layout and renamed project files. This revision is untested and may not run.
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
217 |
} |