OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 | 14 |
15 package com.google.dart.tools.debug.core.dartium; | 15 package com.google.dart.tools.debug.core.dartium; |
16 | 16 |
17 import com.google.dart.tools.core.utilities.resource.IFileUtilities; | 17 import com.google.dart.tools.core.utilities.resource.IFileUtilities; |
18 import com.google.dart.tools.debug.core.DartDebugCorePlugin; | 18 import com.google.dart.tools.debug.core.DartDebugCorePlugin; |
19 import com.google.dart.tools.debug.core.util.ResourceChangeManager; | 19 import com.google.dart.tools.debug.core.util.ResourceChangeManager; |
20 import com.google.dart.tools.debug.core.util.ResourceChangeParticipant; | 20 import com.google.dart.tools.debug.core.util.ResourceChangeParticipant; |
21 import com.google.dart.tools.debug.core.webkit.WebkitCallback; | 21 import com.google.dart.tools.debug.core.webkit.WebkitCallback; |
22 import com.google.dart.tools.debug.core.webkit.WebkitNode; | 22 import com.google.dart.tools.debug.core.webkit.WebkitNode; |
23 import com.google.dart.tools.debug.core.webkit.WebkitResult; | 23 import com.google.dart.tools.debug.core.webkit.WebkitResult; |
24 | 24 |
25 import org.eclipse.core.resources.IFile; | 25 import org.eclipse.core.resources.IFile; |
26 import org.eclipse.core.runtime.CoreException; | 26 import org.eclipse.core.runtime.CoreException; |
| 27 import org.eclipse.core.runtime.IProgressMonitor; |
| 28 import org.eclipse.core.runtime.IStatus; |
| 29 import org.eclipse.core.runtime.Status; |
| 30 import org.eclipse.core.runtime.jobs.Job; |
27 | 31 |
28 import java.io.IOException; | 32 import java.io.IOException; |
29 | 33 |
30 /** | 34 /** |
31 * A class to listen for resource changes to html files and sync their contents
over a WIP | 35 * A class to listen for resource changes to html files and sync their contents
over a WIP |
32 * connection. | 36 * connection. |
33 */ | 37 */ |
34 public class HtmlScriptManager implements ResourceChangeParticipant { | 38 public class HtmlScriptManager implements ResourceChangeParticipant { |
| 39 |
| 40 private class UpdateHtmlFileJob extends Job { |
| 41 |
| 42 IFile file; |
| 43 |
| 44 public UpdateHtmlFileJob(IFile file) { |
| 45 super("Updating file"); |
| 46 this.file = file; |
| 47 } |
| 48 |
| 49 @Override |
| 50 protected IStatus run(IProgressMonitor monitor) { |
| 51 String fileUrl = target.getResourceResolver().getUrlForResource(file); |
| 52 |
| 53 if (fileUrl != null && fileUrl.equals(rootNode.getDocumentURL())) { |
| 54 uploadNewSource(rootNode, file); |
| 55 } |
| 56 |
| 57 return Status.OK_STATUS; |
| 58 } |
| 59 |
| 60 } |
| 61 |
35 private DartiumDebugTarget target; | 62 private DartiumDebugTarget target; |
36 | 63 |
37 private WebkitNode rootNode; | 64 private WebkitNode rootNode; |
38 | 65 |
39 public HtmlScriptManager(DartiumDebugTarget target) { | 66 public HtmlScriptManager(DartiumDebugTarget target) { |
40 this.target = target; | 67 this.target = target; |
41 | 68 |
42 ResourceChangeManager.getManager().addChangeParticipant(this); | 69 ResourceChangeManager.getManager().addChangeParticipant(this); |
43 } | 70 } |
44 | 71 |
45 public void dispose() { | 72 public void dispose() { |
46 ResourceChangeManager.removeChangeParticipant(this); | 73 ResourceChangeManager.removeChangeParticipant(this); |
47 } | 74 } |
48 | 75 |
49 public void handleDocumentUpdated() { | 76 public void handleDocumentUpdated() { |
50 resync(); | 77 resync(); |
51 } | 78 } |
52 | 79 |
53 @Override | 80 @Override |
54 public void handleFileAdded(IFile file) { | 81 public void handleFileAdded(IFile file) { |
55 | 82 |
56 } | 83 } |
57 | 84 |
58 @Override | 85 @Override |
59 public final void handleFileChanged(IFile file) { | 86 public final void handleFileChanged(IFile file) { |
60 if ("html".equals(file.getFileExtension())) { | 87 if ("html".equals(file.getFileExtension())) { |
61 String fileUrl = target.getResourceResolver().getUrlForResource(file); | 88 UpdateHtmlFileJob job = new UpdateHtmlFileJob(file); |
62 | 89 job.schedule(); |
63 if (fileUrl != null && fileUrl.equals(rootNode.getDocumentURL())) { | |
64 uploadNewSource(rootNode, file); | |
65 } | |
66 } | 90 } |
67 } | 91 } |
68 | 92 |
69 @Override | 93 @Override |
70 public void handleFileRemoved(IFile file) { | 94 public void handleFileRemoved(IFile file) { |
71 | 95 |
72 } | 96 } |
73 | 97 |
74 public void handleLoadEventFired() { | 98 public void handleLoadEventFired() { |
75 resync(); | 99 resync(); |
(...skipping 26 matching lines...) Expand all Loading... |
102 IFileUtilities.getContents(file)); | 126 IFileUtilities.getContents(file)); |
103 } catch (IOException e) { | 127 } catch (IOException e) { |
104 // We upload changed html on a best-effort basis. | 128 // We upload changed html on a best-effort basis. |
105 // DartDebugCorePlugin.logError(e); | 129 // DartDebugCorePlugin.logError(e); |
106 } catch (CoreException e) { | 130 } catch (CoreException e) { |
107 DartDebugCorePlugin.logError(e); | 131 DartDebugCorePlugin.logError(e); |
108 } | 132 } |
109 } | 133 } |
110 | 134 |
111 } | 135 } |
OLD | NEW |